MPQC 2.3.1
stateout.h
1//
2// stateout.h
3//
4// Copyright (C) 1998 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_state_stateout_h
29#define _util_state_stateout_h
30
31#ifdef __GNUC__
32#pragma interface
33#endif
34
35#include <string>
36#include <vector>
37#include <map>
38
39#include <util/class/class.h>
40#include <util/state/state.h>
41
42namespace sc {
43
45 public:
46 int num;
47 int size;
48 int type;
49 int offset;
50
51 StateOutData(): num(0), size(0), type(0), offset(0) {}
52};
53
61class StateOut: public DescribedClass {
62 friend class SavableState;
63 friend class TranslateDataOut;
64 private:
65 // do not allow copy constructor or assignment
66 StateOut(const StateOut&);
67 void operator=(const StateOut&);
68 int have_cd_;
69 protected:
70 int dir_loc_loc_;
71 TranslateDataOut *translate_;
72 int copy_references_;
73 int next_object_number_;
74 std::map<Ref<SavableState>,StateOutData> ps_;
75 std::map<ClassDescP,int> classidmap_;
76 int nextclassid_;
77 int node_to_node_;
78 virtual int put_array_void(const void*,int);
79 virtual int putparents(const ClassDesc*);
80
81 void put_directory();
82
83 // The following members are called by friend SavableState
84
85 void have_classdesc() { have_cd_ = 1; }
86 int need_classdesc() { int tmp = have_cd_; have_cd_ = 0; return !tmp; }
87
92 virtual int putobject(const Ref<SavableState> &);
93
95 virtual int put(const ClassDesc*);
96 public:
97 StateOut();
98 virtual ~StateOut();
99
101 virtual void put_header();
102
105 virtual int putstring(const char*);
106
108 virtual int put(const std::string &);
109
111 virtual int put(char r);
112 virtual int put(unsigned int r);
113 virtual int put(int r);
114 virtual int put(bool r);
115 virtual int put(unsigned long r);
116 virtual int put(float r);
117 virtual int put(double r);
120 virtual int put(const char*,int);
121 virtual int put(const unsigned int*,int);
122 virtual int put(const int*,int);
123 virtual int put(const float*,int);
124 virtual int put(const double*,int);
127 virtual int put_array_char(const char*p,int size);
128 virtual int put_array_uint(const unsigned int*p,int size);
129 virtual int put_array_int(const int*p,int size);
130 virtual int put_array_float(const float*p,int size);
131 virtual int put_array_double(const double*p,int size);
132
134 template <class T>
135 int put(typename std::vector<T> &v) {
136 int l = v.size();
137 int r = put(l);
138 if (l) { for (int i=0; i<l; i++) r += put(v[i]); }
139 return r;
140 }
141
151
153 virtual int use_directory();
154
156 virtual void flush();
157
162 int node_to_node() const { return node_to_node_; }
163
166 virtual int tell();
169 virtual void seek(int loc);
172 virtual int seekable();
173 };
174
175}
176
177#endif
178
179// Local Variables:
180// mode: c++
181// c-file-style: "CLJ"
182// End:
This class is used to contain information about classes.
Definition class.h:158
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition class.h:244
A template class that maintains references counts.
Definition ref.h:332
Base class for objects that can save/restore state.
Definition state.h:46
Definition stateout.h:44
Serializes objects that derive from SavableState.
Definition stateout.h:61
void copy_references()
If a reference to an object that has already been written is encountered, copy it instead of generati...
virtual void flush()
Flush out any remaining data.
int node_to_node() const
True if this is a node to node save/restore.
Definition stateout.h:162
virtual int put_array_char(const char *p, int size)
Put arrays of data.
virtual int put(char r)
Write the given datum.
virtual int tell()
Returns the current position in the file.
virtual int putstring(const char *)
This is like put except the length of the char array is determined by interpreting the character arra...
int put(typename std::vector< T > &v)
Write an STL vector of data.
Definition stateout.h:135
virtual void put_header()
Write out header information.
virtual int use_directory()
Returns true if this object uses a directory.
void forget_references()
Don't keep track of pointers to objects.
virtual int seekable()
Return non-zero if tell and seek do anything sensible.
virtual int put(const ClassDesc *)
Write out information about the given ClassDesc.
virtual int put(const char *, int)
Write the given array data.
virtual int put(const std::string &)
Write out a std::string object.
virtual int putobject(const Ref< SavableState > &)
This will prepare StateOut to output a pointer to data.
virtual void seek(int loc)
Set the current position in the file.
Convert data to other formats.
Definition translate.h:154

Generated at Fri Jan 31 2025 00:00:00 for MPQC 2.3.1 using the documentation package Doxygen 1.12.0.