MPQC 2.3.1

- Main Page
- Related Pages
- Classes
- Files

- File List

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 #ifdef __GNUC__
32 #pragma interface
33 #endif
34
35 #include <string>
36 #include <vector>
37 #include <map>
38
39 #include <util/state/state.h>
40 #include <util/keyval/keyval.h>
41
42 namespace sc {
43
44 class StateInData {
45 public:
46 Ref<SavableState> ptr;
47 int size;
48 int type;
49 int offset;
50
51 StateInData(): size(0), type(0), offset(0) {}
52 };
53
54 class StateClassData {
55 public:
56 int version;
57 char *name;
58 const ClassDesc *classdesc;
59 int ninstance;
60 public:
61 StateClassData(int v=-1, const ClassDesc *c=0, char *name=0):
62 version(v), name(name), classdesc(c), ninstance(0) {}
63 StateClassData(const StateClassData &d) { operator=(d); }
64 ~StateClassData();
65 StateClassData &operator=(const StateClassData &d);
66 };
67
70 class StateIn: public DescribedClass {
71 friend class SavableState;
72 friend class TranslateDataIn;
73 private:
74 // do not allow copy constructor or assignment
75 StateIn(const StateIn&);
76 void operator=(const StateIn&);
77 int have_cd_;
78 int dir_loc_;
79 char key_[KeyVal::MaxKeywordLength];
80 int keylength_;
81 protected:
82 Ref<KeyVal> override_;
83 TranslateDataIn *translate_;
84 std::map<int,StateInData> ps_;
85 int expected_object_num_;
86 std::map<ClassDescP,int> classidmap_;
87 std::map<int,StateClassData> classdatamap_;
88 int nextclassid_;
89 int node_to_node_;
90 int version_;
91 int date_;
92 char userid_[9];
93 char format_;
94 virtual int get_array_void(void*,int);
95
96 int push_key(const char *key);
97 void pop_key(int n) { key_[n] = '\0'; keylength_ = n; }
98 const char *key() { return key_; }
99
100 void get_directory();
101 int directory_location() const { return dir_loc_; }
102 void find_and_get_directory();
103
104 // The following members are called by friend SavableState
105
111 virtual int getobject(Ref<SavableState> &);
112
114 virtual int dir_getobject(Ref<SavableState> &, const char *name);
115
120 virtual void haveobject(int,const Ref<SavableState> &);
121
124 virtual void nextobject(int);
125 virtual void haveobject(const Ref<SavableState> &);
126
127 void have_classdesc() { have_cd_ = 1; }
128 int need_classdesc() { int tmp = have_cd_; have_cd_ = 0; return !tmp; }
129
134 virtual int get(const ClassDesc**);
135 public:
136 StateIn();
137 virtual ~StateIn();
138
141 virtual void get_header();
142
145 virtual int version(const ClassDesc*);
146
148 virtual int getstring(char*&);
149
151 virtual int get(std::string&);
152
154 virtual int get(char&r, const char *keyword = 0);
155 virtual int get(unsigned int&r, const char *keyword = 0);
156 virtual int get(int&r, const char *keyword = 0);
157 virtual int get(bool&r, const char *keyword = 0);
158 virtual int get(float&r, const char *keyword = 0);
159 virtual int get(double&r, const char *keyword = 0);
162 virtual int get(char*&);
163 virtual int get(unsigned int*&);
164 virtual int get(int*&);
165 virtual int get(float*&);
166 virtual int get(double*&);
169 virtual int get_array_char(char*p,int size);
170 virtual int get_array_uint(unsigned int*p,int size);
171 virtual int get_array_int(int*p,int size);
172 virtual int get_array_float(float*p,int size);
173 virtual int get_array_double(double*p,int size);
174
176 template <class T>
177 int get(typename std::vector<T> &v) {
178 int l;
179 int r = get(l);
180 if (l) { v.resize(l); for (int i=0; i<l; i++) r += get(v[i]); }
181 return r;
182 }
183
188 int node_to_node() const { return node_to_node_; }
189
191 virtual int use_directory();
192
194 virtual int tell();
197 virtual void seek(int);
200 virtual int seekable();
201 int has_directory() const { return dir_loc_ != 0; }
202
205 virtual void list_objects(std::ostream& = ExEnv::out0());
206
209 void set_override(const Ref<KeyVal>&kv) { override_ = kv; }
211 const Ref<KeyVal> &override() const { return override_; }
212 };
213
214 }
215
216 #endif
217
218 // Local Variables:
219 // mode: c++
220 // c-file-style: "CLJ"
221 // End: