00001 // 00002 // keyval.h 00003 // 00004 // Copyright (C) 1997 Limit Point Systems, Inc. 00005 // 00006 // Author: Curtis Janssen <cljanss@limitpt.com> 00007 // Maintainer: LPS 00008 // 00009 // This file is part of the SC Toolkit. 00010 // 00011 // The SC Toolkit is free software; you can redistribute it and/or modify 00012 // it under the terms of the GNU Library General Public License as published by 00013 // the Free Software Foundation; either version 2, or (at your option) 00014 // any later version. 00015 // 00016 // The SC Toolkit is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU Library General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Library General Public License 00022 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to 00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 00024 // 00025 // The U.S. Government is granted a limited license as per AL 91-7. 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 <string> 00035 00036 #include <util/class/class.h> 00037 00038 namespace sc { 00039 00041 class KeyValValue: public RefCount { 00042 public: 00043 enum KeyValValueError { OK, WrongType }; 00044 public: 00045 KeyValValue() {} 00046 KeyValValue(const KeyValValue&); 00047 virtual ~KeyValValue(); 00048 virtual KeyValValue::KeyValValueError doublevalue(double&) const; 00049 virtual KeyValValue::KeyValValueError booleanvalue(int&) const; 00050 virtual KeyValValue::KeyValValueError floatvalue(float&) const; 00051 virtual KeyValValue::KeyValValueError charvalue(char&) const; 00052 virtual KeyValValue::KeyValValueError intvalue(int&) const; 00053 virtual KeyValValue::KeyValValueError longvalue(long&) const; 00054 virtual KeyValValue::KeyValValueError sizevalue(size_t&) const; 00055 DEPRECATED virtual KeyValValue::KeyValValueError pcharvalue(const char*&) const; 00056 virtual KeyValValue::KeyValValueError stringvalue(std::string&) const; 00057 virtual KeyValValue::KeyValValueError describedclassvalue(Ref<DescribedClass>&) const; 00058 virtual void print(std::ostream &o=ExEnv::out0()) const; 00059 }; 00060 std::ostream& operator<<(std::ostream&,const KeyValValue&); 00061 00062 00063 00065 class KeyValValuedouble: public KeyValValue { 00066 private: 00067 double _val; 00068 public: 00069 KeyValValuedouble(): _val(0.0) {} 00070 KeyValValuedouble(double v): _val(v) {} 00071 KeyValValuedouble(const KeyValValuedouble&); 00072 ~KeyValValuedouble(); 00073 KeyValValue::KeyValValueError doublevalue(double&) const; 00074 void print(std::ostream &o=ExEnv::out0()) const; 00075 }; 00076 00078 class KeyValValueboolean: public KeyValValue { 00079 private: 00080 int _val; 00081 public: 00082 KeyValValueboolean(): _val(0) {} 00083 KeyValValueboolean(int v): _val(v) {} 00084 KeyValValueboolean(const KeyValValueboolean&); 00085 ~KeyValValueboolean(); 00086 KeyValValue::KeyValValueError booleanvalue(int&) const; 00087 void print(std::ostream &o=ExEnv::out0()) const; 00088 }; 00089 00091 class KeyValValuefloat: public KeyValValue { 00092 private: 00093 float _val; 00094 public: 00095 KeyValValuefloat(): _val(0.0) {} 00096 KeyValValuefloat(float v): _val(v) {} 00097 KeyValValuefloat(const KeyValValuefloat&); 00098 ~KeyValValuefloat(); 00099 KeyValValue::KeyValValueError floatvalue(float&) const; 00100 void print(std::ostream &o=ExEnv::out0()) const; 00101 }; 00102 00104 class KeyValValuechar: public KeyValValue { 00105 private: 00106 char _val; 00107 public: 00108 KeyValValuechar(): _val(0) {} 00109 KeyValValuechar(char v): _val(v) {} 00110 KeyValValuechar(const KeyValValuechar&); 00111 ~KeyValValuechar(); 00112 KeyValValue::KeyValValueError charvalue(char&) const; 00113 void print(std::ostream &o=ExEnv::out0()) const; 00114 }; 00115 00117 class KeyValValueint: public KeyValValue { 00118 private: 00119 int _val; 00120 public: 00121 KeyValValueint(): _val(0) {} 00122 KeyValValueint(int v): _val(v) {} 00123 KeyValValueint(const KeyValValueint&); 00124 ~KeyValValueint(); 00125 KeyValValue::KeyValValueError intvalue(int&) const; 00126 void print(std::ostream &o=ExEnv::out0()) const; 00127 }; 00128 00130 class KeyValValuelong: public KeyValValue { 00131 private: 00132 long _val; 00133 public: 00134 KeyValValuelong(): _val(0) {} 00135 KeyValValuelong(long v): _val(v) {} 00136 KeyValValuelong(const KeyValValuelong&); 00137 ~KeyValValuelong(); 00138 KeyValValue::KeyValValueError longvalue(long&) const; 00139 void print(std::ostream &o=ExEnv::out0()) const; 00140 }; 00141 00143 class KeyValValuesize: public KeyValValue { 00144 private: 00145 size_t _val; 00146 public: 00147 KeyValValuesize(): _val(0) {} 00148 KeyValValuesize(int v): _val(v) {} 00149 KeyValValuesize(const KeyValValuesize&); 00150 ~KeyValValuesize(); 00151 KeyValValue::KeyValValueError sizevalue(size_t&) const; 00152 void print(std::ostream &o=ExEnv::out0()) const; 00153 }; 00154 00156 class KeyValValuepchar: public KeyValValue { 00157 private: 00158 char* _val; 00159 public: 00160 DEPRECATED KeyValValuepchar(): _val(0) {} 00161 DEPRECATED KeyValValuepchar(const char*); 00162 DEPRECATED KeyValValuepchar(const KeyValValuepchar&); 00163 ~KeyValValuepchar(); 00164 DEPRECATED KeyValValue::KeyValValueError pcharvalue(const char*&) const; 00165 KeyValValue::KeyValValueError stringvalue(std::string&) const; 00166 void print(std::ostream &o=ExEnv::out0()) const; 00167 }; 00168 00171 class KeyValValuestring: public KeyValValue { 00172 private: 00173 // This is used to provide compatibility with KeyValValuepchar: 00174 bool _defined; 00175 std::string _val; 00176 public: 00177 KeyValValuestring():_defined(false) {} 00178 KeyValValuestring(const std::string&); 00179 KeyValValuestring(const KeyValValuestring&); 00180 ~KeyValValuestring(); 00182 KeyValValue::KeyValValueError doublevalue(double&) const; 00185 KeyValValue::KeyValValueError booleanvalue(int&) const; 00187 KeyValValue::KeyValValueError floatvalue(float&) const; 00189 KeyValValue::KeyValValueError charvalue(char&) const; 00191 KeyValValue::KeyValValueError intvalue(int&) const; 00193 KeyValValue::KeyValValueError longvalue(long&) const; 00196 KeyValValue::KeyValValueError sizevalue(size_t&) const; 00198 DEPRECATED KeyValValue::KeyValValueError pcharvalue(const char*&) const; 00199 KeyValValue::KeyValValueError stringvalue(std::string&) const; 00200 void print(std::ostream &o=ExEnv::out0()) const; 00201 }; 00202 00204 class KeyValValueRefDescribedClass: public KeyValValue { 00205 private: 00206 Ref<DescribedClass> _val; 00207 public: 00208 KeyValValueRefDescribedClass() {} 00209 KeyValValueRefDescribedClass(const Ref<DescribedClass>& v): _val(v) {} 00210 KeyValValueRefDescribedClass(const KeyValValueRefDescribedClass&); 00211 ~KeyValValueRefDescribedClass(); 00212 KeyValValue::KeyValValueError describedclassvalue(Ref<DescribedClass>&) const; 00213 void print(std::ostream &o=ExEnv::out0()) const; 00214 }; 00215 00217 class KeyValValueString: public KeyValValue { 00218 private: 00219 const char* _val; 00220 char *_val_to_delete; 00221 public: 00222 // Copy = copy the string data 00223 // Steal = use the passed pointer and delete it in DTOR 00224 // Use = use the passed pointer but do not delete it 00225 enum Storage { Copy, Steal, Use }; 00226 00227 DEPRECATED KeyValValueString(const char*, 00228 KeyValValueString::Storage s = KeyValValueString::Use); 00229 DEPRECATED KeyValValueString(char*, 00230 KeyValValueString::Storage s = KeyValValueString::Use); 00231 DEPRECATED KeyValValueString(const KeyValValueString&); 00232 ~KeyValValueString(); 00233 KeyValValue::KeyValValueError doublevalue(double&) const; 00234 KeyValValue::KeyValValueError booleanvalue(int&) const; 00235 KeyValValue::KeyValValueError floatvalue(float&) const; 00236 KeyValValue::KeyValValueError charvalue(char&) const; 00237 KeyValValue::KeyValValueError intvalue(int&) const; 00238 KeyValValue::KeyValValueError longvalue(long&) const; 00239 KeyValValue::KeyValValueError sizevalue(size_t&) const; 00240 DEPRECATED KeyValValue::KeyValValueError pcharvalue(const char*&) const; 00241 KeyValValue::KeyValValueError stringvalue(std::string&) const; 00242 void print(std::ostream &o=ExEnv::out0()) const; 00243 }; 00244 00245 } 00246 00247 #endif /* _KeyVal_h */ 00248 00249 // Local Variables: 00250 // mode: c++ 00251 // c-file-style: "CLJ" 00252 // End: