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