MPQC  2.3.1
translate.h
1 
2 // translate.h -- data translation classes for StateIn and StateOut
3 //
4 // Copyright (C) 1997 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_translate_h
29 #define _util_state_translate_h
30 
31 #ifdef HAVE_CONFIG_H
32 #include <scconfig.h>
33 #endif
34 
35 #if defined(WORDS_BIGENDIAN)
36 #define BIGENDIAN 1
37 #else
38 #define BIGENDIAN 0
39 #endif
40 
41 namespace sc {
42 
46  public:
47  TranslateData();
48  virtual ~TranslateData();
49 
51  virtual char format_code();
52 
55  static TranslateData *vctor(char code);
56 
59  virtual void to_native (char *, int n);
62  virtual void to_external(char *, int n);
63  virtual void to_native (short *, int n);
64  virtual void to_external(short *, int n);
65  virtual void to_native (unsigned int *, int n);
66  virtual void to_external(unsigned int *, int n);
67  virtual void to_native (int *, int n);
68  virtual void to_external(int *, int n);
69  virtual void to_native (long *, int n);
70  virtual void to_external(long *, int n);
71  virtual void to_native (float *, int n);
72  virtual void to_external(float *, int n);
73  virtual void to_native (double *, int n);
74  virtual void to_external(double *, int n);
75 
78  virtual void to_native (char *target, const void *source, int n);
81  virtual void to_external(void *target, const char *source, int n);
82  virtual void to_native (short *, const void *, int n);
83  virtual void to_external(void *, const short *, int n);
84  virtual void to_native (unsigned int *, const void *, int n);
85  virtual void to_external(void *, const unsigned int *, int n);
86  virtual void to_native (int *, const void *, int n);
87  virtual void to_external(void *, const int *, int n);
88  virtual void to_native (long *, const void *, int n);
89  virtual void to_external(void *, const long *, int n);
90  virtual void to_native (float *, const void *, int n);
91  virtual void to_external(void *, const float *, int n);
92  virtual void to_native (double *, const void *, int n);
93  virtual void to_external(void *, const double *, int n);
94 };
95 
99  public:
101  virtual ~TranslateDataByteSwap();
102 
104  virtual char format_code();
105 
107  virtual void to_native (char *, int n);
109  virtual void to_external(char *, int n);
110  virtual void to_native (short *, int n);
111  virtual void to_external(short *, int n);
112  virtual void to_native (unsigned int *, int n);
113  virtual void to_external(unsigned int *, int n);
114  virtual void to_native (int *, int n);
115  virtual void to_external(int *, int n);
116  virtual void to_native (long *, int n);
117  virtual void to_external(long *, int n);
118  virtual void to_native (float *, int n);
119  virtual void to_external(float *, int n);
120  virtual void to_native (double *, int n);
121  virtual void to_external(double *, int n);
122 
124  virtual void to_native (char *, const void *, int n);
126  virtual void to_external(void *, const char *, int n);
127  virtual void to_native (short *, const void *, int n);
128  virtual void to_external(void *, const short *, int n);
129  virtual void to_native (unsigned int *, const void *, int n);
130  virtual void to_external(void *, const unsigned int *, int n);
131  virtual void to_native (int *, const void *, int n);
132  virtual void to_external(void *, const int *, int n);
133  virtual void to_native (long *, const void *, int n);
134  virtual void to_external(void *, const long *, int n);
135  virtual void to_native (float *, const void *, int n);
136  virtual void to_external(void *, const float *, int n);
137  virtual void to_native (double *, const void *, int n);
138  virtual void to_external(void *, const double *, int n);
139 };
140 
141 #if BIGENDIAN
144 #else
147 #endif
148 
149 class StateOut;
150 
155  private:
156  StateOut *so_;
157  TranslateData *translate_;
158  // the translation buffer
159  enum { bufsize = 8192 };
160  char buf_[bufsize];
161  protected:
162  int putv(const void*d,int s);
163  public:
167  virtual ~TranslateDataOut();
168 
171  virtual int put(const char*,int);
172  virtual int put(const short*,int);
173  virtual int put(const unsigned int*,int);
174  virtual int put(const int*,int);
175  virtual int put(const long*,int);
176  virtual int put(const float*,int);
177  virtual int put(const double*,int);
178 
180  TranslateData *translator() { return translate_; }
181 };
182 
183 class StateIn;
184 
189  private:
190  StateIn *si_;
191  TranslateData *translate_;
192  protected:
193  int getv(void*d,int s);
194  public:
198  virtual ~TranslateDataIn();
199 
202  virtual int get(char*,int);
203  virtual int get(short*,int);
204  virtual int get(unsigned int*,int);
205  virtual int get(int*,int);
206  virtual int get(long*,int);
207  virtual int get(float*,int);
208  virtual int get(double*,int);
209 
211  TranslateData *translator() { return translate_; }
212 };
213 
214 }
215 
216 #endif
217 
218 // Local Variables:
219 // mode: c++
220 // c-file-style: "CLJ"
221 // End:
sc::TranslateDataByteSwap::to_native
virtual void to_native(char *, int n)
Overridden translation routines exist for all the basic types.
sc::TranslateDataIn::get
virtual int get(char *, int)
Read and translate data.
sc::TranslateData::to_native
virtual void to_native(char *, int n)
Translates to native format in-place.
sc::TranslateDataByteSwap::format_code
virtual char format_code()
Returns a code for the type of format for the external data.
sc::TranslateData::to_external
virtual void to_external(char *, int n)
Translates to external format in-place.
sc::TranslateData::format_code
virtual char format_code()
Returns a code for the type of format for the external data.
sc::TranslateDataByteSwap::to_external
virtual void to_external(char *, int n)
Overridden translation routines exist for all the basic types.
sc::TranslateData::vctor
static TranslateData * vctor(char code)
A virtual constructor that choses a specialization based on the format code.
sc::StateIn
Restores objects that derive from SavableState.
Definition: statein.h:70
sc::TranslateDataOut::put
virtual int put(const char *, int)
Translate and write the data.
sc::TranslateDataIn::TranslateDataIn
TranslateDataIn(StateIn *s, TranslateData *t)
Input data will come from s.
sc::TranslateDataOut::TranslateDataOut
TranslateDataOut(StateOut *s, TranslateData *t)
Write to s using the translation defined by t.
sc::TranslateDataIn
Convert data from other formats.
Definition: translate.h:188
sc::TranslateDataOut::translator
TranslateData * translator()
Returns the translator.
Definition: translate.h:180
sc::TranslateDataOut
Convert data to other formats.
Definition: translate.h:154
sc::StateOut
Serializes objects that derive from SavableState.
Definition: stateout.h:61
sc::TranslateData
Generic data translation.
Definition: translate.h:45
sc::TranslateDataIn::translator
TranslateData * translator()
Return the translator.
Definition: translate.h:211
sc::TranslateDataByteSwap
Data translation to an external representation with bytes swapped.
Definition: translate.h:98

Generated at Sun Jan 26 2020 23:33:05 for MPQC 2.3.1 using the documentation package Doxygen 1.8.16.