MPQC  2.3.1
keyvalval.h
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 
64  private:
65  double _val;
66  public:
67  KeyValValuedouble(): _val(0.0) {}
68  KeyValValuedouble(double v): _val(v) {}
71  KeyValValue::KeyValValueError doublevalue(double&) const;
72  void print(std::ostream &o=ExEnv::out0()) const;
73 };
74 
76  private:
77  int _val;
78  public:
79  KeyValValueboolean(): _val(0) {}
80  KeyValValueboolean(int v): _val(v) {}
83  KeyValValue::KeyValValueError booleanvalue(int&) const;
84  void print(std::ostream &o=ExEnv::out0()) const;
85 };
86 
88  private:
89  float _val;
90  public:
91  KeyValValuefloat(): _val(0.0) {}
92  KeyValValuefloat(float v): _val(v) {}
95  KeyValValue::KeyValValueError floatvalue(float&) const;
96  void print(std::ostream &o=ExEnv::out0()) const;
97 };
98 
100  private:
101  char _val;
102  public:
103  KeyValValuechar(): _val(0) {}
104  KeyValValuechar(char v): _val(v) {}
106  ~KeyValValuechar();
107  KeyValValue::KeyValValueError charvalue(char&) const;
108  void print(std::ostream &o=ExEnv::out0()) const;
109 };
110 
112  private:
113  int _val;
114  public:
115  KeyValValueint(): _val(0) {}
116  KeyValValueint(int v): _val(v) {}
118  ~KeyValValueint();
119  KeyValValue::KeyValValueError intvalue(int&) const;
120  void print(std::ostream &o=ExEnv::out0()) const;
121 };
122 
124  private:
125  size_t _val;
126  public:
127  KeyValValuesize(): _val(0) {}
128  KeyValValuesize(int v): _val(v) {}
130  ~KeyValValuesize();
131  KeyValValue::KeyValValueError sizevalue(size_t&) const;
132  void print(std::ostream &o=ExEnv::out0()) const;
133 };
134 
136  private:
137  char* _val;
138  public:
139  KeyValValuepchar(): _val(0) {}
140  KeyValValuepchar(const char*);
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 
149  private:
150  std::string _val;
151  public:
152  KeyValValuestring() {}
153  KeyValValuestring(const std::string&);
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 
162  private:
163  Ref<DescribedClass> _val;
164  public:
169  KeyValValue::KeyValValueError describedclassvalue(Ref<DescribedClass>&) const;
170  void print(std::ostream &o=ExEnv::out0()) const;
171 };
172 
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);
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:
sc::KeyValValuefloat
Definition: keyvalval.h:87
sc::KeyValValuestring
Definition: keyvalval.h:148
sc::KeyValValueRefDescribedClass
Definition: keyvalval.h:161
sc::Ref
A template class that maintains references counts.
Definition: ref.h:332
sc::KeyValValuesize
Definition: keyvalval.h:123
sc::KeyValValueboolean
Definition: keyvalval.h:75
sc::KeyValValueint
Definition: keyvalval.h:111
sc::KeyValValuechar
Definition: keyvalval.h:99
sc::KeyValValue
Definition: keyvalval.h:40
sc::KeyValValuepchar
Definition: keyvalval.h:135
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::RefCount
The base class for all reference counted objects.
Definition: ref.h:194
sc::KeyValValuedouble
Definition: keyvalval.h:63
sc::KeyValValueString
Definition: keyvalval.h:173

Generated at Sun Jan 26 2020 23:33:04 for MPQC 2.3.1 using the documentation package Doxygen 1.8.16.