MPQC  3.0.0-alpha
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 #ifndef _util_group_mstate_h
29 #define _util_group_mstate_h
30 
31 #include <util/state/state.h>
32 #include <util/state/statein.h>
33 #include <util/state/stateout.h>
34 #include <util/group/message.h>
35 
36 namespace sc {
37 
41 class MsgStateSend: public StateOut {
42  private:
43  // do not allow copy constructor or assignment
44  MsgStateSend(const MsgStateSend&);
45  void operator=(const MsgStateSend&);
46  protected:
47  Ref<MessageGrp> grp;
48  int nbuf; // the number of bytes used in the buffer
49  int bufsize; // the allocated size of the data buffer
50  char* buffer; // the data buffer
51  char* send_buffer; // the buffer used to send data (includes nbuf)
52  int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
53  int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
54 
55  int put_array_void(const void*, int);
56  public:
58  virtual ~MsgStateSend();
59 
61  virtual void flush() = 0;
62 
65  void set_buffer_size(int);
66 
69  int put(const ClassDesc*);
70  int put(const std::string&);
71  int put(char r);
72  int put(unsigned int r);
73  int put(int r);
74  int put(unsigned long r);
75  int put(bool r);
76  int put(long 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 long*,int);
83  int put(const unsigned long*,int);
84  int put(const float*,int);
85  int put(const double*,int);
86 };
87 
91 class MsgStateBufRecv: public StateIn {
92  private:
93  // do not allow copy constructor or assignment
95  void operator=(const MsgStateBufRecv&);
96  protected:
97  Ref<MessageGrp> grp;
98  int nbuf; // the number of bytes used in the buffer
99  int ibuf; // the current pointer withing the buffer
100  int bufsize; // the allocated size of the buffer
101  char* buffer; // the data buffer
102  char* send_buffer; // the buffer used to send data (includes nbuf)
103  int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
104  int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
105 
106  int get_array_void(void*,int);
107 
109  virtual void next_buffer() = 0;
110  public:
114  MsgStateBufRecv();
115 
116  virtual ~MsgStateBufRecv();
117 
120  void set_buffer_size(int);
121 };
122 
126  private:
127  // do not allow copy constructor or assignment
128  MsgStateRecv(const MsgStateRecv&);
129  void operator=(const MsgStateRecv&);
130  public:
133 
134  virtual ~MsgStateRecv();
135 
139  int version(const ClassDesc*);
140 
143  int get(const ClassDesc**);
144  int get(std::string&);
145  int get(char&r, const char *key = 0);
146  int get(unsigned int&r, const char *key = 0);
147  int get(int&r, const char *key = 0);
148  int get(unsigned long&r, const char *key = 0);
149  int get(long&r, const char *key = 0);
150  int get(bool&r, const char *key = 0);
151  int get(float&r, const char *key = 0);
152  int get(double&r, const char *key = 0);
153  int get(char*&);
154  int get(unsigned int*&);
155  int get(int*&);
156  int get(unsigned long*&);
157  int get(long*&);
158  int get(float*&);
159  int get(double*&);
160 };
161 
165 class StateSend: public MsgStateSend {
166  private:
167  // do not allow copy constructor or assignment
168  StateSend(const StateSend&);
169  void operator=(const StateSend&);
170  private:
171  int type_;
172  int target_;
173  public:
175  StateSend(const Ref<MessageGrp>&);
176 
177  ~StateSend();
179  void target(int);
181  int get_target() const { return target_; }
183  void type(int);
185  int get_type() const { return type_; }
187  void flush();
188 };
189 
193 class StateRecv: public MsgStateRecv {
194  private:
195  // do not allow copy constructor or assignment
196  StateRecv(const StateRecv&);
197  void operator=(const StateRecv&);
198  private:
199  int source_;
200  int type_;
201  int last_source_;
202  int last_type_;
203  protected:
204  void next_buffer();
205  public:
207  StateRecv(const Ref<MessageGrp>&);
209  void source(int);
211  void type(int);
213  int last_source();
215  int last_type();
216 };
217 
222  private:
223  // do not allow copy constructor or assignment
225  void operator=(const BcastStateSend&);
226  public:
229 
230  ~BcastStateSend();
232  void flush();
233 };
234 
239  private:
240  // do not allow copy constructor or assignment
242  void operator=(const BcastStateRecv&);
243  protected:
244  int source_;
245  void next_buffer();
246  public:
248  BcastStateRecv(const Ref<MessageGrp>&, int source = 0);
250  void source(int s);
251 };
252 
256 class BcastState {
257  private:
258  BcastStateRecv *recv_;
259  BcastStateSend *send_;
260  public:
262  BcastState(const Ref<MessageGrp> &, int source = 0);
263 
264  ~BcastState();
265 
271  void bcast(int &);
272  void bcast(double &);
273  void bcast(int *&, int);
274  void bcast(double *&, int);
275  template <class T> void bcast(Ref<T>&a)
276  {
277  if (recv_) {
278  a << SavableState::restore_state(*recv_);
279  }
280  else if (send_) {
281  SavableState::save_state(a.pointer(),*send_);
282  }
283  }
285 
288  void flush();
289 
292  void forget_references();
293 
295  void set_buffer_size(int);
296 };
297 
302  private:
303  // do not allow copy constructor or assignment
305  void operator=(const BcastStateRecv&);
306  protected:
307  int opened_;
308  int file_position_;
309  std::streambuf *buf_;
310 
311  void next_buffer();
312  int get_array_void(void*, int);
313  public:
315  BcastStateInBin(const Ref<KeyVal> &);
317  BcastStateInBin(const Ref<MessageGrp>&, const char *filename);
318 
319  ~BcastStateInBin();
320 
321  virtual int open(const char *name);
322  virtual void close();
323 
324  void seek(int loc);
325  int seekable();
326  int tell();
327  int use_directory();
328 };
329 
330 }
331 
332 #endif
333 
334 // Local Variables:
335 // mode: c++
336 // c-file-style: "CLJ"
337 // End:
sc::MsgStateSend
The MsgStateSend is an abstract base class that sends objects to nodes in a MessageGrp.
Definition: mstate.h:41
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:238
sc::StateRecv::next_buffer
void next_buffer()
Specializations must implement next_buffer().
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
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:91
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::StateSend::type
void type(int)
Specify the type.
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:413
sc::StateRecv::last_source
int last_source()
Return the source of the last message received.
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:193
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:165
sc::BcastStateRecv::next_buffer
void next_buffer()
Specializations must implement next_buffer().
sc::StateIn
Definition: statein.h:79
sc::ClassDesc
This class is used to contain information about classes.
Definition: class.h:147
sc::StateSend::flush
void flush()
Flush the buffer.
sc::BcastState::forget_references
void forget_references()
Call the StateOut or StateIn forget_references member.
sc::StateRecv::type
void type(int)
Specify the message type.
sc::BcastStateInBin
BcastStateBin reads a file in written by StateInBin on node 0 and broadcasts it to all nodes so state...
Definition: mstate.h:301
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:125
sc::StateSend::get_type
int get_type() const
Return the type.
Definition: mstate.h:185
sc::StateSend::get_target
int get_target() const
Return the target.
Definition: mstate.h:181
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
Definition: stateout.h:71
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:221
sc::StateRecv::last_type
int last_type()
Return the type of the last message received.
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:256
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
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:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.