Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

mstate.h

00001 //
00002 // mstate.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031 
00032 #ifndef _util_group_mstate_h
00033 #define _util_group_mstate_h
00034 
00035 #include <util/state/state.h>
00036 #include <util/state/statein.h>
00037 #include <util/state/stateout.h>
00038 #include <util/group/message.h>
00039 
00043 class MsgStateSend: public StateOut {
00044   private:
00045     // do not allow copy constructor or assignment
00046     MsgStateSend(const MsgStateSend&);
00047     void operator=(const MsgStateSend&);
00048   protected:
00049     Ref<MessageGrp> grp;
00050     int nbuf; // the number of bytes used in the buffer
00051     int bufsize; // the allocated size of the data buffer
00052     char* buffer; // the data buffer
00053     char* send_buffer; // the buffer used to send data (includes nbuf)
00054     int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
00055     int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
00056 
00057     int put_array_void(const void*, int);
00058   public:
00059     MsgStateSend(const Ref<MessageGrp>&);
00060     virtual ~MsgStateSend();
00061 
00063     virtual void flush() = 0;
00064 
00067     void set_buffer_size(int);
00068 
00071     int put(const ClassDesc*);
00072     int put(char r);
00073     int put(unsigned int r);
00074     int put(int r);
00075     int put(float r);
00076     int put(double r);
00077     int put(const char*,int);
00078     int put(const int*,int);
00079     int put(const unsigned int*,int);
00080     int put(const float*,int);
00081     int put(const double*,int);
00082 };
00083 
00087 class MsgStateBufRecv: public StateIn {
00088   private:
00089     // do not allow copy constructor or assignment
00090     MsgStateBufRecv(const MsgStateBufRecv&);
00091     void operator=(const MsgStateBufRecv&);
00092   protected:
00093     Ref<MessageGrp> grp;
00094     int nbuf; // the number of bytes used in the buffer
00095     int ibuf; // the current pointer withing the buffer
00096     int bufsize; // the allocated size of the buffer
00097     char* buffer; // the data buffer
00098     char* send_buffer; // the buffer used to send data (includes nbuf)
00099     int nheader; // nbuf + nheader = the number of bytes in send_buffer to send
00100     int* nbuf_buffer; // the pointer to the nbuf stored in the buffer
00101 
00102     int get_array_void(void*,int);
00103 
00105     virtual void next_buffer() = 0;
00106   public:
00108     MsgStateBufRecv(const Ref<MessageGrp>&);
00110     MsgStateBufRecv();
00111 
00112     virtual ~MsgStateBufRecv();
00113 
00116     void set_buffer_size(int);
00117 };
00118 
00121 class MsgStateRecv: public MsgStateBufRecv {
00122   private:
00123     // do not allow copy constructor or assignment
00124     MsgStateRecv(const MsgStateRecv&);
00125     void operator=(const MsgStateRecv&);
00126   public:
00128     MsgStateRecv(const Ref<MessageGrp>&);
00129 
00130     virtual ~MsgStateRecv();
00131 
00135     int version(const ClassDesc*);
00136 
00139     int get(const ClassDesc**);
00140     int get(char&r, const char *key = 0);
00141     int get(unsigned int&r, const char *key = 0);
00142     int get(int&r, const char *key = 0);
00143     int get(float&r, const char *key = 0);
00144     int get(double&r, const char *key = 0);
00145     int get(char*&);
00146     int get(unsigned int*&);
00147     int get(int*&);
00148     int get(float*&);
00149     int get(double*&);
00150 };
00151 
00155 class StateSend: public MsgStateSend {
00156   private:
00157     // do not allow copy constructor or assignment
00158     StateSend(const StateSend&);
00159     void operator=(const StateSend&);
00160   private:
00161     int target_;
00162   public:
00164     StateSend(const Ref<MessageGrp>&);
00165 
00166     ~StateSend();
00168     void target(int);
00170     void flush();
00171 };
00172 
00176 class StateRecv: public MsgStateRecv {
00177   private:
00178     // do not allow copy constructor or assignment
00179     StateRecv(const StateRecv&);
00180     void operator=(const StateRecv&);
00181   private:
00182     int source_;
00183   protected:
00184     void next_buffer();
00185   public:
00187     StateRecv(const Ref<MessageGrp>&);
00189     void source(int);
00190 };
00191 
00195 class BcastStateSend: public MsgStateSend {
00196   private:
00197     // do not allow copy constructor or assignment
00198     BcastStateSend(const BcastStateSend&);
00199     void operator=(const BcastStateSend&);
00200   public:
00202     BcastStateSend(const Ref<MessageGrp>&);
00203 
00204     ~BcastStateSend();
00206     void flush();
00207 };
00208 
00212 class BcastStateRecv: public MsgStateRecv {
00213   private:
00214     // do not allow copy constructor or assignment
00215     BcastStateRecv(const BcastStateRecv&);
00216     void operator=(const BcastStateRecv&);
00217   protected:
00218     int source_;
00219     void next_buffer();
00220   public:
00222     BcastStateRecv(const Ref<MessageGrp>&, int source = 0);
00224     void source(int s);
00225 };
00226 
00230 class BcastState {
00231   private:
00232     BcastStateRecv *recv_;
00233     BcastStateSend *send_;
00234   public:
00236     BcastState(const Ref<MessageGrp> &, int source = 0);
00237 
00238     ~BcastState();
00239 
00243     void bcast(int &);
00244     void bcast(double &);
00245     void bcast(int *&, int);
00246     void bcast(double *&, int);
00247     template <class T> void bcast(Ref<T>&a)
00248         {
00249           if (recv_) {
00250               a << SavableState::restore_state(*recv_);
00251             }
00252           else if (send_) {
00253               SavableState::save_state(a.pointer(),*send_);
00254             }
00255         }
00256 
00259     void flush();
00260 
00263     void forget_references();
00264 
00266     void set_buffer_size(int);
00267 };
00268 
00272 class BcastStateInBin: public MsgStateBufRecv {
00273   private:
00274     // do not allow copy constructor or assignment
00275     BcastStateInBin(const BcastStateRecv&);
00276     void operator=(const BcastStateRecv&);
00277   protected:
00278     int opened_;
00279     int file_position_;
00280     std::streambuf *buf_;
00281 
00282     void next_buffer();
00283     int get_array_void(void*, int);
00284   public:
00286     BcastStateInBin(const Ref<KeyVal> &);
00288     BcastStateInBin(const Ref<MessageGrp>&, const char *filename);
00289 
00290     ~BcastStateInBin();
00291 
00292     virtual int open(const char *name);
00293     virtual void close();
00294 
00295     void seek(int loc);
00296     int seekable();
00297     int tell();
00298     int use_directory();
00299 };
00300 
00301 #endif
00302 
00303 // Local Variables:
00304 // mode: c++
00305 // c-file-style: "CLJ"
00306 // End:

Generated at Thu Oct 4 18:08:46 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.