Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

rtdelphi.h

Go to the documentation of this file.
00001 /*
00002  * rtdelphi.h
00003  * 
00004  * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
00005  * and Martin Trautmann (martintrautmann@gmx.de) 
00006  * 
00007  * This file may be distributed and/or modified under the terms of the 
00008  * GNU General Public License version 2 as published by the Free Software 
00009  * Foundation. 
00010  * 
00011  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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 } // namespace
00190 
00191 #endif 

This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer