- Main Page
- Related Pages
- Classes
- Files

- File List

# statein.h

    00001 //
    00002 // statein.h
    00003 //
    00004 // Copyright (C) 1998 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 #ifndef _util_state_statein_h
    00029 #define _util_state_statein_h
    00030
    00031 #ifdef __GNUC__
    00032 #pragma interface
    00033 #endif
    00034
    00035 #include <string>
    00036 #include <vector>
    00037 #include <map>
    00038
    00039 #include <util/state/state.h>
    00040 #include <util/keyval/keyval.h>
    00041
    00042 namespace sc {
    00043
    00044 class StateInData {
    00045   public:
    00046     Ref<SavableState> ptr;
    00047     int size;
    00048     int type;
    00049     int offset;
    00050
    00051     StateInData(): size(0), type(0), offset(0) {}
    00052 };
    00053
    00054 class StateClassData {
    00055   public:
    00056     int version;
    00057     char *name;
    00058     const ClassDesc *classdesc;
    00059     int ninstance;
    00060   public:
    00061     StateClassData(int v=-1, const ClassDesc *c=0, char *name=0):
    00062       version(v), name(name), classdesc(c), ninstance(0) {}
    00063     StateClassData(const StateClassData &d) { operator=(d); }
    00064     ~StateClassData();
    00065     StateClassData &operator=(const StateClassData &d);
    00066 };
    00067
    00070 class StateIn:  public DescribedClass {
    00071     friend class SavableState;
    00072     friend class TranslateDataIn;
    00073   private:
    00074     // do not allow copy constructor or assignment
    00075     StateIn(const StateIn&);
    00076     void operator=(const StateIn&);
    00077     int have_cd_;
    00078     int dir_loc_;
    00079     char key_[KeyVal::MaxKeywordLength];
    00080     int keylength_;
    00081   protected:
    00082     Ref<KeyVal> override_;
    00083     TranslateDataIn *translate_;
    00084     std::map<int,StateInData> ps_;
    00085     int expected_object_num_;
    00086     std::map<ClassDescP,int> classidmap_;
    00087     std::map<int,StateClassData> classdatamap_;
    00088     int nextclassid_;
    00089     int node_to_node_;
    00090     int version_;
    00091     int date_;
    00092     char userid_[9];
    00093     char format_;
    00094     virtual int get_array_void(void*,int);
    00095
    00096     int push_key(const char *key);
    00097     void pop_key(int n) { key_[n] = '\0'; keylength_ = n; }
    00098     const char *key() { return key_; }
    00099
    00100     void get_directory();
    00101     int directory_location() const { return dir_loc_; }
    00102     void find_and_get_directory();
    00103
    00104     // The following members are called by friend SavableState
    00105
    00111     virtual int getobject(Ref<SavableState> &);
    00112
    00114     virtual int dir_getobject(Ref<SavableState> &, const char *name);
    00115
    00120     virtual void haveobject(int,const Ref<SavableState> &);
    00121
    00124     virtual void nextobject(int);
    00125     virtual void haveobject(const Ref<SavableState> &);
    00126
    00127     void have_classdesc() { have_cd_ = 1; }
    00128     int need_classdesc() { int tmp = have_cd_; have_cd_ = 0; return !tmp; }
    00129
    00134     virtual int get(const ClassDesc**);
    00135   public:
    00136     StateIn();
    00137     virtual ~StateIn();
    00138
    00141     virtual void get_header();
    00142
    00145     virtual int version(const ClassDesc*);
    00146
    00148     virtual int getstring(char*&);
    00149
    00151     virtual int get(std::string&);
    00152
    00154     virtual int get(char&r, const char *keyword = 0);
    00155     virtual int get(unsigned int&r, const char *keyword = 0);
    00156     virtual int get(int&r, const char *keyword = 0);
    00157     virtual int get(bool&r, const char *keyword = 0);
    00158     virtual int get(float&r, const char *keyword = 0);
    00159     virtual int get(double&r, const char *keyword = 0);
    00162     virtual int get(char*&);
    00163     virtual int get(unsigned int*&);
    00164     virtual int get(int*&);
    00165     virtual int get(float*&);
    00166     virtual int get(double*&);
    00169     virtual int get_array_char(char*p,int size);
    00170     virtual int get_array_uint(unsigned int*p,int size);
    00171     virtual int get_array_int(int*p,int size);
    00172     virtual int get_array_float(float*p,int size);
    00173     virtual int get_array_double(double*p,int size);
    00174
    00176     template <class T>
    00177     int get(typename std::vector<T> &v) {
    00178       int l;
    00179       int r = get(l);
    00180       if (l) { v.resize(l); for (int i=0; i<l; i++) r += get(v[i]); }
    00181       return r;
    00182     }
    00183
    00188     int node_to_node() const { return node_to_node_; }
    00189
    00191     virtual int use_directory();
    00192
    00194     virtual int tell();
    00197     virtual void seek(int);
    00200     virtual int seekable();
    00201     int has_directory() const { return dir_loc_ != 0; }
    00202
    00205     virtual void list_objects(std::ostream& = ExEnv::out0());
    00206
    00209     void set_override(const Ref<KeyVal>&kv) { override_ = kv; }
    00211     const Ref<KeyVal> &override() const { return override_; }
    00212   };
    00213
    00214 }
    00215
    00216 #endif
    00217
    00218 // Local Variables:
    00219 // mode: c++
    00220 // c-file-style: "CLJ"
    00221 // End: