00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __GZ_BASE_H__
00024 #define __GZ_BASE_H__
00025
00034 #include "gzBasicTypes.h"
00035 #include "gzMemory.h"
00036 #include "gzDebug.h"
00037 #include "gzMutex.h"
00038
00039 #include <string.h>
00040
00041 #if defined GZ_UNIX
00042
00043 #include <dirent.h>
00044
00045 typedef DIR * gzDirHandle;
00046 typedef struct dirent * gzDirEntry;
00047
00048 #else // non unix
00049
00050 #include "windows.h"
00051 typedef HANDLE gzDirHandle;
00052 typedef WIN32_FIND_DATA gzDirEntry;
00053
00054 #endif
00055
00056
00057
00058 #if defined UNICODE
00059 #define GZ_T_UNICODE(x) (x)##.getWideString()
00060 #define GZ_T_UNICODE_LEN(x) (x)##.getWideStringLength()
00061 #else
00062 #define GZ_T_UNICODE(x) (const char *)(x)
00063 #define GZ_T_UNICODE_LEN(x) (x)##.length()
00064 #endif
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00091 class GZ_BASE_EXPORT gzString
00092 {
00093
00094 public:
00095
00096
00097 GZ_DECLARE_TYPE_INTERFACE;
00098
00099
00100
00102
00104 gzString():m_string(NULL),m_len(0),m_uniqueID(0),m_hash(0){}
00105
00107
00109 gzString(const char *str):m_string(NULL),m_len(0),m_uniqueID(0),m_hash(0){ *this = str; }
00110
00111 gzString(const char *str, gzUShort len);
00112
00113 gzString(const gzString &str);
00114
00115 virtual ~gzString();
00116
00121 gzString(const gzWideChar *widestr);
00122
00123 gzString(const gzWideChar *widestr , gzUShort len,gzBool isPlain=FALSE);
00124
00125
00130 gzString(gzLongLong number,gzUByte radix,gzULong minLen=0);
00131
00135 gzString(gzDouble number,const gzString & format="");
00136
00137
00139 gzUShort length() const { return m_len; }
00140
00142 gzVoid clear();
00143
00145 const char * getString() const;
00146
00148 gzLongLong num() const;
00149
00151 gzDouble real(gzUShort decimalToken='.') const;
00152
00153 gzDouble sortval() const;
00154
00156
00161 gzBool contains(const gzString & substr, gzUShort startindex=0 , gzBool caseSensitive = TRUE , gzUShort *index=NULL) const;
00162
00164
00168 gzString rightOf(const gzString & substr, gzBool searchFromEnd = TRUE, gzBool caseSensitive = TRUE ) const;
00169
00171
00175 gzString leftOf(const gzString & substr, gzBool searchFromStart = TRUE , gzBool caseSensitive = TRUE ) const;
00176
00178 gzString toLower() const;
00179
00181 gzString toUpper() const;
00182
00183 gzString left(gzULong count,gzBool inverse=FALSE) const;
00184
00185 gzString right(gzULong count,gzBool inverse=FALSE) const;
00186
00187
00192 gzString strip(char c , gzBool left=TRUE , gzBool right=TRUE) const;
00193
00194 gzString stripWhiteSpace(gzBool left=TRUE , gzBool right=TRUE) const;
00195
00197 gzVoid reverse();
00198
00200 gzULong hash() const { return m_hash; }
00201
00203 gzBool isEmpty() const { return m_len==0; }
00204
00206 gzBool isFirst( const gzString &str , gzBool caseSensitive = TRUE) const;
00207
00209 gzBool isFirst( const char ch , gzBool caseSensitive = TRUE) const;
00210
00212 gzBool isLast( const gzString &str , gzBool caseSensitive = TRUE) const;
00213
00215 gzBool isLast( const char ch , gzBool caseSensitive = TRUE) const;
00216
00218
00268 gzString & format( const gzString &format, ARG_DECL_LIST );
00269
00270 gzString & identifier(gzLongLong number);
00271
00273 gzUShort getWideStringLength() const;
00274
00276
00278 gzUShort getWideString(gzWideChar *buffer, gzBool appendZero=TRUE) const;
00279
00281 gzBool hasEscapedUTF8Chars() const;
00282
00284 gzBool isAsciiString() const;
00285
00287
00289 gzString convertAsciiToUTF8() const;
00290
00292
00294 gzString convertUTF8ToAscii() const;
00295
00296 gzString convertUTF8ToNumList(const gzString &format="0x%02x",const gzString &separator=",") const;
00297
00298 gzString convertNumListToUTF8() const;
00299
00300 gzString convertTextToCtrl() const;
00301
00302 gzString convertCtrlToText() const;
00303
00305 const gzWideChar * getWideString(gzUShort knownLength=0) const;
00306
00308
00309 gzArray<gzUByte> getBSTR() const;
00310
00312
00313 gzArray<gzWideChar> getWideBSTR() const;
00314
00316 gzString & scramble(gzULong code);
00317
00319
00320 gzLongLong dotValue(gzULong base=256,gzULong *groups=NULL) const;
00321
00323 gzUShort substitute(char from,char to);
00324
00326 gzBool yesNo();
00327
00329
00330 static gzULong hash(const char *s , gzULong size=0);
00331
00332
00333 gzBool isUnique() const;
00334 gzUShort getUniqueID() const;
00335 gzBool makeUnique(gzUShort uniqueID=0);
00336 gzBool checkUnique() const;
00337
00338
00339
00340 operator gzLongLong () const { return num(); }
00341
00342 operator gzDouble () const { return real(); }
00343
00344 gzString & operator =(const char *str);
00345
00346
00347 operator const char *() const;
00348
00349 gzString & operator =(const gzString &str);
00350
00351 gzString & operator +=(const char *str);
00352
00353 gzString operator +(const char *str) const;
00354
00355 gzString operator +(const gzString &str) const;
00356
00357 gzString & operator +=(const gzString &str);
00358
00359 gzString & operator +=(const char c);
00360
00361 gzString & operator +=(const gzWideChar wc);
00362
00363 gzString operator +(const char c) const;
00364
00365 gzString operator +(const gzWideChar wc) const;
00366
00367 gzBool operator !() const { return (m_string == NULL) ? TRUE : (m_string[0] == '\0'); }
00368
00369 char & operator ()(const gzUShort index);
00370
00371 gzString operator ()(const gzUShort index , const gzUShort len) const;
00372
00373
00374
00375 GZ_BASE_EXPORT friend gzBool operator ==(const gzString &str, const char *s);
00376
00377 GZ_BASE_EXPORT friend gzBool operator ==(const char *s, const gzString &str);
00378
00379 GZ_BASE_EXPORT friend gzBool operator ==(const gzString &str1, const gzString &str2);
00380
00381 GZ_BASE_EXPORT friend gzBool operator !=(const gzString &str, const char *s);
00382
00383 GZ_BASE_EXPORT friend gzBool operator !=(const char *s, const gzString &str);
00384
00385 GZ_BASE_EXPORT friend gzBool operator !=(const gzString &str1, const gzString &str2);
00386
00387 GZ_BASE_EXPORT friend gzBool operator <(const gzString &str, const char *s);
00388
00389 GZ_BASE_EXPORT friend gzBool operator <(const char *s, const gzString &str);
00390
00391 GZ_BASE_EXPORT friend gzBool operator <(const gzString &str1, const gzString &str2);
00392
00393 GZ_BASE_EXPORT friend gzBool operator >(const gzString &str, const char *s);
00394
00395 GZ_BASE_EXPORT friend gzBool operator >(const char *s, const gzString &str);
00396
00397 GZ_BASE_EXPORT friend gzBool operator >(const gzString &str1, const gzString &str2);
00398
00399 GZ_BASE_EXPORT friend gzBool operator <=(const gzString &str, const char *s);
00400
00401 GZ_BASE_EXPORT friend gzBool operator <=(const char *s, const gzString &str);
00402
00403 GZ_BASE_EXPORT friend gzBool operator <=(const gzString &str1, const gzString &str2);
00404
00405 GZ_BASE_EXPORT friend gzBool operator >=(const gzString &str, const char *s);
00406
00407 GZ_BASE_EXPORT friend gzBool operator >=(const char *s, const gzString &str);
00408
00409 GZ_BASE_EXPORT friend gzBool operator >=(const gzString &str1, const gzString &str2);
00410
00411
00412
00413 static gzString spaces(gzUShort count,const char fillChar=' ');
00414
00415 private:
00416
00417 gzChar mutable *m_string;
00418 gzUShort m_len;
00419 gzUShort mutable m_uniqueID;
00420 gzULong m_hash;
00421
00422 };
00423
00424
00426 const gzString GZ_EMPTY_STRING;
00427
00429 const gzUShort GZ_MAX_SYSTEM_UNIQUE_ID=65535;
00430
00432 const gzUShort GZ_MAX_BASE_UNIQUE_ID=500;
00433
00434 class GZ_BASE_EXPORT gzUniqueString : public gzString
00435 {
00436 public:
00437 gzUniqueString(const gzString ©,gzUShort uniqueID=0);
00438 gzUniqueString(gzUShort uniqueID);
00439
00440 static gzUShort getNextFreeId();
00441 static gzBool isFreeId(gzUShort id);
00442 };
00443
00445 enum gzBeepType
00446 {
00447 GZ_BEEP_DEFAULT,
00448 GZ_BEEP_ASTERISK,
00449 GZ_BEEP_EXCLAMATION,
00450 GZ_BEEP_HAND,
00451 GZ_BEEP_QUESTION,
00452 GZ_BEEP_OK
00453 };
00454
00455
00456
00457
00458
00460 GZ_BASE_EXPORT gzDouble gzRandom();
00461
00463 GZ_BASE_EXPORT const gzDouble &gzRandom(gzULong seqIndex);
00464
00466 GZ_BASE_EXPORT gzBool gzIsPowerOfTwo(gzDouble number);
00467
00469 GZ_BASE_EXPORT gzDouble gzGetUpperPowerOfTwo(gzDouble number);
00470
00472 GZ_BASE_EXPORT gzLong gzGetUpperPowerOfTwoExponent(gzDouble number);
00473
00475 GZ_BASE_EXPORT gzVoid gzLtoA( char * buffer , gzLongLong number , gzUByte radix , gzLong precision=0 , gzLong *len=NULL , gzBool upper=FALSE);
00476
00478 GZ_BASE_EXPORT gzVoid gzLtoA( gzWideChar * buffer , gzLongLong number , gzUByte radix , gzLong precision=0 , gzLong *len=NULL , gzBool upper=FALSE);
00479
00481 GZ_BASE_EXPORT gzVoid gzULtoA( char * buffer , gzULongLong number , gzUByte radix , gzLong precision=0 , gzLong *len=NULL , gzBool upper=FALSE);
00482
00484 GZ_BASE_EXPORT gzVoid gzULtoA( gzWideChar * buffer , gzULongLong number , gzUByte radix , gzLong precision=0 , gzLong *len=NULL , gzBool upper=FALSE);
00485
00487 GZ_BASE_EXPORT gzVoid gzULtoIdent( char * buffer , gzULongLong number , gzLong precision=0 , gzLong *len=NULL );
00488
00490 GZ_BASE_EXPORT gzVoid gzDtoA( char * buffer , gzDouble number , gzLong precision=6 , gzLong *len=NULL);
00491
00493 GZ_BASE_EXPORT gzVoid gzDtoA( gzWideChar * buffer , gzDouble number , gzLong precision=6 , gzLong *len=NULL);
00494
00496 GZ_BASE_EXPORT gzDouble gzFaculty( gzULong num);
00497
00499 GZ_BASE_EXPORT gzDouble gzCombination( gzULong n , gzULong p);
00500
00501 GZ_BASE_EXPORT gzDouble gzPow10(gzShort power);
00502
00504 GZ_BASE_EXPORT gzDouble gzPrecision( gzDouble number , gzULong digits , gzBool round=TRUE);
00505
00507 GZ_BASE_EXPORT gzULong gzUTF8ToULong(const char *adress,gzUByte *size=NULL);
00508
00510 GZ_BASE_EXPORT gzUByte gzULongToUTF8(char *adress,gzULong data);
00511
00513 GZ_BASE_EXPORT gzUByte gzUTF8Size(gzULong data);
00514
00516 GZ_BASE_EXPORT gzUByte gzUTF8Size(const char *adress);
00517
00518 GZ_BASE_EXPORT gzInt gzGetLastSysError();
00519
00520 GZ_BASE_EXPORT gzVoid gzSetLastSysError(gzInt error=0);
00521
00522 GZ_BASE_EXPORT gzString gzGetSysErrorDescription(gzInt error);
00523
00525 GZ_BASE_EXPORT gzString gzYesNo(gzBool value);
00526
00527 GZ_BASE_EXPORT gzBool gzBigEndian();
00528
00529 GZ_BASE_EXPORT gzVoid gzBeep(gzBeepType beepType = GZ_BEEP_DEFAULT);
00530
00531 GZ_BASE_EXPORT gzBool gzIsValidIpAddress(const gzString& ipAddress, gzUInt groups = 4);
00532
00533 GZ_BASE_EXPORT gzBool gzAttachConsole();
00534
00536 GZ_BASE_EXPORT gzString gzRegKeyExpandedString(const gzString &compressed);
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 struct gzTranslation
00553 {
00554 gzString language;
00555 gzString context;
00556 gzString message;
00557 gzString translation;
00558 };
00559
00560 GZ_BASE_EXPORT gzArray<gzTranslation> getDefaultTranslations();
00561
00563 enum gzRegKeyHeader
00564 {
00565 GZ_KEY_LOCAL_MACHINE,
00566 GZ_KEY_CURRENT_USER,
00567 GZ_KEY_CLASSES_ROOT,
00568 };
00569
00571 const gzString GZ_DEFAULT_KEY_HEADER = "software/Saab Training Systems/GizmoSDK";
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00593 class GZ_BASE_EXPORT gzKeyDatabase
00594 {
00595 public:
00596
00597
00598 static gzBool existGlobalKey(gzString key, const gzString & password="");
00599
00600 static gzVoid setGlobalKey(gzString key , gzString value, const gzString & password="");
00601 static gzString getGlobalKey(gzString key, const gzString & password="");
00602 static gzString getDefaultGlobalKey(gzString key, const gzString &defaultValue , const gzString & password="");
00603 static gzBool removeGlobalKey(gzString key, const gzString & password="");
00604
00605
00606 static gzBool existUserKey(gzString key, const gzString & password="", gzBool onlyUserKey=FALSE);
00607
00608 static gzVoid setUserKey(gzString key , gzString value , const gzString & password="");
00609 static gzString getUserKey(gzString key , const gzString & password="" , gzBool onlyUserKey=FALSE);
00610 static gzString getDefaultUserKey(gzString key , const gzString &defaultValue , const gzString & password="" , gzBool onlyUserKey=FALSE);
00611 static gzBool removeUserKey(gzString key , const gzString & password="", gzBool onlyUserKey=FALSE);
00612
00613
00614 static gzVoid setRegKey(gzRegKeyHeader keyRootHeader, gzString keyHeader, const gzString &keyName , const gzString &value);
00615 static gzBool existRegKey(gzRegKeyHeader keyRootHeader, gzString keyHeader, const gzString &keyName );
00616 static gzBool removeRegKey(gzRegKeyHeader keyRootHeader, gzString keyHeader, const gzString &keyName );
00617 static gzString getRegKey(gzRegKeyHeader keyRootHeader, gzString keyHeader, const gzString &keyName );
00618 static gzString getDefaultRegKey(gzRegKeyHeader keyRootHeader, gzString keyHeader, const gzString &keyName ,const gzString &defaultValue );
00619
00620 static gzVoid setDefaultKeyHeader(const gzString &header);
00621 static const gzString & getDefaultKeyHeader();
00622
00623
00624 static gzVoid setLocalRegistry(const gzString &url);
00625
00626 };
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00647 class GZ_BASE_EXPORT gzDirectory
00648 {
00649 public:
00650
00651 static gzString getExtendedFileName(gzString filename);
00652 };
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00669 class GZ_BASE_EXPORT gzDirectoryEntry
00670 {
00671 public:
00672 gzDirectoryEntry(){};
00673
00674 gzBool isDirectory();
00675
00676 gzString getPath();
00677
00678 gzString getEntryName();
00679
00680 private:
00681
00682 friend class gzDirectoryIterator;
00683 gzDirectoryEntry(gzString name , gzString path , gzBool isDirectory);
00684
00685 gzString m_name;
00686 gzString m_path;
00687 gzBool m_isDirectory;
00688 };
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00705 class GZ_BASE_EXPORT gzDirectoryIterator
00706 {
00707 public:
00708 gzDirectoryIterator(const gzString &path , gzBool recursive=FALSE );
00709
00710 virtual ~gzDirectoryIterator();
00711
00712 gzBool foundEntry();
00713
00714 gzDirectoryEntry getEntry();
00715
00716 private:
00717
00718 gzDirHandle m_dirp;
00719 gzDirEntry m_entry;
00720 gzString m_path;
00721 gzBool m_recursive;
00722 gzDirectoryEntry m_currentEntry;
00723 gzDirectoryIterator *m_iterator;
00724 };
00725
00726 class gzSerializeAdapter;
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 class gzNameInterface
00743 {
00744 public:
00745 GZ_BASE_EXPORT gzNameInterface(const gzString &name=GZ_EMPTY_STRING);
00746
00747 GZ_BASE_EXPORT virtual ~gzNameInterface(){};
00748
00749 GZ_BASE_EXPORT const gzString & getName() const;
00750 GZ_BASE_EXPORT gzVoid setName(const gzString &name);
00751
00752 GZ_BASE_EXPORT gzVoid write(gzSerializeAdapter *adapter);
00753 GZ_BASE_EXPORT gzVoid read(gzSerializeAdapter *adapter);
00754 GZ_BASE_EXPORT gzULong getDataSize(gzSerializeAdapter *adapter=NULL) const;
00755
00756
00757 private:
00758
00759 gzLateBindData<gzString> m_name;
00760 };
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00779 class GZ_BASE_EXPORT gzUpdateIDInterface
00780 {
00781 public:
00782
00783 gzUpdateIDInterface(){m_updateID=(gzULong)gzPtr2Val(this);}
00784
00785 gzUpdateIDInterface(const gzUpdateIDInterface ©){m_updateID=(gzULong)gzPtr2Val(this);}
00786
00787 gzUpdateIDInterface & operator=(const gzUpdateIDInterface ©){m_updateID=(gzULong)gzPtr2Val(this);return *this;}
00788
00789 gzULong getUpdateID() { return m_updateID; }
00790
00791 gzVoid setUpdateID(gzULong id) { m_updateID=id; }
00792
00793 gzVoid updateID() { ++m_updateID;}
00794
00795 private:
00796
00797 gzULong m_updateID;
00798 };
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00817 class gzUpdateIDFeatureInterface
00818 {
00819 public:
00820
00821 GZ_BASE_EXPORT gzUpdateIDFeatureInterface();
00822
00823 GZ_BASE_EXPORT gzUpdateIDFeatureInterface(const gzUpdateIDFeatureInterface ©);
00824
00825 GZ_BASE_EXPORT gzUpdateIDFeatureInterface & operator=(const gzUpdateIDFeatureInterface ©);
00826
00827 GZ_BASE_EXPORT gzULong getUpdateID();
00828
00829 GZ_BASE_EXPORT gzVoid setUpdateID(gzULong id);
00830
00831 GZ_BASE_EXPORT gzVoid updateID(gzULong featureMask=0xFFFFFFFFUL);
00832
00833
00834
00835 GZ_BASE_EXPORT gzVoid setFeatureMask(gzULong mask);
00836
00837
00838
00839 GZ_BASE_EXPORT gzVoid resetFeatureMask(gzULong mask=0xFFFFFFFFUL,gzULong lookup=0);
00840
00841 GZ_BASE_EXPORT gzBool checkFeature(gzULong mask,gzULong lookup=0);
00842
00843 private:
00844
00845 class gzUpdateIDFeature
00846 {
00847 public:
00848
00849 gzUpdateIDFeature():m_featureMask(0xFFFFFFFFUL){};
00850
00851 gzULong m_featureMask;
00852 };
00853
00854 gzULong m_updateID;
00855
00856 gzDynamicArray<gzUpdateIDFeature> m_lookup_feature_data;
00857 };
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873 class gzLookupUpdateID
00874 {
00875 public:
00876
00877 GZ_BASE_EXPORT gzLookupUpdateID();
00878
00879 GZ_BASE_EXPORT gzVoid setUpdateID(gzULong lookup,gzULong id);
00880
00881 GZ_BASE_EXPORT gzULong getUpdateID(gzULong lookup);
00882
00883 GZ_BASE_EXPORT gzVoid clear();
00884
00885 private:
00886
00887 class gzLookupUpdateData
00888 {
00889 public:
00890 gzLookupUpdateData():m_id(0){}
00891
00892 gzULong m_id;
00893 };
00894
00895 gzDynamicArray<gzLookupUpdateData> m_lookup_id;
00896 };
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913 class gzUniqueIDManager
00914 {
00915 public:
00916
00917 GZ_BASE_EXPORT gzUniqueIDManager();
00918
00919 GZ_BASE_EXPORT virtual ~gzUniqueIDManager();
00920
00921 GZ_BASE_EXPORT gzULong allocateID();
00922
00923 GZ_BASE_EXPORT gzVoid freeID(gzULong id);
00924
00925 private:
00926
00927 gzQueue<gzULong> m_idRep;
00928
00929 gzULong m_lastID;
00930 };
00931
00932 #endif // __GZ_BASE_H__
00933