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 #ifndef _util_keyval_keyvalval_h
00029 #define _util_keyval_keyvalval_h
00030 #ifdef __GNUG__
00031 #pragma interface
00032 #endif
00033
00034 #include <util/class/class.h>
00035
00036 class KeyValValue: public RefCount {
00037 public:
00038 enum KeyValValueError { OK, WrongType };
00039 public:
00040 KeyValValue() {}
00041 KeyValValue(const KeyValValue&);
00042 virtual ~KeyValValue();
00043
00044 virtual KeyValValue::KeyValValueError doublevalue(double&) const;
00045 virtual KeyValValue::KeyValValueError booleanvalue(int&) const;
00046 virtual KeyValValue::KeyValValueError floatvalue(float&) const;
00047 virtual KeyValValue::KeyValValueError charvalue(char&) const;
00048 virtual KeyValValue::KeyValValueError intvalue(int&) const;
00049 virtual KeyValValue::KeyValValueError pcharvalue(const char*&) const;
00050 virtual KeyValValue::KeyValValueError describedclassvalue(Ref<DescribedClass>&) const;
00051 virtual void print(std::ostream &o=ExEnv::out()) const;
00052 };
00053 std::ostream& operator<<(std::ostream&,const KeyValValue&);
00054
00055
00056
00057 class KeyValValuedouble: public KeyValValue {
00058 private:
00059 double _val;
00060 public:
00061 KeyValValuedouble(): _val(0.0) {}
00062 KeyValValuedouble(double v): _val(v) {}
00063 KeyValValuedouble(const KeyValValuedouble&);
00064 ~KeyValValuedouble();
00065 KeyValValue::KeyValValueError doublevalue(double&) const;
00066 void print(std::ostream &o=ExEnv::out()) const;
00067 };
00068
00069 class KeyValValueboolean: public KeyValValue {
00070 private:
00071 int _val;
00072 public:
00073 KeyValValueboolean(): _val(0) {}
00074 KeyValValueboolean(int v): _val(v) {}
00075 KeyValValueboolean(const KeyValValueboolean&);
00076 ~KeyValValueboolean();
00077 KeyValValue::KeyValValueError booleanvalue(int&) const;
00078 void print(std::ostream &o=ExEnv::out()) const;
00079 };
00080
00081 class KeyValValuefloat: public KeyValValue {
00082 private:
00083 float _val;
00084 public:
00085 KeyValValuefloat(): _val(0.0) {}
00086 KeyValValuefloat(float v): _val(v) {}
00087 KeyValValuefloat(const KeyValValuefloat&);
00088 ~KeyValValuefloat();
00089 KeyValValue::KeyValValueError floatvalue(float&) const;
00090 void print(std::ostream &o=ExEnv::out()) const;
00091 };
00092
00093 class KeyValValuechar: public KeyValValue {
00094 private:
00095 char _val;
00096 public:
00097 KeyValValuechar(): _val(0) {}
00098 KeyValValuechar(char v): _val(v) {}
00099 KeyValValuechar(const KeyValValuechar&);
00100 ~KeyValValuechar();
00101 KeyValValue::KeyValValueError charvalue(char&) const;
00102 void print(std::ostream &o=ExEnv::out()) const;
00103 };
00104
00105 class KeyValValueint: public KeyValValue {
00106 private:
00107 int _val;
00108 public:
00109 KeyValValueint(): _val(0) {}
00110 KeyValValueint(int v): _val(v) {}
00111 KeyValValueint(const KeyValValueint&);
00112 ~KeyValValueint();
00113 KeyValValue::KeyValValueError intvalue(int&) const;
00114 void print(std::ostream &o=ExEnv::out()) const;
00115 };
00116
00117 class KeyValValuepchar: public KeyValValue {
00118 private:
00119 char* _val;
00120 public:
00121 KeyValValuepchar(): _val(0) {}
00122 KeyValValuepchar(const char*);
00123 KeyValValuepchar(const KeyValValuepchar&);
00124 ~KeyValValuepchar();
00125 KeyValValue::KeyValValueError pcharvalue(const char*&) const;
00126 void print(std::ostream &o=ExEnv::out()) const;
00127 };
00128
00129 class KeyValValueRefDescribedClass: public KeyValValue {
00130 private:
00131 Ref<DescribedClass> _val;
00132 public:
00133 KeyValValueRefDescribedClass() {}
00134 KeyValValueRefDescribedClass(const Ref<DescribedClass>& v): _val(v) {}
00135 KeyValValueRefDescribedClass(const KeyValValueRefDescribedClass&);
00136 ~KeyValValueRefDescribedClass();
00137 KeyValValue::KeyValValueError describedclassvalue(Ref<DescribedClass>&) const;
00138 void print(std::ostream &o=ExEnv::out()) const;
00139 };
00140
00141 class KeyValValueString: public KeyValValue {
00142 private:
00143 const char* _val;
00144 char *_val_to_delete;
00145 public:
00146
00147
00148
00149 enum Storage { Copy, Steal, Use };
00150
00151 KeyValValueString(const char*,
00152 KeyValValueString::Storage s = KeyValValueString::Use);
00153 KeyValValueString(char*,
00154 KeyValValueString::Storage s = KeyValValueString::Use);
00155 KeyValValueString(const KeyValValueString&);
00156 ~KeyValValueString();
00157 KeyValValue::KeyValValueError doublevalue(double&) const;
00158 KeyValValue::KeyValValueError booleanvalue(int&) const;
00159 KeyValValue::KeyValValueError floatvalue(float&) const;
00160 KeyValValue::KeyValValueError charvalue(char&) const;
00161 KeyValValue::KeyValValueError intvalue(int&) const;
00162 KeyValValue::KeyValValueError pcharvalue(const char*&) const;
00163 void print(std::ostream &o=ExEnv::out()) const;
00164 };
00165
00166 #endif
00167
00168
00169
00170
00171