keyvalval.h

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

Generated at Mon Dec 3 23:23:38 2007 for MPQC 2.3.1 using the documentation package Doxygen 1.5.2.