00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef URBI_UVALUE_HH
00016 # define URBI_UVALUE_HH
00017
00018 namespace urbi
00019 {
00020
00021
00022
00024 enum UDataType
00025 {
00026 DATA_DOUBLE,
00027 DATA_STRING,
00028 DATA_BINARY,
00029 DATA_LIST,
00030 DATA_OBJECT,
00031 DATA_VOID
00032 };
00033
00035 class UList
00036 {
00037 public:
00038 std::vector<UValue *> array;
00039 UList();
00040 UList(const UList &b);
00041 UList & operator = (const UList &b);
00042 ~UList();
00043 UValue & operator [](int i) {return *array[i+offset];}
00044 const UValue & operator [](int i) const {return *array[i+offset];}
00045 int size() const {return array.size();}
00046 void setOffset(int n) { offset = n;};
00047
00048 private:
00049 int offset;
00050 };
00051
00052 class UNamedValue
00053 {
00054 public:
00055 UNamedValue(const std::string& n, UValue *v)
00056 : val(v),name(n)
00057 {}
00058 UNamedValue()
00059 : val(0),name()
00060 {}
00061 UValue *val;
00062 std::string name;
00063 };
00064
00065 class UObjectStruct
00066 {
00067 public:
00068 std::string refName;
00069 std::vector<UNamedValue> array;
00070 UObjectStruct();
00071 UObjectStruct(const UObjectStruct &b);
00072 UObjectStruct & operator = (const UObjectStruct &b);
00073 ~UObjectStruct();
00074 UValue & operator [](const std::string& s);
00075 UNamedValue & operator [](int i) {return array[i];}
00076 int size() {return array.size();}
00077 };
00078
00081 class UValue
00082 {
00083 public:
00084 UDataType type;
00085 ufloat val;
00086 union
00087 {
00088 std::string *stringValue;
00089 UBinary *binary;
00090 UList *list;
00091 UObjectStruct *object;
00092 void *storage;
00093 };
00094
00095 UValue();
00096 UValue(const UValue&);
00097 explicit UValue(ufloat doubleValue);
00098 explicit UValue(int intValue);
00099 explicit UValue(long intValue);
00100 explicit UValue(unsigned int intValue);
00101 explicit UValue(unsigned long intValue);
00102 explicit UValue(char * val);
00103 explicit UValue(void * val);
00104 explicit UValue(const std::string& str);
00105 explicit UValue(const UBinary& b);
00106 explicit UValue(const UList & l);
00107 explicit UValue(const UObjectStruct &o);
00108 explicit UValue(const USound &);
00109 explicit UValue(const UImage &);
00110 operator ufloat() const;
00111 operator std::string() const;
00112 operator int() const {return (int)(ufloat)(*this);}
00113 operator unsigned int() const {return (unsigned int)(ufloat)(*this);}
00114 operator long() const {return (int)(ufloat)(*this);}
00115 operator unsigned long() const {return (unsigned int)(ufloat)(*this);}
00116 operator bool() const {return (bool)(int)(ufloat)(*this);}
00117 operator UBinary() const;
00118 operator UList() const;
00119 operator UImage() const;
00120 operator USound() const;
00121 UValue& operator=(const UValue&);
00122
00123 ~UValue();
00124
00127 int parse(const char* message,
00128 int pos,
00129 std::list<BinaryData> &bins,
00130 std::list<BinaryData>::iterator &binpos);
00131
00133 std::ostream& print (std::ostream& s) const;
00134 };
00135
00136 inline
00137 std::ostream&
00138 operator<<(std::ostream &s, const UValue &v)
00139 {
00140 return v.print (s);
00141 }
00142
00143
00144 }
00145
00146 #endif // ! URBI_UVALUE_HH