MPQC  2.3.1
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:
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
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:
112  MsgStateBufRecv();
113 
114  virtual ~MsgStateBufRecv();
115 
118  void set_buffer_size(int);
119 };
120 
124  private:
125  // do not allow copy constructor or assignment
126  MsgStateRecv(const MsgStateRecv&);
127  void operator=(const MsgStateRecv&);
128  public:
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 
198  private:
199  // do not allow copy constructor or assignment
201  void operator=(const BcastStateSend&);
202  public:
205 
206  ~BcastStateSend();
208  void flush();
209 };
210 
215  private:
216  // do not allow copy constructor or assignment
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 
275  private:
276  // do not allow copy constructor or assignment
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:
sc::MsgStateSend
The MsgStateSend is an abstract base class that sends objects to nodes in a MessageGrp.
Definition: mstate.h:45
sc::BcastStateInBin::next_buffer
void next_buffer()
Specializations must implement next_buffer().
sc::MsgStateBufRecv::next_buffer
virtual void next_buffer()=0
Specializations must implement next_buffer().
sc::BcastStateInBin::use_directory
int use_directory()
Returns true of this object uses a directory.
sc::BcastStateRecv
BcastStateRecv does the receive part of a broadcast of an object to all nodes.
Definition: mstate.h:214
sc::BcastState::bcast
void bcast(int &)
Broadcast data to all nodes.
sc::StateRecv::next_buffer
void next_buffer()
Specializations must implement next_buffer().
sc::Ref
A template class that maintains references counts.
Definition: ref.h:332
sc::MsgStateRecv::version
int version(const ClassDesc *)
Returns the version of the ClassDesc.
sc::MsgStateBufRecv
The MsgStateBufRecv is an abstract base class that buffers objects sent through a MessageGrp.
Definition: mstate.h:89
sc::MsgStateSend::set_buffer_size
void set_buffer_size(int)
The buffer size of statein and stateout objects that communicate with each other must match.
sc::MsgStateBufRecv::set_buffer_size
void set_buffer_size(int)
The buffer size of statein and stateout objects that communicate with each other must match.
sc::Ref::pointer
T * pointer() const
Returns a pointer the reference counted object.
Definition: ref.h:383
sc::BcastState::BcastState
BcastState(const Ref< MessageGrp > &, int source=0)
Create a BcastState object. The default source is node 0.
sc::MsgStateSend::put
int put(const ClassDesc *)
I only need to override put(const ClassDesc*) but C++ will hide all of the other put's so I must over...
sc::MsgStateBufRecv::MsgStateBufRecv
MsgStateBufRecv()
Use the default MessageGrp.
sc::StateRecv
StateRecv is a concrete specialization of MsgStateRecv that does the receive part of point to point c...
Definition: mstate.h:178
sc::BcastState::flush
void flush()
Force data to be written.
sc::BcastStateInBin::tell
int tell()
Return the current position in the file.
sc::BcastStateSend::flush
void flush()
Flush the data remaining in the buffer.
sc::StateSend
StateSend is a concrete specialization of MsgStateSend that does the send part of point to point comm...
Definition: mstate.h:157
sc::BcastStateRecv::next_buffer
void next_buffer()
Specializations must implement next_buffer().
sc::StateIn
Restores objects that derive from SavableState.
Definition: statein.h:70
sc::ClassDesc
This class is used to contain information about classes.
Definition: class.h:158
sc::StateSend::flush
void flush()
Flush the buffer.
sc::BcastState::forget_references
void forget_references()
Call the StateOut or StateIn forget_references member.
sc::BcastStateInBin
BcastStateBin reads a file in written by StateInBin on node 0 and broadcasts it to all nodes so state...
Definition: mstate.h:274
sc::SavableState::restore_state
static SavableState * restore_state(StateIn &si)
Restores objects saved with save_state.
sc::StateSend::target
void target(int)
Specify the target node.
sc::MsgStateRecv
The MsgStateRecv is an abstract base class that receives objects from nodes in a MessageGrp.
Definition: mstate.h:123
sc::MsgStateSend::flush
virtual void flush()=0
Specializations must implement flush().
sc::BcastStateInBin::seekable
int seekable()
Return non-zero if seek does anything sensible.
sc::StateOut
Serializes objects that derive from SavableState.
Definition: stateout.h:61
sc::SavableState::save_state
void save_state(StateOut &)
Save the state of the object as specified by the StateOut object.
sc::BcastStateSend
BcastStateSend does the send part of a broadcast of an object to all nodes.
Definition: mstate.h:197
sc::BcastStateRecv::source
void source(int s)
Set the source node.
sc::BcastStateInBin::seek
void seek(int loc)
Set the current position in the file.
sc::StateRecv::source
void source(int)
Specify the source node.
sc::BcastState
This creates and forwards/retrieves data from either a BcastStateRecv or a BcastStateSend depending o...
Definition: mstate.h:232
sc::BcastState::set_buffer_size
void set_buffer_size(int)
Controls the amount of data that is buffered before it is sent.
sc::MsgStateRecv::get
int get(const ClassDesc **)
I only need to override get(ClassDesc**) but C++ will hide all of the other get's so I must override ...

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