[342] | 1 | #ifndef __BUFFER_IMPL_HPP__ |
---|
| 2 | #define __BUFFER_IMPL_HPP__ |
---|
[300] | 3 | |
---|
[335] | 4 | namespace xios |
---|
[300] | 5 | { |
---|
| 6 | |
---|
| 7 | // template spectialisation : CBuffer::put |
---|
| 8 | template <> bool CBuffer::put<char>(const char& data) { return put_template(data) ; } |
---|
| 9 | template <> bool CBuffer::put<int>(const int& data) { return put_template(data) ; } |
---|
| 10 | template <> bool CBuffer::put<short>(const short& data) { return put_template(data) ; } |
---|
| 11 | template <> bool CBuffer::put<long>(const long& data) { return put_template(data) ; } |
---|
[1875] | 12 | template <> bool CBuffer::put<longlong>(const longlong& data) { return put_template(data) ; } |
---|
[300] | 13 | template <> bool CBuffer::put<uint>(const uint& data) { return put_template(data) ; } |
---|
| 14 | template <> bool CBuffer::put<ushort>(const ushort& data) { return put_template(data) ; } |
---|
| 15 | template <> bool CBuffer::put<ulong>(const ulong& data) { return put_template(data) ; } |
---|
[1875] | 16 | template <> bool CBuffer::put<ulonglong>(const ulonglong& data) { return put_template(data) ; } |
---|
[300] | 17 | template <> bool CBuffer::put<float>(const float& data) { return put_template(data) ; } |
---|
| 18 | template <> bool CBuffer::put<double>(const double& data) { return put_template(data) ; } |
---|
| 19 | template <> bool CBuffer::put<long double>(const long double& data) { return put_template(data) ;} |
---|
| 20 | |
---|
| 21 | template <> bool CBuffer::put<char>(const char* data, size_t n) { return put_template(data,n) ; } |
---|
| 22 | template <> bool CBuffer::put<int>(const int* data, size_t n) { return put_template(data,n) ; } |
---|
| 23 | template <> bool CBuffer::put<short>(const short* data, size_t n) { return put_template(data,n) ; } |
---|
| 24 | template <> bool CBuffer::put<long>(const long* data, size_t n) { return put_template(data,n) ; } |
---|
[1875] | 25 | template <> bool CBuffer::put<longlong>(const longlong* data, size_t n) { return put_template(data,n) ; } |
---|
[300] | 26 | template <> bool CBuffer::put<uint>(const uint* data, size_t n) { return put_template(data,n) ; } |
---|
| 27 | template <> bool CBuffer::put<ushort>(const ushort* data, size_t n) { return put_template(data,n) ; } |
---|
| 28 | template <> bool CBuffer::put<ulong>(const ulong* data, size_t n) { return put_template(data,n) ; } |
---|
[1875] | 29 | template <> bool CBuffer::put<ulonglong>(const ulonglong* data, size_t n) { return put_template(data,n) ; } |
---|
[300] | 30 | template <> bool CBuffer::put<float>(const float* data, size_t n) { return put_template(data,n) ; } |
---|
| 31 | template <> bool CBuffer::put<double>(const double* data, size_t n) { return put_template(data,n) ; } |
---|
| 32 | template <> bool CBuffer::put<long double>(const long double* data, size_t n) { return put_template(data,n) ;} |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | template <> bool CBuffer::put_ptr<char>(const char*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
| 36 | template <> bool CBuffer::put_ptr<int>(const int*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
| 37 | template <> bool CBuffer::put_ptr<short>(const short*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
| 38 | template <> bool CBuffer::put_ptr<long>(const long*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
[1875] | 39 | template <> bool CBuffer::put_ptr<longlong>(const longlong*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
[300] | 40 | template <> bool CBuffer::put_ptr<uint>(const uint*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
| 41 | template <> bool CBuffer::put_ptr<ushort>(const ushort*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
| 42 | template <> bool CBuffer::put_ptr<ulong>(const ulong*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
[1875] | 43 | template <> bool CBuffer::put_ptr<ulonglong>(const ulonglong*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
[300] | 44 | template <> bool CBuffer::put_ptr<float>(const float*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
| 45 | template <> bool CBuffer::put_ptr<double>(const double*& data, size_t n) { return put_ptr_template(data,n) ; } |
---|
| 46 | template <> bool CBuffer::put_ptr<long double>(const long double*& data, size_t n) { return put_ptr_template(data,n) ;} |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | // template spectialisation : CBuffer::get |
---|
| 50 | template <> bool CBuffer::get<char>(char& data) { return get_template(data) ; } |
---|
| 51 | template <> bool CBuffer::get<int>(int& data) { return get_template(data) ; } |
---|
| 52 | template <> bool CBuffer::get<short>(short& data) { return get_template(data) ; } |
---|
| 53 | template <> bool CBuffer::get<long>(long& data) { return get_template(data) ; } |
---|
[1875] | 54 | template <> bool CBuffer::get<longlong>(longlong& data) { return get_template(data) ; } |
---|
[300] | 55 | template <> bool CBuffer::get<uint>(uint& data) { return get_template(data) ; } |
---|
| 56 | template <> bool CBuffer::get<ushort>(ushort& data) { return get_template(data) ; } |
---|
| 57 | template <> bool CBuffer::get<ulong>(ulong& data) { return get_template(data) ; } |
---|
[1875] | 58 | template <> bool CBuffer::get<ulonglong>(ulonglong& data) { return get_template(data) ; } |
---|
[300] | 59 | template <> bool CBuffer::get<float>(float& data) { return get_template(data) ; } |
---|
| 60 | template <> bool CBuffer::get<double>(double& data) { return get_template(data) ; } |
---|
| 61 | template <> bool CBuffer::get<long double>(long double& data) { return get_template(data) ;} |
---|
| 62 | |
---|
| 63 | template <> bool CBuffer::get<char>(char* data, size_t n) { return get_template(data,n) ; } |
---|
| 64 | template <> bool CBuffer::get<int>(int* data, size_t n) { return get_template(data,n) ; } |
---|
| 65 | template <> bool CBuffer::get<short>(short* data, size_t n) { return get_template(data,n) ; } |
---|
| 66 | template <> bool CBuffer::get<long>(long* data, size_t n) { return get_template(data,n) ; } |
---|
[1875] | 67 | template <> bool CBuffer::get<longlong>(longlong* data, size_t n) { return get_template(data,n) ; } |
---|
[300] | 68 | template <> bool CBuffer::get<uint>(uint* data, size_t n) { return get_template(data,n) ; } |
---|
| 69 | template <> bool CBuffer::get<ushort>(ushort* data, size_t n) { return get_template(data,n) ; } |
---|
| 70 | template <> bool CBuffer::get<ulong>(ulong* data, size_t n) { return get_template(data,n) ; } |
---|
[1875] | 71 | template <> bool CBuffer::get<ulonglong>(ulonglong* data, size_t n) { return get_template(data,n) ; } |
---|
[300] | 72 | template <> bool CBuffer::get<float>(float* data, size_t n) { return get_template(data,n) ; } |
---|
| 73 | template <> bool CBuffer::get<double>(double* data, size_t n) { return get_template(data,n) ; } |
---|
| 74 | template <> bool CBuffer::get<long double>(long double* data, size_t n) { return get_template(data,n) ;} |
---|
| 75 | |
---|
| 76 | template <> bool CBuffer::get_ptr<char>(char*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
| 77 | template <> bool CBuffer::get_ptr<int>(int*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
| 78 | template <> bool CBuffer::get_ptr<short>(short*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
| 79 | template <> bool CBuffer::get_ptr<long>(long*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
[1875] | 80 | template <> bool CBuffer::get_ptr<longlong>(longlong*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
[300] | 81 | template <> bool CBuffer::get_ptr<uint>(uint*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
| 82 | template <> bool CBuffer::get_ptr<ushort>(ushort*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
| 83 | template <> bool CBuffer::get_ptr<ulong>(ulong*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
[1875] | 84 | template <> bool CBuffer::get_ptr<ulonglong>(ulonglong*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
[300] | 85 | template <> bool CBuffer::get_ptr<float>(float*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
| 86 | template <> bool CBuffer::get_ptr<double>(double*& data, size_t n) { return get_ptr_template(data,n) ; } |
---|
| 87 | template <> bool CBuffer::get_ptr<long double>(long double*& data, size_t n) { return get_ptr_template(data,n) ;} |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | template <class T> |
---|
| 91 | bool CBuffer::put_template(const T& data) |
---|
| 92 | { |
---|
| 93 | return put_template<T>(&data,1); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | template <class T> |
---|
| 97 | bool CBuffer::put_template(const T* data, size_t n) |
---|
| 98 | { |
---|
| 99 | bool ret; |
---|
| 100 | char* dataBuff ; |
---|
| 101 | |
---|
| 102 | size_t dataSize=sizeof(T)*n ; |
---|
| 103 | |
---|
| 104 | if (count+dataSize<=size) |
---|
| 105 | { |
---|
| 106 | dataBuff=(char*) data ; |
---|
| 107 | for(size_t i=0;i<dataSize;i++) write[i]=dataBuff[i] ; |
---|
| 108 | write+=dataSize ; |
---|
| 109 | count+=dataSize; |
---|
| 110 | ret=true ; |
---|
| 111 | } |
---|
| 112 | else ret=false ; |
---|
| 113 | |
---|
| 114 | return ret ; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | template <class T> |
---|
| 118 | bool CBuffer::put_ptr_template(const T*& data, size_t n) |
---|
| 119 | { |
---|
| 120 | bool ret; |
---|
| 121 | char* dataBuff ; |
---|
| 122 | |
---|
| 123 | size_t dataSize=sizeof(T)*n ; |
---|
| 124 | |
---|
| 125 | if (count+dataSize<=size) |
---|
| 126 | { |
---|
| 127 | data=(T*) write ; |
---|
| 128 | write+=dataSize ; |
---|
| 129 | count+=dataSize; |
---|
| 130 | ret=true ; |
---|
| 131 | } |
---|
| 132 | else ret=false ; |
---|
| 133 | |
---|
| 134 | return ret ; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | template <class T> |
---|
| 139 | bool CBuffer::get_template(T& data) |
---|
| 140 | { |
---|
| 141 | return get_template<T>(&data,1) ; |
---|
| 142 | |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | template <class T> |
---|
| 146 | bool CBuffer::get_template(T* data, size_t n) |
---|
| 147 | { |
---|
| 148 | bool ret; |
---|
| 149 | char* dataBuff ; |
---|
| 150 | |
---|
| 151 | size_t dataSize=sizeof(T)*n ; |
---|
| 152 | |
---|
| 153 | if (read+dataSize<=buffer+size) |
---|
| 154 | { |
---|
| 155 | dataBuff=(char*) data ; |
---|
| 156 | for(size_t i=0;i<dataSize;i++) dataBuff[i]=read[i] ; |
---|
| 157 | read+=dataSize ; |
---|
| 158 | ret=true ; |
---|
| 159 | } |
---|
| 160 | else ret=false ; |
---|
| 161 | |
---|
| 162 | return ret ; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | template <class T> |
---|
| 166 | bool CBuffer::get_ptr_template(T*& data, size_t n) |
---|
| 167 | { |
---|
| 168 | bool ret; |
---|
| 169 | char* dataBuff ; |
---|
| 170 | |
---|
| 171 | size_t dataSize=sizeof(T)*n ; |
---|
| 172 | |
---|
| 173 | if (read+dataSize<=buffer+size) |
---|
| 174 | { |
---|
| 175 | data=(T*) read ; |
---|
| 176 | read+=dataSize ; |
---|
| 177 | ret=true ; |
---|
| 178 | } |
---|
| 179 | else ret=false ; |
---|
| 180 | |
---|
| 181 | return ret ; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | #endif |
---|