00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00021 #ifndef __LRT_DELPHI_STREAMS__
00022 #define __LRT_DELPHI_STREAMS__
00023
00024 #include "rtsystem.h"
00025 #include "rtcollect.h"
00026 #include "rtstring.h"
00027 #include "rtstreams.h"
00028
00029 namespace lrt {
00030
00034 class Variant {
00035 public:
00037 enum VariantType {
00038 typeString = 0,
00039 typeInt,
00040 typeDouble
00041 };
00042
00044 Variant();
00046 Variant(const Variant&);
00048 Variant& operator=(const Variant&);
00049 ~Variant();
00050
00052 explicit Variant(int);
00054 explicit Variant(double);
00056 explicit Variant(const String&);
00057
00059 void set(int);
00061 void set(double);
00063 void set(const String&);
00064
00071 int getInt(int def = 0) const;
00072
00079 double getDouble(double def = 0.) const;
00080
00084 String getString() const;
00085
00088 VariantType getCurrentType() const;
00089
00090 private:
00091 union {
00092 int i;
00093 double d;
00094 String* str;
00095 };
00096 VariantType curType;
00097 };
00098
00099
00108 class DelphiDataInputStream : public FilterInputStream
00109 {
00110 public:
00111
00115 DelphiDataInputStream(InputStream* in);
00120 DelphiDataInputStream(const String& filename);
00121
00122 virtual ~DelphiDataInputStream();
00123
00127 Variant readAny();
00128
00132 String readString();
00136 int readInt();
00140 double readDouble();
00141 private:
00142 String doReadString(int type);
00143 int doReadInt(int type);
00144 double doReadDouble(int type);
00145
00146 double ld2d(Array<unsigned char>&);
00147 void inverseByteOrder(unsigned char* data, int len);
00148 };
00149
00158 class DelphiDataOutputStream : public FilterOutputStream
00159 {
00160 public:
00164 DelphiDataOutputStream(OutputStream* out);
00165
00167 bool writeAny(const Variant&);
00168
00172 bool writeString(const String&);
00173
00178 bool writeInt(int);
00179
00182 bool writeDouble(double);
00183 private:
00184 void d2ld(double d, Array<unsigned char>& ld);
00185 void inverseByteOrder(unsigned char* data, int len);
00186 bool write4(int);
00187 };
00188
00189 }
00190
00191 #endif