| 1 | //
 | 
|---|
| 2 | // keyval.h
 | 
|---|
| 3 | //
 | 
|---|
| 4 | // Copyright (C) 1997 Limit Point Systems, Inc.
 | 
|---|
| 5 | //
 | 
|---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com>
 | 
|---|
| 7 | // Maintainer: LPS
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // This file is part of the SC Toolkit.
 | 
|---|
| 10 | //
 | 
|---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify
 | 
|---|
| 12 | // it under the terms of the GNU Library General Public License as published by
 | 
|---|
| 13 | // the Free Software Foundation; either version 2, or (at your option)
 | 
|---|
| 14 | // any later version.
 | 
|---|
| 15 | //
 | 
|---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful,
 | 
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 19 | // GNU Library General Public License for more details.
 | 
|---|
| 20 | //
 | 
|---|
| 21 | // You should have received a copy of the GNU Library General Public License
 | 
|---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
 | 
|---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 | 
|---|
| 24 | //
 | 
|---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7.
 | 
|---|
| 26 | //
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #ifndef _util_keyval_keyvalval_h
 | 
|---|
| 29 | #define _util_keyval_keyvalval_h
 | 
|---|
| 30 | #ifdef __GNUG__
 | 
|---|
| 31 | #pragma interface
 | 
|---|
| 32 | #endif
 | 
|---|
| 33 | 
 | 
|---|
| 34 | #include <string>
 | 
|---|
| 35 | 
 | 
|---|
| 36 | #include <util/class/class.h>
 | 
|---|
| 37 | 
 | 
