00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00016 #ifndef LXDR__HH
00017 #define LXDR__HH
00018
00019 #include <stdio.h>
00020
00022
00023
00024
00026
00031 class lXDR {
00032 private:
00033
00034
00035
00036 enum { MAJOR = 1, MINOR = 0, DAY = 23, MONTH = 10, YEAR = 2003 };
00037
00038 public:
00039 static int getMajor(void) { return(MAJOR); };
00040 static int getMinor(void) { return(MINOR); };
00041 static const char *getText(void) {
00042 static char buff[80];
00043 sprintf(buff, "lXDR version %d.%d (%02d.%02d.%d) by W.G.J. Langeveld, SLAC",
00044 MAJOR, MINOR, DAY, MONTH, YEAR);
00045 return(buff);
00046 };
00047 public:
00048
00049
00050
00051
00052
00053
00054 lXDR(const char *filename = 0, bool open_for_write = false);
00055 private:
00056 lXDR(const lXDR &);
00057 public:
00058 virtual ~lXDR();
00059
00060
00061
00062
00063
00064 void setFileName(const char *filename, bool open_for_write = false);
00065 const char *getFileName(void) const { return(_fileName); };
00066
00067
00068
00069 private:
00070 lXDR &operator=(const lXDR &);
00071 public:
00072
00073
00074
00075 long getError(void) const { return(_error); };
00076
00077
00078
00079
00080
00081
00082 long readLong(void);
00083 double readFloat(void);
00084 double readDouble(void);
00085
00086
00087
00088
00089
00090
00091 const char *readString(long &length);
00092 long *readLongArray(long &length);
00093 double *readFloatArray(long &length);
00094 double *readDoubleArray(long &length);
00095
00096
00097
00098
00099
00100
00101 long writeLong(long data);
00102 long writeDouble(double data);
00103
00104
00105
00106
00107
00108 long writeString(const char *data);
00109 long writeString(const char *data, long length);
00110 long writeLongArray(const long *data, long length);
00111 long writeDoubleArray(const double *data, long length);
00112
00113 void setError(long error) { _error = error; return; };
00114
00115
00116
00117 long filePosition(long pos = -1);
00118
00119 private:
00120 char *_fileName;
00121 FILE *_fp;
00122 long _error;
00123 bool _openForWrite;
00124
00125 bool _hasNetworkOrder;
00126 double ntohd(double d) const;
00127 double htond(double d) const { return(ntohd(d)); };
00128
00129 long checkRead(long *);
00130 long checkRead(float *);
00131 long checkRead(double *);
00132 long checkWrite(long *);
00133 long checkWrite(double *);
00134 };
00135
00136 #define LXDR_SUCCESS 0
00137 #define LXDR_OPENFAILURE 1
00138 #define LXDR_READONLY 2
00139 #define LXDR_WRITEONLY 3
00140 #define LXDR_NOFILE 4
00141 #define LXDR_READERROR 5
00142 #define LXDR_WRITEERROR 6
00143 #define LXDR_SEEKERROR 7
00144
00145
00146 #endif
00147