source: ThirdParty/mpqc_open/src/lib/util/state/translate.h@ 398fcd

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 398fcd was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 7.7 KB
Line 
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
41namespace sc {
42
43/** Generic data translation.
44 */
45class TranslateData {
46 public:
47 TranslateData();
48 virtual ~TranslateData();
49
50 /// Returns a code for the type of format for the external data.
51 virtual char format_code();
52
53 /** A virtual constructor that choses a specialization based on
54 the format code. */
55 static TranslateData *vctor(char code);
56
57 /** Translates to native format in-place.
58 Similar routines exist for all the basic types. */
59 virtual void to_native (char *, int n);
60 /** Translates to external format in-place.
61 Similar routines exist for all the basic types. */
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
76 /** Translates to native format.
77 Similar routines exist for all the basic types. */
78 virtual void to_native (char *target, const void *source, int n);
79 /** Translates to external format.
80 Similar routines exist for all the basic types. */
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
96/** Data translation to an external representation with bytes swapped.
97 */
98class TranslateDataByteSwap: public TranslateData {
99 public:
100 TranslateDataByteSwap();
101 virtual ~TranslateDataByteSwap();
102
103 /// Returns a code for the type of format for the external data.
104 virtual char format_code();
105
106 /// Overridden translation routines exist for all the basic types.
107 virtual void to_native (char *, int n);
108 /// Overridden translation routines exist for all the basic types.
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
123 /// Overridden translation routines exist for all the basic types.
124 virtual void to_native (char *, const void *, int n);
125 /// Overridden translation routines exist for all the basic types.
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
142typedef TranslateDataByteSwap TranslateDataLittleEndian;
143typedef TranslateData TranslateDataBigEndian;
144#else
145typedef TranslateDataByteSwap TranslateDataBigEndian;
146typedef TranslateData TranslateDataLittleEndian;
147#endif
148
149class StateOut;
150
151/** Convert data to other formats.
152 The generated data is inserted into a StateOut object.
153 */
154class TranslateDataOut {
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:
164 /** Write to s using the translation defined by t.
165 The t argument will be deleted by this. */
166 TranslateDataOut(StateOut*s, TranslateData*t);
167 virtual ~TranslateDataOut();
168
169 /** Translate and write the data. A similar member exists for
170 each basic type. */
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
179 /// Returns the translator.
180 TranslateData *translator() { return translate_; }
181};
182
183class StateIn;
184
185/** Convert data from other formats.
186 The data is taken from a StateIn object.
187 */
188class TranslateDataIn {
189 private:
190 StateIn *si_;
191 TranslateData *translate_;
192 protected:
193 int getv(void*d,int s);
194 public:
195 /** Input data will come from s. The t argument will be deleted by this.
196 */
197 TranslateDataIn(StateIn*s, TranslateData *t);
198 virtual ~TranslateDataIn();
199
200 /** Read and translate data. A similar member exists for each basic
201 type. */
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
210 /// Return the translator.
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:
Note: See TracBrowser for help on using the repository browser.