Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

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 <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     // return 1 for success 0, if the datum is of the wrong type
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     // Copy = copy the string data
00147     // Steal = use the passed pointer and delete it in DTOR
00148     // Use = use the passed pointer but do not delete it
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 /* _KeyVal_h */
00167 
00168 // Local Variables:
00169 // mode: c++
00170 // c-file-style: "CLJ"
00171 // End:

Generated at Thu Oct 4 18:08:45 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.