00001 #ifndef Xdr_h
00002 #define Xdr_h
00003
00004 #ifdef USE_CONDDB
00005
00006
00007 #include "lccd.h"
00008
00009 #include <typeinfo>
00010
00011 namespace lccd {
00012
00022 class Xdr {
00023
00024 public:
00025
00029 static void copy( unsigned const char* from, unsigned char* dest,
00030 const int size, const int count);
00031
00032
00033
00037 template <class T>
00038 static void tostream( std::string& s , T* t, unsigned count ) {
00039
00040 int bytlen, padlen;
00041 bytlen = count * sizeof( T ) ;
00042 padlen = (bytlen + 3) & 0xfffffffc ;
00043
00044
00045 unsigned index = s.size() ;
00046
00047 s.resize( s.size() + padlen ) ;
00048
00049 unsigned char* dest = reinterpret_cast< unsigned char* > ( & s[ index ] ) ;
00050 unsigned char* from = reinterpret_cast< unsigned char* > ( t ) ;
00051
00052
00053
00054 Xdr::copy( from , dest , sizeof( T ) , count ) ;
00055
00056 }
00057
00063 template <class T>
00064 static unsigned fromstream( const std::string& s , unsigned position, T* t, unsigned count ) {
00065
00066 if( count == 0 )
00067 return position ;
00068
00069 unsigned bytlen, padlen;
00070 bytlen = count * sizeof( T ) ;
00071 padlen = (bytlen + 3) & 0xfffffffc ;
00072
00073
00074 unsigned const char* from = reinterpret_cast< unsigned const char* > ( & s[ position ] ) ;
00075 unsigned char* dest = reinterpret_cast< unsigned char* > ( t ) ;
00076
00077
00078
00079 Xdr::copy( from , dest , sizeof( T ) , count ) ;
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 return position + padlen ;
00091 }
00092
00093
00094
00097
00098 static void tostream( std::string& s , std::string* strVal, unsigned count ) {
00099
00100 int strSize = (int) strVal->size() ;
00101
00102 int bytlen, padlen;
00103 bytlen = strSize + sizeof( int ) ;
00104
00105 padlen = (bytlen + 3) & 0xfffffffc ;
00106
00107 unsigned index = s.size() ;
00108
00109 s.resize( index + padlen ) ;
00110
00111
00112
00113
00114 unsigned char* dest = reinterpret_cast< unsigned char* > ( & s[ index ] ) ;
00115 unsigned char* from = reinterpret_cast< unsigned char* > ( & strSize ) ;
00116
00117 Xdr::copy( from , dest , sizeof( int ) , 1 ) ;
00118
00119
00120 dest = reinterpret_cast< unsigned char* > ( & s[ index + sizeof( int ) ] ) ;
00121 from = reinterpret_cast< unsigned char* > ( & strVal->operator[](0) ) ;
00122
00123
00124
00125
00126
00127 Xdr::copy( from , dest , 1 , strSize ) ;
00128
00129 }
00130
00131
00135
00136 static unsigned fromstream( const std::string& s, unsigned index,
00137 std::string* strVal, unsigned count ) {
00138
00139 if( count == 0 )
00140 return index ;
00141
00142
00143
00144 int strSize ;
00145 unsigned const char* from = reinterpret_cast< unsigned const char* > ( & s[ index ] ) ;
00146 unsigned char* dest = reinterpret_cast< unsigned char* > ( & strSize ) ;
00147
00148 Xdr::copy( from , dest , sizeof( int ) , 1 ) ;
00149
00150 index += sizeof( int ) ;
00151
00152
00153 unsigned bytlen, padlen;
00154 bytlen = strSize ;
00155 padlen = (bytlen + 3) & 0xfffffffc ;
00156
00157
00158 strVal->resize( strSize ) ;
00159
00160 from = reinterpret_cast< unsigned const char* > ( & s[ index ] ) ;
00161 dest = reinterpret_cast< unsigned char* > ( & strVal->operator[](0) ) ;
00162
00163 Xdr::copy( from , dest , 1 , strSize ) ;
00164
00165
00166
00167
00168
00169
00170
00171 return index + padlen ;
00172 }
00173
00174
00175 };
00176 }
00177
00178 #endif // USE_CONDDB
00179 #endif // Xdr_h