1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include "rtstring.h"
#include "rtsystem.h"
#include "rtmath.h"
#include "rtmain.h"
#include "rtchar.h"
#include "rtstreams.h"
#include "rtdelphi.h"
using namespace lrt;
String str1, str2;
int iArr[10];
double dArr[10] = { Math::PI, Math::E, Math::MAX_INT, Math::MIN_INT, 0,
22.0481, 20.1181, 23.0381, 0.815, 47.11 };
void printAll()
{
System::println("Str1: " + str1);
System::println("Str2: " + str2);
System::println("ints:");
for(int i = 0; i < 10; i++)
System::print(String(iArr[i]) + " ");
System::println();
System::println("doubles:");
for(int d = 0; d < 10; d++)
System::print(String(dArr[d]) + " ");
System::println();
System::println();
}
void read()
{
if(!File("delphi.tmp").exists()) {
System::println("No file.");
return;
}
DelphiDataInputStream* in = new DelphiDataInputStream(new FileInputStream("delphi.tmp", false));
if(in->fail()) { System::println("Failed. "); delete in; return; }
str1 = in->readString();
str2 = in->readString();
for(int i = 0; i < 10; i++)
iArr[i] = in->readInt();
for(int d = 0; d < 10; d++)
dArr[d] = in->readDouble();
if(in->fail())
System::println("Failed while reading.");
else
System::println("OK.");
delete in;
}
void write()
{
DelphiDataOutputStream* out = new DelphiDataOutputStream(new FileOutputStream("delphi.tmp", false));
if(out->fail()) { System::println("Failed. "); delete out; return; }
out->writeString(str1);
out->writeString(str2);
out->flush();
for(int i = 0; i < 10; i++)
{
out->writeInt(iArr[i]);
out->flush();
}
for(int d = 0; d < 10; d++)
{
out->writeDouble(dArr[d]);
out->flush();
}
if(out->fail())
System::println("Failed while writing.");
else
System::println("OK.");
delete out;
}
void toggleCase(String& str)
{
for(int i = 0; i < str.length(); i++)
{
if(Char::isLowerCase(str[i]))
str[i] = Char::upperCase(str[i]);
else
str[i] = Char::lowerCase(str[i]);
}
}
void mutate()
{
toggleCase(str1);
toggleCase(str2);
for(int i = 0; i < 10; i++)
iArr[i] += Math::rand(-1000, 1000);
for(int d = 0; d < 10; d++)
dArr[d] += (double)Math::rand(-10000, 10000) / 1000.;
}
void init()
{
// initialize initially
str1 = "Alles Prima? Sagt Flori und fgt noch ein paar Tests an aAbByYzZ";
for(int s = 0; s < 10; s++)
str2 += String(s) + ") " + str1 + "; ";
for(int i = 0; i < 10; i++)
iArr[i] = Math::rand(0, 1 << (i*3));
}
int rtMain(const Array<String> &args)
{
System::println(String("sizeof(float): ") + sizeof(float));
System::println(String("sizeof(double): ") + sizeof(double));
System::println(String("sizeof(long double): ") + sizeof(long double));
System::println("Initializing: *********************************");
init();
System::println("Reading from file: ****************************");
read();
printAll();
#ifdef __SYMBIAN32__
System::read();
#endif
System::println("Mutating: *************************************");
mutate();
printAll();
System::println("Writing to file: ******************************");
write();
/*
#ifdef __SYMBIAN32__
lrt::Time time, ntime;
time = lrt::Time::getCurrentTime();
do{
System::print("K");
System::read();
ntime = lrt::Time::getCurrentTime();
}while((ntime - time).toInt() < 500);
#endif
*/
return 0;
}
|