|---|
| 38 | namespace sc {
 | 
|---|
| 39 | 
 | 
|---|
| 40 | class KeyValValue: public RefCount {
 | 
|---|
| 41 |   public:
 | 
|---|
| 42 |     enum KeyValValueError { OK, WrongType };
 | 
|---|
| 43 |   public:
 | 
|---|
| 44 |     KeyValValue() {}
 | 
|---|
| 45 |     KeyValValue(const KeyValValue&);
 | 
|---|
| 46 |     virtual ~KeyValValue();
 | 
|---|
| 47 |     // return 1 for success 0, if the datum is of the wrong type
 | 
|---|
| 48 |     virtual KeyValValue::KeyValValueError doublevalue(double&) const;
 | 
|---|
| 49 |     virtual KeyValValue::KeyValValueError booleanvalue(int&) const;
 | 
|---|
| 50 |     virtual KeyValValue::KeyValValueError floatvalue(float&) const;
 | 
|---|
| 51 |     virtual KeyValValue::KeyValValueError charvalue(char&) const;
 | 
|---|
| 52 |     virtual KeyValValue::KeyValValueError intvalue(int&) const;
 | 
|---|
| 53 |     virtual KeyValValue::KeyValValueError sizevalue(size_t&) const;
 | 
|---|
| 54 |     virtual KeyValValue::KeyValValueError pcharvalue(const char*&) const;
 | 
|---|
| 55 |     virtual KeyValValue::KeyValValueError stringvalue(std::string&) const;
 | 
|---|
| 56 |     virtual KeyValValue::KeyValValueError describedclassvalue(Ref<DescribedClass>&) const;
 | 
|---|
| 57 |     virtual void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 58 | };
 | 
|---|
| 59 | std::ostream& operator<<(std::ostream&,const KeyValValue&);
 | 
|---|
| 60 | 
 | 
|---|
| 61 | 
 | 
|---|
| 62 | 
 | 
|---|
| 63 | class KeyValValuedouble: public KeyValValue {
 | 
|---|
| 64 |   private:
 | 
|---|
| 65 |     double _val;
 | 
|---|
| 66 |   public:
 | 
|---|
| 67 |     KeyValValuedouble(): _val(0.0) {}
 | 
|---|
| 68 |     KeyValValuedouble(double v): _val(v) {}
 | 
|---|
| 69 |     KeyValValuedouble(const KeyValValuedouble&);
 | 
|---|
| 70 |     ~KeyValValuedouble();
 | 
|---|
| 71 |     KeyValValue::KeyValValueError doublevalue(double&) const;
 | 
|---|
| 72 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 73 | };
 | 
|---|
| 74 | 
 | 
|---|
| 75 | class KeyValValueboolean: public KeyValValue {
 | 
|---|
| 76 |   private:
 | 
|---|
| 77 |     int _val;
 | 
|---|
| 78 |   public:
 | 
|---|
| 79 |     KeyValValueboolean(): _val(0) {}
 | 
|---|
| 80 |     KeyValValueboolean(int v): _val(v) {}
 | 
|---|
| 81 |     KeyValValueboolean(const KeyValValueboolean&);
 | 
|---|
| 82 |     ~KeyValValueboolean();
 | 
|---|
| 83 |     KeyValValue::KeyValValueError booleanvalue(int&) const;
 | 
|---|
| 84 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 85 | };
 | 
|---|
| 86 | 
 | 
|---|
| 87 | class KeyValValuefloat: public KeyValValue {
 | 
|---|
| 88 |   private:
 | 
|---|
| 89 |     float _val;
 | 
|---|
| 90 |   public:
 | 
|---|
| 91 |     KeyValValuefloat(): _val(0.0) {}
 | 
|---|
| 92 |     KeyValValuefloat(float v): _val(v) {}
 | 
|---|
| 93 |     KeyValValuefloat(const KeyValValuefloat&);
 | 
|---|
| 94 |     ~KeyValValuefloat();
 | 
|---|
| 95 |     KeyValValue::KeyValValueError floatvalue(float&) const;
 | 
|---|
| 96 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 97 | };
 | 
|---|
| 98 | 
 | 
|---|
| 99 | class KeyValValuechar: public KeyValValue {
 | 
|---|
| 100 |   private:
 | 
|---|
| 101 |     char _val;
 | 
|---|
| 102 |   public:
 | 
|---|
| 103 |     KeyValValuechar(): _val(0) {}
 | 
|---|
| 104 |     KeyValValuechar(char v): _val(v) {}
 | 
|---|
| 105 |     KeyValValuechar(const KeyValValuechar&);
 | 
|---|
| 106 |     ~KeyValValuechar();
 | 
|---|
| 107 |     KeyValValue::KeyValValueError charvalue(char&) const;
 | 
|---|
| 108 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 109 | };
 | 
|---|
| 110 | 
 | 
|---|
| 111 | class KeyValValueint: public KeyValValue {
 | 
|---|
| 112 |   private:
 | 
|---|
| 113 |     int _val;
 | 
|---|
| 114 |   public:
 | 
|---|
| 115 |     KeyValValueint(): _val(0) {}
 | 
|---|
| 116 |     KeyValValueint(int v): _val(v) {}
 | 
|---|
| 117 |     KeyValValueint(const KeyValValueint&);
 | 
|---|
| 118 |     ~KeyValValueint();
 | 
|---|
| 119 |     KeyValValue::KeyValValueError intvalue(int&) const;
 | 
|---|
| 120 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 121 | };
 | 
|---|
| 122 | 
 | 
|---|
| 123 | class KeyValValuesize: public KeyValValue {
 | 
|---|
| 124 |   private:
 | 
|---|
| 125 |     size_t _val;
 | 
|---|
| 126 |   public:
 | 
|---|
| 127 |     KeyValValuesize(): _val(0) {}
 | 
|---|
| 128 |     KeyValValuesize(int v): _val(v) {}
 | 
|---|
| 129 |     KeyValValuesize(const KeyValValuesize&);
 | 
|---|
| 130 |     ~KeyValValuesize();
 | 
|---|
| 131 |     KeyValValue::KeyValValueError sizevalue(size_t&) const;
 | 
|---|
| 132 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 133 | };
 | 
|---|
| 134 | 
 | 
|---|
| 135 | class KeyValValuepchar: public KeyValValue {
 | 
|---|
| 136 |   private:
 | 
|---|
| 137 |     char* _val;
 | 
|---|
| 138 |   public:
 | 
|---|
| 139 |     KeyValValuepchar(): _val(0) {}
 | 
|---|
| 140 |     KeyValValuepchar(const char*);
 | 
|---|
| 141 |     KeyValValuepchar(const KeyValValuepchar&);
 | 
|---|
| 142 |     ~KeyValValuepchar();
 | 
|---|
| 143 |     KeyValValue::KeyValValueError pcharvalue(const char*&) const;
 | 
|---|
| 144 |     KeyValValue::KeyValValueError stringvalue(std::string&) const;
 | 
|---|
| 145 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 146 | };
 | 
|---|
| 147 | 
 | 
|---|
| 148 | class KeyValValuestring: public KeyValValue {
 | 
|---|
| 149 |   private:
 | 
|---|
| 150 |     std::string _val;
 | 
|---|
| 151 |   public:
 | 
|---|
| 152 |     KeyValValuestring() {}
 | 
|---|
| 153 |     KeyValValuestring(const std::string&);
 | 
|---|
| 154 |     KeyValValuestring(const KeyValValuestring&);
 | 
|---|
| 155 |     ~KeyValValuestring();
 | 
|---|
| 156 |     KeyValValue::KeyValValueError pcharvalue(const char*&) const;
 | 
|---|
| 157 |     KeyValValue::KeyValValueError stringvalue(std::string&) const;
 | 
|---|
| 158 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 159 | };
 | 
|---|
| 160 | 
 | 
|---|
| 161 | class KeyValValueRefDescribedClass: public KeyValValue {
 | 
|---|
| 162 |   private:
 | 
|---|
| 163 |     Ref<DescribedClass> _val;
 | 
|---|
| 164 |   public:
 | 
|---|
| 165 |     KeyValValueRefDescribedClass() {}
 | 
|---|
| 166 |     KeyValValueRefDescribedClass(const Ref<DescribedClass>& v): _val(v) {}
 | 
|---|
| 167 |     KeyValValueRefDescribedClass(const KeyValValueRefDescribedClass&);
 | 
|---|
| 168 |     ~KeyValValueRefDescribedClass();
 | 
|---|
| 169 |     KeyValValue::KeyValValueError describedclassvalue(Ref<DescribedClass>&) const;
 | 
|---|
| 170 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 171 | };
 | 
|---|
| 172 | 
 | 
|---|
| 173 | class KeyValValueString: public KeyValValue {
 | 
|---|
| 174 |   private:
 | 
|---|
| 175 |     const char* _val;
 | 
|---|
| 176 |     char *_val_to_delete;
 | 
|---|
| 177 |   public:
 | 
|---|
| 178 |     // Copy = copy the string data
 | 
|---|
| 179 |     // Steal = use the passed pointer and delete it in DTOR
 | 
|---|
| 180 |     // Use = use the passed pointer but do not delete it
 | 
|---|
| 181 |     enum Storage { Copy, Steal, Use };
 | 
|---|
| 182 | 
 | 
|---|
| 183 |     KeyValValueString(const char*,
 | 
|---|
| 184 |                       KeyValValueString::Storage s = KeyValValueString::Use);
 | 
|---|
| 185 |     KeyValValueString(char*,
 | 
|---|
| 186 |                       KeyValValueString::Storage s = KeyValValueString::Use);
 | 
|---|
| 187 |     KeyValValueString(const KeyValValueString&);
 | 
|---|
| 188 |     ~KeyValValueString();
 | 
|---|
| 189 |     KeyValValue::KeyValValueError doublevalue(double&) const;
 | 
|---|
| 190 |     KeyValValue::KeyValValueError booleanvalue(int&) const;
 | 
|---|
| 191 |     KeyValValue::KeyValValueError floatvalue(float&) const;
 | 
|---|
| 192 |     KeyValValue::KeyValValueError charvalue(char&) const;
 | 
|---|
| 193 |     KeyValValue::KeyValValueError intvalue(int&) const;
 | 
|---|
| 194 |     KeyValValue::KeyValValueError sizevalue(size_t&) const;
 | 
|---|
| 195 |     KeyValValue::KeyValValueError pcharvalue(const char*&) const;
 | 
|---|
| 196 |     KeyValValue::KeyValValueError stringvalue(std::string&) const;
 | 
|---|
| 197 |     void print(std::ostream &o=ExEnv::out0()) const;
 | 
|---|
| 198 | };
 | 
|---|
| 199 | 
 | 
|---|
| 200 | }
 | 
|---|
| 201 | 
 | 
|---|
| 202 | #endif /* _KeyVal_h */
 | 
|---|
| 203 | 
 | 
|---|
| 204 | // Local Variables:
 | 
|---|
| 205 | // mode: c++
 | 
|---|
| 206 | // c-file-style: "CLJ"
 | 
|---|
| 207 | // End:
 | 
|---|