statein.h
//
// statein.h
//
// Copyright (C) 1998 Limit Point Systems, Inc.
//
// Author: Curtis Janssen <cljanss@limitpt.com>
// Maintainer: LPS
//
// This file is part of the SC Toolkit.
//
// The SC Toolkit is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// The SC Toolkit is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
// The U.S. Government is granted a limited license as per AL 91-7.
//
#ifndef _util_state_statein_h
#define _util_state_statein_h
#ifdef __GNUC__
#pragma interface
#endif
#include <string>
#include <vector>
#include <map>
#include <util/state/state.h>
#include <util/keyval/keyval.h>
namespace sc {
class StateInData {
public:
Ref<SavableState> ptr;
int size;
int type;
int offset;
StateInData(): size(0), type(0), offset(0) {}
};
class StateClassData {
public:
int version;
char *name;
const ClassDesc *classdesc;
int ninstance;
public:
StateClassData(int v=-1, const ClassDesc *c=0, char *name=0):
version(v), name(name), classdesc(c), ninstance(0) {}
StateClassData(const StateClassData &d) { operator=(d); }
~StateClassData();
StateClassData &operator=(const StateClassData &d);
};
class StateIn: public DescribedClass {
friend class SavableState;
friend class TranslateDataIn;
private:
// do not allow copy constructor or assignment
StateIn(const StateIn&);
void operator=(const StateIn&);
int have_cd_;
int dir_loc_;
char key_[KeyVal::MaxKeywordLength];
int keylength_;
protected:
Ref<KeyVal> override_;
TranslateDataIn *translate_;
std::map<int,StateInData> ps_;
int expected_object_num_;
std::map<ClassDescP,int> classidmap_;
std::map<int,StateClassData> classdatamap_;
int nextclassid_;
int node_to_node_;
int version_;
int date_;
char userid_[9];
char format_;
virtual int get_array_void(void*,int);
int push_key(const char *key);
void pop_key(int n) { key_[n] = '\0'; keylength_ = n; }
const char *key() { return key_; }
void get_directory();
int directory_location() const { return dir_loc_; }
void find_and_get_directory();
// The following members are called by friend SavableState
virtual int getobject(Ref<SavableState> &);
virtual int dir_getobject(Ref<SavableState> &, const char *name);
virtual void haveobject(int,const Ref<SavableState> &);
virtual void nextobject(int);
virtual void haveobject(const Ref<SavableState> &);
void have_classdesc() { have_cd_ = 1; }
int need_classdesc() { int tmp = have_cd_; have_cd_ = 0; return !tmp; }
virtual int get(const ClassDesc**);
public:
StateIn();
virtual ~StateIn();
virtual void get_header();
virtual int version(const ClassDesc*);
virtual int getstring(char*&);
virtual int get(std::string&);
virtual int get(char&r, const char *keyword = 0);
virtual int get(unsigned int&r, const char *keyword = 0);
virtual int get(int&r, const char *keyword = 0);
virtual int get(bool&r, const char *keyword = 0);
virtual int get(float&r, const char *keyword = 0);
virtual int get(double&r, const char *keyword = 0);
virtual int get(char*&);
virtual int get(unsigned int*&);
virtual int get(int*&);
virtual int get(float*&);
virtual int get(double*&);
virtual int get_array_char(char*p,int size);
virtual int get_array_uint(unsigned int*p,int size);
virtual int get_array_int(int*p,int size);
virtual int get_array_float(float*p,int size);
virtual int get_array_double(double*p,int size);
template <class T>
int get(typename std::vector<T> &v) {
int l;
int r = get(l);
if (l) { v.resize(l); for (int i=0; i<l; i++) r += get(v[i]); }
return r;
}
int node_to_node() const { return node_to_node_; }
virtual int use_directory();
virtual int tell();
virtual void seek(int);
virtual int seekable();
int has_directory() const { return dir_loc_ != 0; }
virtual void list_objects(std::ostream& = ExEnv::out0());
void set_override(const Ref<KeyVal>&kv) { override_ = kv; }
const Ref<KeyVal> &override() const { return override_; }
};
}
#endif
// Local Variables:
// mode: c++
// c-file-style: "CLJ"
// End: