- Main Page
- Related Pages
- Classes
- Files

- File List

# translate.h

    00001
    00002 // translate.h -- data translation classes for StateIn and StateOut
    00003 //
    00004 // Copyright (C) 1997 Limit Point Systems, Inc.
    00005 //
    00006 // Author: Curtis Janssen <cljanss@limitpt.com>
    00007 // Maintainer: LPS
    00008 //
    00009 // This file is part of the SC Toolkit.
    00010 //
    00011 // The SC Toolkit is free software; you can redistribute it and/or modify
    00012 // it under the terms of the GNU Library General Public License as published by
    00013 // the Free Software Foundation; either version 2, or (at your option)
    00014 // any later version.
    00015 //
    00016 // The SC Toolkit is distributed in the hope that it will be useful,
    00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00019 // GNU Library General Public License for more details.
    00020 //
    00021 // You should have received a copy of the GNU Library General Public License
    00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
    00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00024 //
    00025 // The U.S. Government is granted a limited license as per AL 91-7.
    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
    00041 namespace sc {
    00042
    00045 class TranslateData {
    00046   public:
    00047     TranslateData();
    00048     virtual ~TranslateData();
    00049
    00051     virtual char format_code();
    00052
    00055     static TranslateData *vctor(char code);
    00056
    00059     virtual void to_native  (char *,   int n);
    00062     virtual void to_external(char *,   int n);
    00063     virtual void to_native  (short *,  int n);
    00064     virtual void to_external(short *,  int n);
    00065     virtual void to_native  (unsigned int *, int n);
    00066     virtual void to_external(unsigned int *, int n);
    00067     virtual void to_native  (int *,    int n);
    00068     virtual void to_external(int *,    int n);
    00069     virtual void to_native  (long *,   int n);
    00070     virtual void to_external(long *,   int n);
    00071     virtual void to_native  (float *,  int n);
    00072     virtual void to_external(float *,  int n);
    00073     virtual void to_native  (double *, int n);
    00074     virtual void to_external(double *, int n);
    00075
    00078     virtual void to_native  (char *target,   const void *source,   int n);
    00081     virtual void to_external(void *target,   const char *source,   int n);
    00082     virtual void to_native  (short *,  const void *,   int n);
    00083     virtual void to_external(void *,   const short *,  int n);
    00084     virtual void to_native  (unsigned int *,    const void *,   int n);
    00085     virtual void to_external(void *,   const unsigned int *,    int n);
    00086     virtual void to_native  (int *,    const void *,   int n);
    00087     virtual void to_external(void *,   const int *,    int n);
    00088     virtual void to_native  (long *,   const void *,   int n);
    00089     virtual void to_external(void *,   const long *,   int n);
    00090     virtual void to_native  (float *,  const void *,   int n);
    00091     virtual void to_external(void *,   const float *,  int n);
    00092     virtual void to_native  (double *, const void *,   int n);
    00093     virtual void to_external(void *,   const double *, int n);
    00094 };
    00095
    00098 class TranslateDataByteSwap: public TranslateData {
    00099   public:
    00100     TranslateDataByteSwap();
    00101     virtual ~TranslateDataByteSwap();
    00102
    00104     virtual char format_code();
    00105
    00107     virtual void to_native  (char *,   int n);
    00109     virtual void to_external(char *,   int n);
    00110     virtual void to_native  (short *,  int n);
    00111     virtual void to_external(short *,  int n);
    00112     virtual void to_native  (unsigned int *, int n);
    00113     virtual void to_external(unsigned int *, int n);
    00114     virtual void to_native  (int *,    int n);
    00115     virtual void to_external(int *,    int n);
    00116     virtual void to_native  (long *,   int n);
    00117     virtual void to_external(long *,   int n);
    00118     virtual void to_native  (float *,  int n);
    00119     virtual void to_external(float *,  int n);
    00120     virtual void to_native  (double *, int n);
    00121     virtual void to_external(double *, int n);
    00122
    00124     virtual void to_native  (char *,   const void *,   int n);
    00126     virtual void to_external(void *,   const char *,   int n);
    00127     virtual void to_native  (short *,  const void *,   int n);
    00128     virtual void to_external(void *,   const short *,  int n);
    00129     virtual void to_native  (unsigned int *,    const void *,   int n);
    00130     virtual void to_external(void *,   const unsigned int *,    int n);
    00131     virtual void to_native  (int *,    const void *,   int n);
    00132     virtual void to_external(void *,   const int *,    int n);
    00133     virtual void to_native  (long *,   const void *,   int n);
    00134     virtual void to_external(void *,   const long *,   int n);
    00135     virtual void to_native  (float *,  const void *,   int n);
    00136     virtual void to_external(void *,   const float *,  int n);
    00137     virtual void to_native  (double *, const void *,   int n);
    00138     virtual void to_external(void *,   const double *, int n);
    00139 };
    00140
    00141 #if BIGENDIAN
    00142 typedef TranslateDataByteSwap TranslateDataLittleEndian;
    00143 typedef TranslateData TranslateDataBigEndian;
    00144 #else
    00145 typedef TranslateDataByteSwap TranslateDataBigEndian;
    00146 typedef TranslateData TranslateDataLittleEndian;
    00147 #endif
    00148
    00149 class StateOut;
    00150
    00154 class TranslateDataOut {
    00155   private:
    00156     StateOut *so_;
    00157     TranslateData *translate_;
    00158     // the translation buffer
    00159     enum { bufsize = 8192 };
    00160     char buf_[bufsize];
    00161   protected:
    00162     int putv(const void*d,int s);
    00163   public:
    00166     TranslateDataOut(StateOut*s, TranslateData*t);
    00167     virtual ~TranslateDataOut();
    00168
    00171     virtual int put(const char*,int);
    00172     virtual int put(const short*,int);
    00173     virtual int put(const unsigned int*,int);
    00174     virtual int put(const int*,int);
    00175     virtual int put(const long*,int);
    00176     virtual int put(const float*,int);
    00177     virtual int put(const double*,int);
    00178
    00180     TranslateData *translator() { return translate_; }
    00181 };
    00182
    00183 class StateIn;
    00184
    00188 class TranslateDataIn {
    00189   private:
    00190     StateIn *si_;
    00191     TranslateData *translate_;
    00192   protected:
    00193     int getv(void*d,int s);
    00194   public:
    00197     TranslateDataIn(StateIn*s, TranslateData *t);
    00198     virtual ~TranslateDataIn();
    00199
    00202     virtual int get(char*,int);
    00203     virtual int get(short*,int);
    00204     virtual int get(unsigned int*,int);
    00205     virtual int get(int*,int);
    00206     virtual int get(long*,int);
    00207     virtual int get(float*,int);
    00208     virtual int get(double*,int);
    00209
    00211     TranslateData *translator() { return translate_; }
    00212 };
    00213
    00214 }
    00215
    00216 #endif
    00217
    00218 // Local Variables:
    00219 // mode: c++
    00220 // c-file-style: "CLJ"
    00221 // End: