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 #ifndef AbstractInputStreamH
00033 #define AbstractInputStreamH
00034
00035 #include <zeusbase/System/Interfaces/IInputStream.hpp>
00036 #include <zeusbase/System/ZObject.h>
00037
00038 BEGIN_NAMESPACE_Zeus
00039
00040
00042 #define READ_PRIMITIVE_DATA(datatype) \
00043 Retval retError = RET_REQUEST_FAILED; \
00044 datatype tValue = 0; \
00045 Int iSize = sizeof(datatype); \
00046 Int iValidSize = 0; \
00047 char* pBuffer = (char*)&tValue; \
00048 if (this->read(pBuffer, iSize, iValidSize) == RET_NOERROR && iSize == iValidSize) \
00049 { \
00050 retError = RET_NOERROR; \
00051 } \
00052 \
00053 if (pError != NULL) \
00054 { \
00055 *pError = (retError != RET_NOERROR); \
00056 } \
00057 return tValue;
00058
00059
00061 #define READ_ARRAY_DATA(array) \
00062 Retval retValue = RET_NOERROR; \
00063 bool bError = false; \
00064 Int iSize = readInt32(&bError); \
00065 if (bError) \
00066 { \
00067 retValue = RET_REQUEST_FAILED; \
00068 } \
00069 else if (iSize > 0) \
00070 { \
00071 TArrayPtr<char> ptrBuffer(new char[iSize], iSize); \
00072 ptrBuffer.clean(); \
00073 Int iTotalReceived = 0; \
00074 while(iSize > iTotalReceived && retValue == RET_NOERROR) \
00075 { \
00076 Int iReceived = 0; \
00077 Int iSizeToRead = iSize-iTotalReceived; \
00078 char* pHead = static_cast<char*>(ptrBuffer.getPointer() + iTotalReceived); \
00079 retValue = this->read(pHead, iSizeToRead, iReceived); \
00080 iTotalReceived += iReceived; \
00081 } \
00082 array.setArray(ptrBuffer, iSize); \
00083 } \
00084 return retValue;
00085
00086
00088 #define READ_STRING_DATA(rstrData) \
00089 rstrData.clear(); \
00090 Retval retValue = RET_NOERROR; \
00091 bool bError = false; \
00092 Int iStringSize = readInt32(&bError); \
00093 if (bError) \
00094 { \
00095 retValue = RET_REQUEST_FAILED; \
00096 } \
00097 else if (iStringSize > 0) \
00098 { \
00099 TArrayPtr<wchar_t> ptrWcBuffer(new wchar_t[iStringSize + 1], iStringSize + 1); \
00100 ptrWcBuffer.clean(); \
00101 Int iBufferSize = iStringSize * 2; \
00102 TArrayPtr<char> ptrCBuffer(new char[iBufferSize+1], iBufferSize + 1); \
00103 ptrCBuffer.clean(); \
00104 Int iValidSize = 0; \
00105 retValue = this->read(ptrCBuffer, iBufferSize, iValidSize); \
00106 for(Int i = 0, j = 0; i < iValidSize; i += 2, j++) \
00107 { \
00108 char c1 = ptrCBuffer[i]; \
00109 char c2 = ptrCBuffer[i+1]; \
00110 wchar_t wc1 = (wchar_t)(c1 | (c2 << 8)); \
00111 ptrWcBuffer[j] = wc1; \
00112 } \
00113 rstrData.assign(ptrWcBuffer); \
00114 } \
00115 return retValue;
00116
00118 #define SKIP_READING_DATA(iBytes) \
00119 bool bRetval = false; \
00120 if (iBytes > 0) \
00121 { \
00122 TArrayPtr<char> ptrBuffer = new char[iBytes]; \
00123 Int iValidSize = 0; \
00124 if (this->read(ptrBuffer.getPointer(), iBytes, iValidSize) == RET_NOERROR) \
00125 { \
00126 bRetval = true; \
00127 } \
00128 } \
00129 return bRetval;
00130
00131
00132
00135
00136 zeusbase_class TAbstractInputStream : public TZObject, public IInputStream
00137 {
00138 public:
00139 TAbstractInputStream();
00140
00141
00142 virtual Retval MQUALIFIER read(char* pBuffer, Int iBufferSize, Int& rValidSize) const=0;
00143 virtual Int MQUALIFIER readItem() const=0;
00144 virtual bool MQUALIFIER isEndReached() const=0;
00145 virtual void MQUALIFIER close()=0;
00146 virtual void MQUALIFIER reset()=0;
00147 virtual bool MQUALIFIER skip(Int iBytes = 1) = 0;
00148
00149
00150 virtual bool MQUALIFIER available() const;
00151 virtual Int8 MQUALIFIER readInt8(BOOL_ERRORRETVAL(pError)) const;
00152 virtual Int16 MQUALIFIER readInt16(BOOL_ERRORRETVAL(pError)) const;
00153 virtual Int32 MQUALIFIER readInt32(BOOL_ERRORRETVAL(pError)) const;
00154 virtual Int64 MQUALIFIER readInt64(BOOL_ERRORRETVAL(pError)) const;
00155 virtual Uint8 MQUALIFIER readUint8(BOOL_ERRORRETVAL(pError)) const;
00156 virtual Uint16 MQUALIFIER readUint16(BOOL_ERRORRETVAL(pError)) const;
00157 virtual Uint32 MQUALIFIER readUint32(BOOL_ERRORRETVAL(pError)) const;
00158 virtual Uint64 MQUALIFIER readUint64(BOOL_ERRORRETVAL(pError)) const;
00159 virtual Float32 MQUALIFIER readFloat32(BOOL_ERRORRETVAL(pError)) const;
00160 virtual Float64 MQUALIFIER readFloat64(BOOL_ERRORRETVAL(pError)) const;
00161 virtual bool MQUALIFIER readBool(BOOL_ERRORRETVAL(pError)) const;
00162 virtual Retval MQUALIFIER readArray(IByteArray& rData) const;
00163 virtual Retval MQUALIFIER readString(IString& rData) const;
00164
00165
00166 MEMORY_MANAGER_DECL
00167
00168 protected:
00169 virtual ~TAbstractInputStream();
00170
00172 bool m_bOpen;
00174 bool m_bAvailable;
00175
00176 private:
00177
00178 };
00179
00180
00181
00184
00185 inline bool MQUALIFIER TAbstractInputStream::available() const
00186 { return m_bAvailable; }
00187
00188
00191
00192 inline bool MQUALIFIER TAbstractInputStream::readBool(bool* pError) const
00193 {
00194 #ifdef _MSC_VER
00195 return !!readInt8(pError);
00196 #else
00197 return readInt8(pError);
00198 #endif
00199 }
00200
00201
00204
00205 inline Uint8 MQUALIFIER TAbstractInputStream::readUint8(bool* pError) const
00206 {
00207 return static_cast<Uint8>(readInt8(pError));
00208 }
00209
00210
00213
00214 inline Uint16 MQUALIFIER TAbstractInputStream::readUint16(bool* pError) const
00215 {
00216 return static_cast<Uint16>(readInt16(pError));
00217 }
00218
00219
00222
00223 inline Uint32 MQUALIFIER TAbstractInputStream::readUint32(bool* pError) const
00224 {
00225 return static_cast<Uint32>(readInt32(pError));
00226 }
00227
00228
00231
00232 inline Uint64 MQUALIFIER TAbstractInputStream::readUint64(bool* pError) const
00233 {
00234 return static_cast<Uint64>(readInt64(pError));
00235 }
00236
00237 END_NAMESPACE_Zeus
00238
00239 #endif