00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __DATA_PACKAGE_INCLUDED
00020 #define __DATA_PACKAGE_INCLUDED
00021
00022 #include <fstream>
00023 #include <string>
00024 #include <deque>
00025
00026 #include "common/defs.h"
00027 #include "common/leakchecker.h"
00028
00029 class TDataPackageList;
00030 class TObjectID;
00031 class TPoint;
00032
00033
00034
00035
00036
00037
00038
00107 class TDataPackage
00108 {
00109 public:
00110 enum tType
00111 {
00112 BOOL=0,
00113 DATA_PACKAGE_LIST,
00114 DOUBLE,
00115 ID,
00116 INTEGER_2,
00117 INTEGER_4,
00118 POINT,
00119 STRING
00120 };
00121
00125 TDataPackage();
00130 TDataPackage( const string& sIdentifier, const bool* pData );
00135 TDataPackage( const string& sIdentifier, const double* pData );
00140 TDataPackage( const string& sIdentifier, const int2* pData );
00145 TDataPackage( const string& sIdentifier, const int4* pData );
00150 TDataPackage( const string& sIdentifier, const string* pData );
00155 TDataPackage( const string& sIdentifier, const TDataPackageList* pData );
00160 TDataPackage( const string& sIdentifier, const TObjectID* pData );
00165 TDataPackage( const string& sIdentifier, const TPoint* pData );
00169 ~TDataPackage();
00170
00175 bool GetAutoDeleteMode() const;
00179 const string& GetIdentifier() const;
00183 const tType GetType() const;
00187 operator bool*() const;
00191 operator double*() const;
00195 operator int2*() const;
00199 operator int4*() const;
00203 operator string*() const;
00207 operator TDataPackageList*() const;
00211 operator TObjectID*() const;
00215 operator TPoint*() const;
00226 void SetAutoDeleteMode( bool bAutoDelete );
00230 void SetData( const string& sIdentifier, const bool* pData );
00231 void SetData( const string& sIdentifier, const double* pData );
00232 void SetData( const string& sIdentifier, const int2* pData );
00233 void SetData( const string& sIdentifier, const int4* pData );
00234 void SetData( const string& sIdentifier, const TDataPackageList* pData );
00235 void SetData( const string& sIdentifier, const TObjectID* pData );
00236 void SetData( const string& sIdentifier, const TPoint* pData );
00237 void SetData( const string& sIdentifier, const string* pData );
00238
00239 private:
00240 #ifdef SECURE_MODE
00241
00245 static TLeakChecker lc;
00246 #endif // SECURE_MODE
00247
00251 bool bAutoDelete;
00255 void* pData;
00259 string sIdentifier;
00263 tType type;
00264
00269 void CheckAutoDelete();
00273 void Reset();
00274 };
00275
00276
00277
00278
00279
00280
00281
00295 class TDataPackageList : public deque<TDataPackage*>
00296 {
00297 public:
00298 TDataPackageList();
00304 ~TDataPackageList();
00305
00318 bool Add( const string& sIdentifier, const bool* pData,
00319 bool bUnique=true, bool bAutoDelete=false );
00332 bool Add( const string& sIdentifier, const double* pData,
00333 bool bUnique=true, bool bAutoDelete=false );
00346 bool Add( const string& sIdentifier, const int2* pData,
00347 bool bUnique=true, bool bAutoDelete=false );
00360 bool Add( const string& sIdentifier, const int4* pData,
00361 bool bUnique=true, bool bAutoDelete=false );
00374 bool Add( const string& sIdentifier, const string* pData,
00375 bool bUnique=true, bool bAutoDelete=false );
00388 bool Add( const string& sIdentifier, const TDataPackageList* pData,
00389 bool bUnique=true, bool bAutoDelete=false );
00402 bool Add( const string& sIdentifier, const TObjectID* pData,
00403 bool bUnique=true, bool bAutoDelete=false );
00416 bool Add( const string& sIdentifier, const TPoint* pData,
00417 bool bUnique=true, bool bAutoDelete=false );
00421 void DeleteAll();
00433 bool Get( const string& sIdentifier, bool* pData, bool bUnique=true );
00445 bool Get( const string& sIdentifier, double* pData, bool bUnique=true );
00457 bool Get( const string& sIdentifier, int2* pData, bool bUnique=true );
00469 bool Get( const string& sIdentifier, int4* pData, bool bUnique=true );
00481 bool Get( const string& sIdentifier, string* pData, bool bUnique=true );
00493 bool Get( const string& sIdentifier, TDataPackageList* pData, bool bUnique=true );
00505 bool Get( const string& sIdentifier, TObjectID* pData, bool bUnique=true );
00517 bool Get( const string& sIdentifier, TPoint* pData, bool bUnique=true );
00527 bool getBool( const string& identifier, bool unique=true ) const;
00537 double getDouble( const string& identifier, bool unique=true ) const;
00547 int2 getInt2( const string& identifier, bool unique=true ) const;
00557 int4 getInt4( const string& identifier, bool unique=true ) const;
00567 const string getString( const string& identifier, bool unique=true ) const;
00577 const TPoint getPoint( const string& identifier, bool unique=true ) const;
00581 TDataPackageList& operator=( const TDataPackageList& src );
00588 bool save( ofstream& out );
00595 TDataPackage* Search( const string& sIdentifier ) const;
00603 TDataPackage* SearchUnique( const string& sIdentifier ) const;
00612 TDataPackage* SearchAndExtract( const string& sIdentifier );
00622 TDataPackage* SearchAndExtractUnique( const string& sIdentifier );
00629 void set( const string& identifier, bool value );
00636 void set( const string& identifier, double value );
00643 void set( const string& identifier, int2 value );
00650 void set( const string& identifier, int4 value );
00657 void set( const string& identifier, const string& value );
00664 void set( const string& identifier, const char* value );
00671 void set( const string& identifier, const TPoint& value );
00676 void showContent( int indent=0 ) const;
00677
00678 private:
00679 #ifdef SECURE_MODE
00680
00684 static TLeakChecker lc;
00685 #endif // SECURE_MODE
00686
00694 TDataPackage* getAndExtractPackage( const string& identifier, bool unique );
00703 TDataPackage* getPackage( const string& identifier, bool unique ) const;
00710 void Indent( ofstream& out, int2 iIndent ) const;
00717 bool WriteDataPackage( ofstream& out,
00718 const TDataPackage& pPackage, int2 iIndent=0 ) const;
00719 };
00720
00721
00722
00723
00724
00725 #endif // __DATA_PACKAGE_INCLUDED