MPQC 2.3.1

- Main Page
- Related Pages
- Classes
- Files

- File List

mstate.h
1 //
2 // mstate.h
3 //
4 // Copyright (C) 1996 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 #ifdef __GNUC__
29 #pragma interface
30 #endif
31
32 #ifndef _util_group_mstate_h
33 #define _util_group_mstate_h
34
35 #include <util/state/state.h>
36 #include <util/state/statein.h>
37 #include <util/state/stateout.h>
38 #include <util/group/message.h>
39
40 namespace sc {
41
45 class MsgStateSend: public StateOut {
46 private:
47 // do not allow copy constructor or assignment
48 MsgStateSend(const MsgStateSend&);
49 void operator=(const MsgStateSend&);
50 protected:
51 Ref<MessageGrp> grp;
52 int nbuf; // the number of bytes used in the buffer
53 int bufsize; // the allocated size of the data buffer
54 char* buffer; // the data buffer
55 char* send_buffer; // the buffer used to send data (includes nbuf)
56 int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
57 int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
58
59 int put_array_void(const void*, int);
60 public:
61 MsgStateSend(const Ref<MessageGrp>&);
62 virtual ~MsgStateSend();
63
65 virtual void flush() = 0;
66
69 void set_buffer_size(int);
70
73 int put(const ClassDesc*);
74 int put(char r);
75 int put(unsigned int r);
76 int put(int r);
77 int put(float r);
78 int put(double r);
79 int put(const char*,int);
80 int put(const int*,int);
81 int put(const unsigned int*,int);
82 int put(const float*,int);
83 int put(const double*,int);
84 };
85
89 class MsgStateBufRecv: public StateIn {
90 private:
91 // do not allow copy constructor or assignment
92 MsgStateBufRecv(const MsgStateBufRecv&);
93 void operator=(const MsgStateBufRecv&);
94 protected:
95 Ref<MessageGrp> grp;
96 int nbuf; // the number of bytes used in the buffer
97 int ibuf; // the current pointer withing the buffer
98 int bufsize; // the allocated size of the buffer
99 char* buffer; // the data buffer
100 char* send_buffer; // the buffer used to send data (includes nbuf)
101 int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
102 int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
103
104 int get_array_void(void*,int);
105
107 virtual void next_buffer() = 0;
108 public:
110 MsgStateBufRecv(const Ref<MessageGrp>&);
112 MsgStateBufRecv();
113
114 virtual ~MsgStateBufRecv();
115
118 void set_buffer_size(int);
119 };
120
123 class MsgStateRecv: public MsgStateBufRecv {
124 private:
125 // do not allow copy constructor or assignment
126 MsgStateRecv(const MsgStateRecv&);
127 void operator=(const MsgStateRecv&);
128 public:
130 MsgStateRecv(const Ref<MessageGrp>&);
131
132 virtual ~MsgStateRecv();
133
137 int version(const ClassDesc*);
138
141 int get(const ClassDesc**);
142 int get(char&r, const char *key = 0);
143 int get(unsigned int&r, const char *key = 0);
144 int get(int&r, const char *key = 0);
145 int get(float&r, const char *key = 0);
146 int get(double&r, const char *key = 0);
147 int get(char*&);
148 int get(unsigned int*&);
149 int get(int*&);
150 int get(float*&);
151 int get(double*&);
152 };
153
157 class StateSend: public MsgStateSend {
158 private:
159 // do not allow copy constructor or assignment
160 StateSend(const StateSend&);
161 void operator=(const StateSend&);
162 private:
163 int target_;
164 public:
166 StateSend(const Ref<MessageGrp>&);
167
168 ~StateSend();
170 void target(int);
172 void flush();
173 };
174
178 class StateRecv: public MsgStateRecv {
179 private:
180 // do not allow copy constructor or assignment
181 StateRecv(const StateRecv&);
182 void operator=(const StateRecv&);
183 private:
184 int source_;
185 protected:
186 void next_buffer();
187 public:
189 StateRecv(const Ref<MessageGrp>&);
191 void source(int);
192 };
193
197 class BcastStateSend: public MsgStateSend {
198 private:
199 // do not allow copy constructor or assignment
200 BcastStateSend(const BcastStateSend&);
201 void operator=(const BcastStateSend&);
202 public:
204 BcastStateSend(const Ref<MessageGrp>&);
205
206 ~BcastStateSend();
208 void flush();
209 };
210
214 class BcastStateRecv: public MsgStateRecv {
215 private:
216 // do not allow copy constructor or assignment
217 BcastStateRecv(const BcastStateRecv&);
218 void operator=(const BcastStateRecv&);
219 protected:
220 int source_;
221 void next_buffer();
222 public:
224 BcastStateRecv(const Ref<MessageGrp>&, int source = 0);
226 void source(int s);
227 };
228
232 class BcastState {
233 private:
234 BcastStateRecv *recv_;
235 BcastStateSend *send_;
236 public:
238 BcastState(const Ref<MessageGrp> &, int source = 0);
239
240 ~BcastState();
241
245 void bcast(int &);
246 void bcast(double &);
247 void bcast(int *&, int);
248 void bcast(double *&, int);
249 template <class T> void bcast(Ref<T>&a)
250 {
251 if (recv_) {
252 a << SavableState::restore_state(*recv_);
253 }
254 else if (send_) {
255 SavableState::save_state(a.pointer(),*send_);
256 }
257 }
258
261 void flush();
262
265 void forget_references();
266
268 void set_buffer_size(int);
269 };
270
274 class BcastStateInBin: public MsgStateBufRecv {
275 private:
276 // do not allow copy constructor or assignment
277 BcastStateInBin(const BcastStateRecv&);
278 void operator=(const BcastStateRecv&);
279 protected:
280 int opened_;
281 int file_position_;
282 std::streambuf *buf_;
283
284 void next_buffer();
285 int get_array_void(void*, int);
286 public:
288 BcastStateInBin(const Ref<KeyVal> &);
290 BcastStateInBin(const Ref<MessageGrp>&, const char *filename);
291
292 ~BcastStateInBin();
293
294 virtual int open(const char *name);
295 virtual void close();
296
297 void seek(int loc);
298 int seekable();
299 int tell();
300 int use_directory();
301 };
302
303 }
304
305 #endif
306
307 // Local Variables:
308 // mode: c++
309 // c-file-style: "CLJ"
310 // End: