00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _util_state_translate_h
00029 #define _util_state_translate_h
00030
00031 #ifdef HAVE_CONFIG_H
00032 #include <scconfig.h>
00033 #endif
00034
00035 #if defined(WORDS_BIGENDIAN)
00036 #define BIGENDIAN 1
00037 #else
00038 #define BIGENDIAN 0
00039 #endif
00040
00043 class TranslateData {
00044 public:
00045 TranslateData();
00046 virtual ~TranslateData();
00047
00049 virtual char format_code();
00050
00053 static TranslateData *vctor(char code);
00054
00057 virtual void to_native (char *, int n);
00060 virtual void to_external(char *, int n);
00061 virtual void to_native (short *, int n);
00062 virtual void to_external(short *, int n);
00063 virtual void to_native (unsigned int *, int n);
00064 virtual void to_external(unsigned int *, int n);
00065 virtual void to_native (int *, int n);
00066 virtual void to_external(int *, int n);
00067 virtual void to_native (long *, int n);
00068 virtual void to_external(long *, int n);
00069 virtual void to_native (float *, int n);
00070 virtual void to_external(float *, int n);
00071 virtual void to_native (double *, int n);
00072 virtual void to_external(double *, int n);
00073
00076 virtual void to_native (char *target, const void *source, int n);
00079 virtual void to_external(void *target, const char *source, int n);
00080 virtual void to_native (short *, const void *, int n);
00081 virtual void to_external(void *, const short *, int n);
00082 virtual void to_native (unsigned int *, const void *, int n);
00083 virtual void to_external(void *, const unsigned int *, int n);
00084 virtual void to_native (int *, const void *, int n);
00085 virtual void to_external(void *, const int *, int n);
00086 virtual void to_native (long *, const void *, int n);
00087 virtual void to_external(void *, const long *, int n);
00088 virtual void to_native (float *, const void *, int n);
00089 virtual void to_external(void *, const float *, int n);
00090 virtual void to_native (double *, const void *, int n);
00091 virtual void to_external(void *, const double *, int n);
00092 };
00093
00096 class TranslateDataByteSwap: public TranslateData {
00097 public:
00098 TranslateDataByteSwap();
00099 virtual ~TranslateDataByteSwap();
00100
00102 virtual char format_code();
00103
00105 virtual void to_native (char *, int n);
00107 virtual void to_external(char *, int n);
00108 virtual void to_native (short *, int n);
00109 virtual void to_external(short *, int n);
00110 virtual void to_native (unsigned int *, int n);
00111 virtual void to_external(unsigned int *, int n);
00112 virtual void to_native (int *, int n);
00113 virtual void to_external(int *, int n);
00114 virtual void to_native (long *, int n);
00115 virtual void to_external(long *, int n);
00116 virtual void to_native (float *, int n);
00117 virtual void to_external(float *, int n);
00118 virtual void to_native (double *, int n);
00119 virtual void to_external(double *, int n);
00120
00122 virtual void to_native (char *, const void *, int n);
00124 virtual void to_external(void *, const char *, int n);
00125 virtual void to_native (short *, const void *, int n);
00126 virtual void to_external(void *, const short *, int n);
00127 virtual void to_native (unsigned int *, const void *, int n);
00128 virtual void to_external(void *, const unsigned int *, int n);
00129 virtual void to_native (int *, const void *, int n);
00130 virtual void to_external(void *, const int *, int n);
00131 virtual void to_native (long *, const void *, int n);
00132 virtual void to_external(void *, const long *, int n);
00133 virtual void to_native (float *, const void *, int n);
00134 virtual void to_external(void *, const float *, int n);
00135 virtual void to_native (double *, const void *, int n);
00136 virtual void to_external(void *, const double *, int n);
00137 };
00138
00139 #if BIGENDIAN
00140 typedef TranslateDataByteSwap TranslateDataLittleEndian;
00141 typedef TranslateData TranslateDataBigEndian;
00142 #else
00143 typedef TranslateDataByteSwap TranslateDataBigEndian;
00144 typedef TranslateData TranslateDataLittleEndian;
00145 #endif
00146
00147 class StateOut;
00148
00152 class TranslateDataOut {
00153 private:
00154 StateOut *so_;
00155 TranslateData *translate_;
00156
00157 enum { bufsize = 8192 };
00158 char buf_[bufsize];
00159 protected:
00160 int putv(const void*d,int s);
00161 public:
00164 TranslateDataOut(StateOut*s, TranslateData*t);
00165 virtual ~TranslateDataOut();
00166
00169 virtual int put(const char*,int);
00170 virtual int put(const short*,int);
00171 virtual int put(const unsigned int*,int);
00172 virtual int put(const int*,int);
00173 virtual int put(const long*,int);
00174 virtual int put(const float*,int);
00175 virtual int put(const double*,int);
00176
00178 TranslateData *translator() { return translate_; }
00179 };
00180
00181 class StateIn;
00182
00186 class TranslateDataIn {
00187 private:
00188 StateIn *si_;
00189 TranslateData *translate_;
00190 protected:
00191 int getv(void*d,int s);
00192 public:
00195 TranslateDataIn(StateIn*s, TranslateData *t);
00196 virtual ~TranslateDataIn();
00197
00200 virtual int get(char*,int);
00201 virtual int get(short*,int);
00202 virtual int get(unsigned int*,int);
00203 virtual int get(int*,int);
00204 virtual int get(long*,int);
00205 virtual int get(float*,int);
00206 virtual int get(double*,int);
00207
00209 TranslateData *translator() { return translate_; }
00210 };
00211
00212 #endif
00213
00214
00215
00216
00217