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