MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
statein.h
1//
2// statein.h
3//
4// Copyright (C) 1998 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_state_statein_h
29#define _util_state_statein_h
30
31#include <string>
32#include <map>
33
34#include <util/state/state.h>
35#include <util/keyval/keyval.h>
36
37namespace sc {
38
50 template <typename T> void FromStateIn(T& t, StateIn& si, int& count);
51
53 public:
55 int size;
56 int type;
57 int offset;
58
59 StateInData(): size(0), type(0), offset(0) {}
60};
61
63 public:
64 int version;
65 char *name;
66 const ClassDesc *classdesc;
67 int ninstance;
68 public:
69 StateClassData(int v=-1, const ClassDesc *c=0, char *name=0):
70 version(v), name(name), classdesc(c), ninstance(0) {}
71 StateClassData(const StateClassData &d) { operator=(d); }
73 StateClassData &operator=(const StateClassData &d);
74};
75
79class StateIn: public DescribedClass {
80 friend class SavableState;
81 friend class TranslateDataIn;
82 private:
83 // do not allow copy constructor or assignment
84 StateIn(const StateIn&);
85 void operator=(const StateIn&);
86 int have_cd_;
87 int dir_loc_;
88 char key_[KeyVal::MaxKeywordLength];
89 int keylength_;
90 protected:
91 Ref<KeyVal> override_;
92 TranslateDataIn *translate_;
93 std::map<int,StateInData> ps_;
94 int expected_object_num_;
95 std::map<ClassDescP,int> classidmap_;
96 std::map<int,StateClassData> classdatamap_;
97 int nextclassid_;
98 int node_to_node_;
99 int version_;
100 int date_;
101 char userid_[9];
102 char format_;
103 virtual int get_array_void(void*,int);
104
105 int push_key(const char *key);
106 void pop_key(int n) { key_[n] = '\0'; keylength_ = n; }
107 const char *key() { return key_; }
108
109 void get_directory();
110 int directory_location() const { return dir_loc_; }
111 void find_and_get_directory();
112
113 // The following members are called by friend SavableState
114
121
123 virtual int dir_getobject(Ref<SavableState> &, const char *name);
124
129 virtual void haveobject(int,const Ref<SavableState> &);
130
133 virtual void nextobject(int);
134 virtual void haveobject(const Ref<SavableState> &);
135
136 void have_classdesc() { have_cd_ = 1; }
137 int need_classdesc() { int tmp = have_cd_; have_cd_ = 0; return !tmp; }
138
143 virtual int get(const ClassDesc**);
144 public:
145 StateIn();
146 virtual ~StateIn();
147
150 virtual void get_header();
151
154 virtual int version(const ClassDesc*);
155
157 virtual int getstring(char*&);
158
161
162 virtual int get(std::string&);
163 virtual int get(char&r, const char *keyword = 0);
164 virtual int get(unsigned int&r, const char *keyword = 0);
165 virtual int get(int&r, const char *keyword = 0);
166 virtual int get(unsigned long int&r, const char *keyword = 0);
167 virtual int get(long int&r, const char *keyword = 0);
168 virtual int get(bool&r, const char *keyword = 0);
169 virtual int get(float&r, const char *keyword = 0);
170 virtual int get(double&r, const char *keyword = 0);
171
173
177 virtual int get(char*&);
178 virtual int get(unsigned int*&);
179 virtual int get(int*&);
180 virtual int get(unsigned long int*&);
181 virtual int get(long int*&);
182 virtual int get(float*&);
183 virtual int get(double*&);
185
189 virtual int get_array_char(char*p,int size);
190 virtual int get_array_uint(unsigned int*p,int size);
191 virtual int get_array_int(int*p,int size);
192 virtual int get_array_ulong(unsigned long*p,int size);
193 virtual int get_array_long(long*p,int size);
194 virtual int get_array_float(float*p,int size);
195 virtual int get_array_double(double*p,int size);
197
204 template <template <typename, typename> class Container, class T, class A>
205 int get(Container<T,A> &v) {
206 size_t l;
207 int r = get(l);
208 for (size_t i=0; i<l; i++) {
209 T tmp;
210 FromStateIn(tmp,*this,r);
211 v.push_back(tmp);
212 }
213 return r;
214 }
215
217 template <class T, class A>
218 int get(std::vector<T, A> &v) {
219 size_t l;
220 int r = get(l);
221 v.reserve(l);
222 for (size_t i=0; i<l; i++) {
223 T e;
224 FromStateIn(e,*this,r);
225 v.push_back(e);
226 }
227 return r;
228 }
229
231 template <typename Key, typename Compare, typename Alloc>
232 int get(std::set<Key,Compare,Alloc>& s) {
233 typedef std::set<Key,Compare,Alloc> Set;
234 size_t size;
235 int r = get(size);
236 if (size) {
237 for(size_t i=0; i<size; ++i) {
238 Key k;
239 FromStateIn(k,*this,r);
240 s.insert(k);
241 }
242 }
243 return r;
244 }
245
247 template <typename Key, typename Value>
248 int get(std::map<Key,Value>& map) {
249 typedef std::map<Key,Value> Map;
250 size_t size;
251 int r = get(size);
252 if (size) {
253 for(size_t i=0; i<size; ++i) {
254 std::pair<Key,Value> v;
255 r += get(v);
256 map[v.first] = v.second;
257 }
258 }
259 return r;
260 }
261
263 template <typename L, typename R>
264 int get(std::pair<L,R>& v) {
265 int s = 0;
266 FromStateIn(v.first,*this,s);
267 FromStateIn(v.second,*this,s);
268 return s;
269 }
271
276 int node_to_node() const { return node_to_node_; }
277
279 virtual int use_directory();
280
282 virtual int tell();
285 virtual void seek(int);
288 virtual int seekable();
289 int has_directory() const { return dir_loc_ != 0; }
290
293 virtual void list_objects(std::ostream& = ExEnv::out0());
294
297 void set_override(const Ref<KeyVal>&kv) { override_ = kv; }
299 const Ref<KeyVal> &override() const { return override_; }
300 };
301
305 template <typename T> void FromStateIn(T& t, StateIn& so, int& count) {
306 count += so.get(t);
307 }
308
310 template <typename T> void FromStateIn(Ref<T>& t, StateIn& so, int& count) {
312 }
314
315} // namespace sc
316
317#endif
318
319// Local Variables:
320// mode: c++
321// c-file-style: "CLJ"
322// End:
This class is used to contain information about classes.
Definition class.h:147
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition class.h:233
static std::ostream & out0()
Return an ostream that writes from node 0.
A template class that maintains references counts.
Definition ref.h:361
Base class for objects that can save/restore state.
Definition state.h:45
static SavableState * restore_state(StateIn &si)
Restores objects saved with save_state.
Definition statein.h:62
Definition statein.h:52
Restores fundamental and user-defined types from images created with StateOut.
Definition statein.h:79
virtual int tell()
Return the current position in the file.
virtual int seekable()
Return non-zero if seek does anything sensible.
int get(std::set< Key, Compare, Alloc > &s)
Read an std::set. This also works if Key or Value is a Ref to a SavableState.
Definition statein.h:232
int get(std::map< Key, Value > &map)
Read an std::map. This also works if Key or Value is a Ref to a SavableState.
Definition statein.h:248
virtual void seek(int)
Set the current position in the file.
virtual int version(const ClassDesc *)
Returns the version of the ClassDesc in the persistent object or -1 if info on the ClassDesc doesn't ...
virtual void haveobject(int, const Ref< SavableState > &)
When storage has been allocated during object restoration, this routine is called with the object ref...
virtual int dir_getobject(Ref< SavableState > &, const char *name)
This restores objects that are listed in the directory.
virtual int get(const ClassDesc **)
This restores ClassDesc's.
virtual int getobject(Ref< SavableState > &)
This is used to restore an object.
void set_override(const Ref< KeyVal > &kv)
Give this StateIn a KeyVal object that is used to override values.
Definition statein.h:297
int get(Container< T, A > &v)
Read a Container that could be a standard (non-associative) C++ container such as std::vector or std:...
Definition statein.h:205
virtual void get_header()
Read in the header information.
virtual int use_directory()
Returns true of this object uses a directory.
int get(std::pair< L, R > &v)
Read an std::pair.
Definition statein.h:264
virtual void nextobject(int)
A call to nextobject followed by havepointer(int) is equiv to havepointer(int,void**);.
int node_to_node() const
True if this is a node to node save/restore.
Definition statein.h:276
int get(std::vector< T, A > &v)
"Specialization" of the above get() to an std::vector
Definition statein.h:218
virtual void list_objects(std::ostream &=ExEnv::out0())
List all the objects to the stream.
virtual int getstring(char *&)
This restores strings saved with StateOut::putstring.
Convert data from other formats.
Definition translate.h:197
std::vector< int > map(const GaussianBasisSet &B, const GaussianBasisSet &A)
same as operator<<, except A does not have to be contained in B, map[a] = -1 if function a is not in ...
void FromStateIn(Atom &a, StateIn &si, int &count)
reads Atom from sc::StateIn
Contains all MPQC code up to version 3.
Definition mpqcin.h:14

Generated at Wed Sep 25 2024 02:45:31 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.