![]()
|
keyvalval.h00001 // 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 <util/class/class.h> 00035 00036 namespace sc { 00037 00038 class KeyValValue: public RefCount { 00039 public: 00040 enum KeyValValueError { OK, WrongType }; 00041 public: 00042 KeyValValue() {} 00043 KeyValValue(const KeyValValue&); 00044 virtual ~KeyValValue(); 00045 // return 1 for success 0, if the datum is of the wrong type 00046 virtual KeyValValue::KeyValValueError doublevalue(double&) const; 00047 virtual KeyValValue::KeyValValueError booleanvalue(int&) const; 00048 virtual KeyValValue::KeyValValueError floatvalue(float&) const; 00049 virtual KeyValValue::KeyValValueError charvalue(char&) const; 00050 virtual KeyValValue::KeyValValueError intvalue(int&) const; 00051 virtual KeyValValue::KeyValValueError sizevalue(size_t&) const; 00052 virtual KeyValValue::KeyValValueError pcharvalue(const char*&) const; 00053 virtual KeyValValue::KeyValValueError describedclassvalue(Ref<DescribedClass>&) const; 00054 virtual void print(std::ostream &o=ExEnv::out0()) const; 00055 }; 00056 std::ostream& operator<<(std::ostream&,const KeyValValue&); 00057 00058 00059 00060 class KeyValValuedouble: public KeyValValue { 00061 private: 00062 double _val; 00063 public: 00064 KeyValValuedouble(): _val(0.0) {} 00065 KeyValValuedouble(double v): _val(v) {} 00066 KeyValValuedouble(const KeyValValuedouble&); 00067 ~KeyValValuedouble(); 00068 KeyValValue::KeyValValueError doublevalue(double&) const; 00069 void print(std::ostream &o=ExEnv::out0()) const; 00070 }; 00071 00072 class KeyValValueboolean: public KeyValValue { 00073 private: 00074 int _val; 00075 public: 00076 KeyValValueboolean(): _val(0) {} 00077 KeyValValueboolean(int v): _val(v) {} 00078 KeyValValueboolean(const KeyValValueboolean&); 00079 ~KeyValValueboolean(); 00080 KeyValValue::KeyValValueError booleanvalue(int&) const; 00081 void print(std::ostream &o=ExEnv::out0()) const; 00082 }; 00083 00084 class KeyValValuefloat: public KeyValValue { 00085 private: 00086 float _val; 00087 public: 00088 KeyValValuefloat(): _val(0.0) {} 00089 KeyValValuefloat(float v): _val(v) {} 00090 KeyValValuefloat(const KeyValValuefloat&); 00091 ~KeyValValuefloat(); 00092 KeyValValue::KeyValValueError floatvalue(float&) const; 00093 void print(std::ostream &o=ExEnv::out0()) const; 00094 }; 00095 00096 class KeyValValuechar: public KeyValValue { 00097 private: 00098 char _val; 00099 public: 00100 KeyValValuechar(): _val(0) {} 00101 KeyValValuechar(char v): _val(v) {} 00102 KeyValValuechar(const KeyValValuechar&); 00103 ~KeyValValuechar(); 00104 KeyValValue::KeyValValueError charvalue(char&) const; 00105 void print(std::ostream &o=ExEnv::out0()) const; 00106 }; 00107 00108 class KeyValValueint: public KeyValValue { 00109 private: 00110 int _val; 00111 public: 00112 KeyValValueint(): _val(0) {} 00113 KeyValValueint(int v): _val(v) {} 00114 KeyValValueint(const KeyValValueint&); 00115 ~KeyValValueint(); 00116 KeyValValue::KeyValValueError intvalue(int&) const; 00117 void print(std::ostream &o=ExEnv::out0()) const; 00118 }; 00119 00120 class KeyValValuesize: public KeyValValue { 00121 private: 00122 size_t _val; 00123 public: 00124 KeyValValuesize(): _val(0) {} 00125 KeyValValuesize(int v): _val(v) {} 00126 KeyValValuesize(const KeyValValuesize&); 00127 ~KeyValValuesize(); 00128 KeyValValue::KeyValValueError sizevalue(size_t&) const; 00129 void print(std::ostream &o=ExEnv::out0()) const; 00130 }; 00131 00132 class KeyValValuepchar: public KeyValValue { 00133 private: 00134 char* _val; 00135 public: 00136 KeyValValuepchar(): _val(0) {} 00137 KeyValValuepchar(const char*); 00138 KeyValValuepchar(const KeyValValuepchar&); 00139 ~KeyValValuepchar(); 00140 KeyValValue::KeyValValueError pcharvalue(const char*&) const; 00141 void print(std::ostream &o=ExEnv::out0()) const; 00142 }; 00143 00144 class KeyValValueRefDescribedClass: public KeyValValue { 00145 private: 00146 Ref<DescribedClass> _val; 00147 public: 00148 KeyValValueRefDescribedClass() {} 00149 KeyValValueRefDescribedClass(const Ref<DescribedClass>& v): _val(v) {} 00150 KeyValValueRefDescribedClass(const KeyValValueRefDescribedClass&); 00151 ~KeyValValueRefDescribedClass(); 00152 KeyValValue::KeyValValueError describedclassvalue(Ref<DescribedClass>&) const; 00153 void print(std::ostream &o=ExEnv::out0()) const; 00154 }; 00155 00156 class KeyValValueString: public KeyValValue { 00157 private: 00158 const char* _val; 00159 char *_val_to_delete; 00160 public: 00161 // Copy = copy the string data 00162 // Steal = use the passed pointer and delete it in DTOR 00163 // Use = use the passed pointer but do not delete it 00164 enum Storage { Copy, Steal, Use }; 00165 00166 KeyValValueString(const char*, 00167 KeyValValueString::Storage s = KeyValValueString::Use); 00168 KeyValValueString(char*, 00169 KeyValValueString::Storage s = KeyValValueString::Use); 00170 KeyValValueString(const KeyValValueString&); 00171 ~KeyValValueString(); 00172 KeyValValue::KeyValValueError doublevalue(double&) const; 00173 KeyValValue::KeyValValueError booleanvalue(int&) const; 00174 KeyValValue::KeyValValueError floatvalue(float&) const; 00175 KeyValValue::KeyValValueError charvalue(char&) const; 00176 KeyValValue::KeyValValueError intvalue(int&) const; 00177 KeyValValue::KeyValValueError sizevalue(size_t&) const; 00178 KeyValValue::KeyValValueError pcharvalue(const char*&) const; 00179 void print(std::ostream &o=ExEnv::out0()) const; 00180 }; 00181 00182 } 00183 00184 #endif /* _KeyVal_h */ 00185 00186 // Local Variables: 00187 // mode: c++ 00188 // c-file-style: "CLJ" 00189 // End: Generated at Fri Jan 10 08:14:09 2003 for MPQC 2.1.3 using the documentation package Doxygen 1.2.14. |