binary_i_stream.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "io_common.h"
00044 #include "binary_i_stream.h"
00045 #include "../num/basic_types.h"
00046
00047
00048
00049 #if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_MSVC
00050 # pragma warning(push)
00051 # pragma warning(disable: 4312) // 'reinterpret_cast' : conversion from 'lass::num::TintPtr' to 'void *' of greater size
00052 #endif
00053
00054 namespace lass
00055 {
00056
00057 namespace io
00058 {
00059
00060 BinaryIStream::BinaryIStream():
00061 BinaryStreamBase()
00062 {
00063 }
00064
00065
00066
00067 BinaryIStream::~BinaryIStream()
00068 {
00069 }
00070
00071
00072
00073 long BinaryIStream::tellg() const
00074 {
00075 return doTellg();
00076 }
00077
00078
00079
00080 BinaryIStream& BinaryIStream::seekg(long position)
00081 {
00082 doSeekg(position, std::ios_base::beg);
00083 return *this;
00084 }
00085
00086
00087
00088 BinaryIStream& BinaryIStream::seekg(long offset, std::ios_base::seekdir directioin)
00089 {
00090 doSeekg(offset, directioin);
00091 return *this;
00092 }
00093
00094
00095
00096 BinaryIStream& BinaryIStream::operator>>( char& x )
00097 {
00098 return readValue(x);
00099 }
00100
00101
00102
00103 BinaryIStream& BinaryIStream::operator>>( num::Tint8& x )
00104 {
00105 return readValue(x);
00106 }
00107
00108
00109
00110 BinaryIStream& BinaryIStream::operator>>( num::Tuint8& x )
00111 {
00112 return readValue(x);
00113 }
00114
00115
00116
00117 BinaryIStream& BinaryIStream::operator>>( num::Tint16& x )
00118 {
00119 return readValue(x);
00120 }
00121
00122
00123
00124 BinaryIStream& BinaryIStream::operator>>( num::Tuint16& x )
00125 {
00126 return readValue(x);
00127 }
00128
00129
00130
00131 BinaryIStream& BinaryIStream::operator>>( num::Tint32& x )
00132 {
00133 return readValue(x);
00134 }
00135
00136
00137
00138 BinaryIStream& BinaryIStream::operator>>( num::Tuint32& x )
00139 {
00140 return readValue(x);
00141 }
00142
00143
00144
00145 BinaryIStream& BinaryIStream::operator>>( num::Tint64& x )
00146 {
00147 return readValue(x);
00148 }
00149
00150
00151
00152 BinaryIStream& BinaryIStream::operator>>( num::Tuint64& x )
00153 {
00154 return readValue(x);
00155 }
00156
00157
00158
00159 BinaryIStream& BinaryIStream::operator>>( num::Tfloat32& x )
00160 {
00161 return readValue(x);
00162 }
00163
00164
00165
00166 BinaryIStream& BinaryIStream::operator>>( num::Tfloat64& x )
00167 {
00168 return readValue(x);
00169 }
00170
00171
00172
00173 BinaryIStream& BinaryIStream::operator>>(bool& x)
00174 {
00175 num::Tuint8 temp;
00176 *this >> temp;
00177 if (good())
00178 {
00179 x = temp ? true : false;
00180 }
00181 return *this;
00182 }
00183
00184
00185
00186 BinaryIStream& BinaryIStream::operator>>(void*& x)
00187 {
00188 LASS_META_ASSERT(sizeof(num::TintPtr) == sizeof(const void*), TintPtr_should_be_of_pointer_size);
00189 num::Tint64 temp;
00190 *this >> temp;
00191 if (good())
00192 {
00193 #pragma LASS_FIXME("do something special here if cast causes truncation [Bramz]")
00194 x = reinterpret_cast<void*>(static_cast<num::TintPtr>(temp));
00195 }
00196 return *this;
00197 }
00198
00199
00200
00201 BinaryIStream& BinaryIStream::operator>>( std::string& x )
00202 {
00203 num::Tuint64 n;
00204 *this >> n;
00205 if (good())
00206 {
00207 size_t length = static_cast<size_t>(n);
00208 #pragma LASS_FIXME("do something special if there's an overflow [Bramz]")
00209 LASS_ASSERT(n == static_cast<num::Tuint64>(n));
00210 std::vector<char> buffer(length + 2, '\0');
00211 doRead(&buffer[0], length);
00212 if (good())
00213 {
00214 x = std::string(&buffer[0]);
00215 }
00216 }
00217 return *this;
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 void BinaryIStream::read(void* output, size_t numBytes)
00230 {
00231 doRead(output, numBytes);
00232 }
00233
00234
00235
00236
00237
00238 template <typename T>
00239 BinaryIStream& BinaryIStream::readValue(T& x)
00240 {
00241 if (good())
00242 {
00243 T temp;
00244 doRead(&temp, sizeof(T));
00245 if (good())
00246 {
00247 x = num::fixEndianness(temp, endianness());
00248 }
00249 }
00250 return *this;
00251 }
00252
00253
00254 }
00255
00256 }
00257