Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

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 
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     // the translation buffer
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 // Local Variables:
00215 // mode: c++
00216 // c-file-style: "CLJ"
00217 // End:

Generated at Thu Oct 4 18:08:47 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.