00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef ULXR_VALUE_H
00031 #define ULXR_VALUE_H
00032
00033
00034 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00035
00036 #include <map>
00037 #include <vector>
00038
00039
00040 namespace ulxr {
00041
00042
00046 typedef enum
00047 {
00048 RpcInteger, RpcDouble, RpcBoolean,
00049 RpcStrType, RpcDateTime, RpcBase64,
00050 RpcArray, RpcStruct, RpcVoid
00051 }
00052 ValueType;
00053
00054
00055 class Void;
00056 class Boolean;
00057 class Integer;
00058 class Double;
00059 class Array;
00060 class Struct;
00061 class RpcString;
00062 class Base64;
00063 class DateTime;
00064 class ValueBase;
00065
00066
00070 class ULXR_API_DECL0 Value
00071 {
00072 public:
00073
00076 Value ();
00077
00081 Value (const Value &val);
00082
00086 Value (const Boolean &val);
00087
00091 Value (const Integer &val);
00092
00096 Value (const Double &val);
00097
00101 Value (const Array &val);
00102
00106 Value (const Struct &val);
00107
00111 Value (const RpcString &val);
00112
00116 Value (const Base64 &val);
00117
00121 Value (const DateTime &val);
00122
00123 #ifdef ULXR_USE_INTRINSIC_VALUE_TYPES
00124
00128 Value (const char *val);
00129
00133 Value (const wchar_t *val);
00134
00138 Value (const double &val);
00139
00143 Value (const int &val);
00144
00148 Value (const bool &val);
00149
00150 #endif
00151
00154 virtual ~Value();
00155
00159 Value &operator=(const Value &val);
00160
00166 CppString getSignature(bool deep = false) const;
00167
00174 virtual std::string getWbXml() const;
00175
00183 CppString getXml(int indent = 0) const;
00184
00189 operator Void& ();
00190
00195 operator const Void& () const;
00196
00201 operator Boolean& ();
00206 operator const Boolean& () const;
00207
00212 operator Integer& ();
00213
00218 operator const Integer& () const;
00219
00224 operator Double& ();
00225
00230 operator const Double& () const;
00231
00236 operator Array& ();
00237
00242 operator const Array& () const;
00243
00248 operator Struct& ();
00249
00254 operator const Struct& () const;
00255
00260 operator RpcString& ();
00261
00266 operator const RpcString& () const;
00267
00272 operator Base64& ();
00273
00278 operator const Base64& () const;
00279
00284 operator DateTime& ();
00285
00290 operator const DateTime& () const;
00291
00296 Struct* getStruct();
00297
00302 const Struct* getStruct() const;
00303
00308 Array* getArray();
00309
00314 const Array* getArray() const;
00315
00319 bool isBoolean() const;
00320
00324 bool isVoid() const;
00325
00329 bool isInteger() const;
00330
00334 bool isDouble() const;
00335
00339 bool isArray() const;
00340
00344 bool isStruct() const;
00345
00349 bool isString() const;
00350
00354 bool isBase64() const;
00355
00359 bool isDateTime() const;
00360
00364 ValueType getType() const;
00365
00369 CppString getTypeName() const;
00370
00371 private:
00372
00373 union
00374 {
00375 ValueBase *baseVal;
00376 Void *voidVal;
00377
00378 Boolean *boolVal;
00379 Integer *intVal;
00380 Double *doubleVal;
00381 Array *arrayVal;
00382 Struct *structVal;
00383 RpcString *stringVal;
00384 Base64 *base64Val;
00385 DateTime *dateVal;
00386 };
00387 };
00388
00389
00391
00392
00397 class ULXR_API_DECL0 ValueBase
00398 {
00399 public:
00400
00404 ValueBase (ValueType t);
00405
00408 virtual ~ValueBase ();
00409
00413 bool isVoid() const;
00414
00418 bool isBoolean() const;
00419
00423 bool isInteger() const;
00424
00428 bool isDouble() const;
00429
00433 bool isArray() const;
00434
00438 bool isStruct() const;
00439
00443 bool isString() const;
00444
00448 bool isBase64() const;
00449
00453 bool isDateTime() const;
00454
00458 ValueType getType() const;
00459
00463 virtual ValueBase* cloneValue() const = 0;
00464
00470 virtual CppString getSignature(bool deep = false) const = 0;
00471
00478 virtual std::string getWbXml() const = 0;
00479
00487 virtual CppString getXml(int indent = 0) const = 0;
00488
00492 CppString getTypeName() const;
00493
00494 private:
00495
00496 ValueType type;
00497
00501 ValueBase ();
00502 };
00503
00504
00506
00507
00512 class ULXR_API_DECL0 Void : public ValueBase
00513 {
00514 public:
00515
00519 Void ();
00520
00523 virtual ~Void ();
00524
00528 virtual ValueBase* cloneValue() const;
00529
00535 virtual CppString getSignature(bool deep = false) const;
00536
00540 static CppString getValueName();
00541
00548 virtual std::string getWbXml() const;
00549
00557 virtual CppString getXml(int indent = 0) const;
00558
00559 private:
00560
00561 bool val;
00562 };
00563
00564
00566
00567
00572 class ULXR_API_DECL0 Boolean : public ValueBase
00573 {
00574 public:
00575
00579 Boolean ();
00580
00584 Boolean (bool b);
00585
00589 Boolean (const CppString &s);
00590
00593 virtual ~Boolean ();
00594
00598 bool getBoolean () const;
00599
00603 void setBoolean(const bool newval);
00604
00608 virtual ValueBase* cloneValue() const;
00609
00615 virtual CppString getSignature(bool deep = false) const;
00616
00620 static CppString getValueName();
00621
00628 virtual std::string getWbXml() const;
00629
00637 virtual CppString getXml(int indent = 0) const;
00638
00639 private:
00640
00641 bool val;
00642 };
00643
00644
00646
00647
00652 class ULXR_API_DECL0 Integer : public ValueBase
00653 {
00654 public:
00655
00658 Integer ();
00659
00663 Integer (int i);
00664
00668 Integer (const CppString &s);
00669
00672 virtual ~Integer ();
00673
00677 int getInteger () const;
00678
00682 void setInteger(const int newval);
00683
00687 virtual ValueBase* cloneValue() const;
00688
00694 virtual CppString getSignature(bool deep = false) const;
00695
00699 static CppString getValueName();
00700
00707 virtual std::string getWbXml() const;
00708
00716 virtual CppString getXml(int indent = 0) const;
00717
00718 private:
00719
00720 int val;
00721 };
00722
00723
00725
00726
00733 class ULXR_API_DECL0 Double : public ValueBase
00734 {
00735 public:
00736
00739 Double ();
00740
00744 Double (double d);
00745
00749 Double (const CppString &s);
00750
00753 virtual ~Double ();
00754
00758 double getDouble () const;
00759
00763 void setDouble(const double newval);
00764
00768 virtual ValueBase* cloneValue() const;
00769
00775 virtual CppString getSignature(bool deep = false) const;
00776
00780 static CppString getValueName();
00781
00788 virtual std::string getWbXml() const;
00789
00797 virtual CppString getXml(int indent = 0) const;
00798
00809 static bool setScientificMode(bool scientific);
00810
00811 private:
00812
00813 double val;
00814
00815 static bool scientific;
00816 };
00817
00818
00820
00821
00828 class ULXR_API_DECL0 Array : public ValueBase
00829 {
00830 public:
00831
00834 Array ();
00835
00838 virtual ~Array ();
00839
00843 void addItem(const Value &item);
00844
00850 void setItem(unsigned idx, const Value &item);
00851
00856 Value getItem(unsigned idx);
00857
00861 unsigned size() const;
00862
00866 virtual ValueBase* cloneValue() const;
00867
00874 virtual CppString getSignature(bool deep = false) const;
00875
00879 static CppString getValueName();
00880
00887 virtual std::string getWbXml() const;
00888
00896 virtual CppString getXml(int indent = 0) const;
00897
00900 void clear();
00901
00902 private:
00903
00904 std::vector<Value> values;
00905 };
00906
00907
00910 template<class T>
00911 Array& operator<< (Array& array, const T& t)
00912 {
00913 array.addItem(t);
00914 return array;
00915 }
00916
00918
00919
00927 class ULXR_API_DECL0 Struct : public ValueBase
00928 {
00929 public:
00930
00931 class Member;
00932
00935 Struct ();
00936
00939 virtual ~Struct ();
00940
00945 void addMember(const CppString &name, const Value &item);
00946
00950 std::vector<CppString> getMemberNames() const;
00951
00956 Value getMember(const CppString &name) const;
00957
00962 bool hasMember(const CppString &name) const;
00963
00967 unsigned size() const;
00968
00972 virtual ValueBase* cloneValue() const;
00973
00981 virtual CppString getSignature(bool deep = false) const;
00982
00986 static CppString getValueName();
00987
00994 virtual std::string getWbXml() const;
00995
01003 virtual CppString getXml(int indent = 0) const;
01004
01009 CppString dump_C_decl(const char *name) const;
01010
01013 void clear();
01014
01015 protected:
01016
01017 typedef std::map<CppString, Value> Members;
01018
01021 const Members & getAllMembers() const;
01022
01023 private:
01024
01025 typedef std::pair<CppString, Value> Member_pair;
01026
01027 Members val;
01028 };
01029
01030
01035 class ULXR_API_DECL0 Struct::Member
01036 {
01037 public:
01038
01043 Member(const CppString &str, const Value &val);
01044
01048 const CppString &getName() const;
01049
01053 const Value &getValue() const;
01054
01055 private:
01056
01057 CppString str;
01058 Value t;
01059
01060 };
01061
01063
01064
01065 #ifdef ULXR_STRUCT_MEMBER_FROM_NAME_VALUE
01066
01067 Struct::Member ULXR_API_DECL0 operator<< (const CppString &str, const Value &t);
01068
01069 #endif
01070
01071 Struct::Member ULXR_API_DECL0 make_member (const CppString &str, const Value &t);
01072
01073 Struct ULXR_API_DECL0 & operator<< (Struct &st, const Struct::Member &k);
01074
01075
01077
01078
01089 class ULXR_API_DECL0 RpcString : public ValueBase
01090 {
01091 public:
01092
01095 RpcString ();
01096
01097 #ifdef ULXR_UNICODE
01098
01102 RpcString (const Cpp16BitString &s);
01103
01104 #endif
01105
01109 RpcString (const Cpp8BitString &s);
01110
01113 virtual ~RpcString ();
01114
01115 #ifdef ULXR_UNICODE
01116
01120 void setString(const Cpp16BitString &newval);
01121
01122 #endif
01123
01127 void setString(const Cpp8BitString &newval);
01128
01129 #if (defined(HAVE_ICONV_H) || defined(HAVE_ICONV)) && !defined (ULXR_UNICODE)
01130
01140 void setString(const Cpp8BitString &newval, const char *encoding);
01141
01151 CppString getString (const char *encoding) const;
01152
01153 #endif
01154
01158 CppString getString () const;
01159
01160 #ifdef ULXR_UNICODE
01161
01165 Cpp16BitString getUnicodeString () const;
01166
01167 #endif
01168
01172 virtual ValueBase* cloneValue() const;
01173
01179 virtual CppString getSignature(bool deep = false) const;
01180
01184 static CppString getValueName();
01185
01192 virtual std::string getWbXml() const;
01193
01201 virtual CppString getXml(int indent = 0) const;
01202
01203 private:
01204
01205 CppString val;
01206 };
01207
01208
01210
01211
01223 class ULXR_API_DECL0 DateTime : public ValueBase
01224 {
01225 public:
01226
01229 DateTime ();
01230
01234 DateTime (const CppString &s);
01235
01240 DateTime (const ulxr_time_t &tm);
01241
01244 virtual ~DateTime ();
01245
01249 CppString getDateTime () const;
01250
01254 void setDateTime(const CppString &newval);
01255
01265 void setDateTime (const ulxr_time_t &tm,
01266 bool add_dash = false,
01267 bool add_colon = true);
01268
01272 virtual ValueBase* cloneValue() const;
01273
01279 virtual CppString getSignature(bool deep = false) const;
01280
01284 static CppString getValueName();
01285
01292 virtual std::string getWbXml() const;
01293
01301 virtual CppString getXml(int indent = 0) const;
01302
01303 private:
01304
01305 CppString val;
01306 };
01307
01308
01310
01311
01319 class ULXR_API_DECL0 Base64 : public ValueBase
01320 {
01321 public:
01322
01325 Base64 ();
01326
01330 Base64 (const CppString &s);
01331
01334 virtual ~Base64 ();
01335
01339 CppString getString () const;
01340
01344 CppString getBase64() const;
01345
01349 void setBase64(const CppString s);
01350
01354 void setString(const CppString &newval);
01355
01359 virtual ValueBase* cloneValue() const;
01360
01366 virtual CppString getSignature(bool deep = false) const;
01367
01371 static CppString getValueName();
01372
01379 virtual std::string getWbXml() const;
01380
01388 virtual CppString getXml(int indent = 0) const;
01389
01390 private:
01391
01392 CppString val;
01393 };
01394
01395
01396 }
01397
01398
01399
01400 #endif // ULXR_VALUE_H
01401