Index: ext/libicpf/src/libicpf/file.cpp =================================================================== diff -u -r3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f -r11ed3bb42c590253675ed5083ecce17d5b0273e9 --- ext/libicpf/src/libicpf/file.cpp (.../file.cpp) (revision 3150d0c0a9a5fe75a5954e17a5a445a14e0bea1f) +++ ext/libicpf/src/libicpf/file.cpp (.../file.cpp) (revision 11ed3bb42c590253675ed5083ecce17d5b0273e9) @@ -739,204 +739,6 @@ _sbuf_read(pData, uiSize); } -/** Writes a value of a given type to the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - value to be stored in a file - * \return Reference to this file object. - */ -file& file::operator<<(bool val) -{ - swrite(&val, sizeof(val)); - return *this; -} - -/** Reads a value of a given type from the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - reference to a variable to receive data - * \return Reference to this file object. - */ -file& file::operator>>(bool& val) -{ - sread(&val, sizeof(val)); - return *this; -} - -/** Writes a value of a given type to the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - value to be stored in a file - * \return Reference to this file object. - */ -file& file::operator<<(tchar_t val) -{ - swrite(&val, sizeof(val)); - return *this; -} - -/** Reads a value of a given type from the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - reference to a variable to receive data - * \return Reference to this file object. - */ -file& file::operator>>(tchar_t& val) -{ - sread(&val, sizeof(val)); - return *this; -} - -/** Writes a value of a given type to the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - value to be stored in a file - * \return Reference to this file object. - */ -file& file::operator<<(uchar_t val) -{ - swrite(&val, sizeof(val)); - return *this; -} - -/** Reads a value of a given type from the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - reference to a variable to receive data - * \return Reference to this file object. - */ -file& file::operator>>(uchar_t& val) -{ - sread(&val, sizeof(val)); - return *this; -} - -/** Writes a value of a given type to the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - value to be stored in a file - * \return Reference to this file object. - */ -file& file::operator<<(short_t val) -{ - swrite(&val, sizeof(val)); - return *this; -} - -/** Reads a value of a given type from the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - reference to a variable to receive data - * \return Reference to this file object. - */ -file& file::operator>>(short_t& val) -{ - sread(&val, sizeof(val)); - return *this; -} - -/** Writes a value of a given type to the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - value to be stored in a file - * \return Reference to this file object. - */ -file& file::operator<<(ushort_t val) -{ - swrite(&val, sizeof(val)); - return *this; -} - -/** Reads a value of a given type from the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - reference to a variable to receive data - * \return Reference to this file object. - */ -file& file::operator>>(ushort_t& val) -{ - sread(&val, sizeof(val)); - return *this; -} - -/** Writes a value of a given type to the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - value to be stored in a file - * \return Reference to this file object. - */ -file& file::operator<<(int_t val) -{ - swrite(&val, sizeof(val)); - return *this; -} - -/** Reads a value of a given type from the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - reference to a variable to receive data - * \return Reference to this file object. - */ -file& file::operator>>(int_t& val) -{ - sread(&val, sizeof(val)); - return *this; -} - -/** Writes a value of a given type to the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - value to be stored in a file - * \return Reference to this file object. - */ -file& file::operator<<(uint_t val) -{ - swrite(&val, sizeof(val)); - return *this; -} - -/** Reads a value of a given type from the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - reference to a variable to receive data - * \return Reference to this file object. - */ -file& file::operator>>(uint_t& val) -{ - sread(&val, sizeof(val)); - return *this; -} - -/** Writes a value of a given type to the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - value to be stored in a file - * \return Reference to this file object. - */ -file& file::operator<<(ll_t val) -{ - swrite(&val, sizeof(val)); - return *this; -} - -/** Reads a value of a given type from the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - reference to a variable to receive data - * \return Reference to this file object. - */ -file& file::operator>>(ll_t& val) -{ - sread(&val, sizeof(val)); - return *this; -} - -/** Writes a value of a given type to the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - value to be stored in a file - * \return Reference to this file object. - */ -file& file::operator<<(ull_t val) -{ - swrite(&val, sizeof(val)); - return *this; -} - -/** Reads a value of a given type from the file. This is a serialization related function, so - * the datablock has to be opened prior to using this operator. - * \param[in] val - reference to a variable to receive data - * \return Reference to this file object. - */ -file& file::operator>>(ull_t& val) -{ - sread(&val, sizeof(val)); - return *this; -} - /** Cancels the serialization process and removes all the traces of data being serialized * (it includes deleting the serialization buffer). */ @@ -1018,7 +820,7 @@ if (m_uiSerialBufferPos+uiLen > m_uiSerialBufferSize) { // throw an exception - read beyond the data range in a given object - THROW(exception::format(_t("[file] Trying to read the serialization data beyond the range (file ") STRFMT _t(")."), m_pszPath), FERR_MEMORY, CURRENT_LAST_ERROR, 0); + THROW(exception::format(_t("[file] Trying to read the serialization data beyond the range (file ") TSTRFMT _t(")."), m_pszPath), FERR_MEMORY, CURRENT_LAST_ERROR, 0); } // read the data @@ -1033,7 +835,6 @@ void file::_sbuf_append(ptr_t pData, uint_t uiCount) { // check if we are writing - assert(m_pbySerialBuffer); assert(m_uiFlags & FA_WRITE); // check serial buffer size (if there is enough room for the data) @@ -1046,6 +847,9 @@ _sbuf_resize(m_uiSerialBufferSize+uiDelta); } + assert(m_pbySerialBuffer); + if(!m_pbySerialBuffer) + THROW(_t("Invalid buffer."), 0, 0, 0); // real storage of the data if (uiCount > 0) { @@ -1060,8 +864,6 @@ */ void file::_sbuf_resize(uint_t uiNewLen) { - assert(m_pbySerialBuffer); - // alloc the new buffer byte_t* pbyNewBuffer=new byte_t[uiNewLen]; Index: ext/libicpf/src/libicpf/file.h =================================================================== diff -u -r8995004f8741e2dfa77d64667be130d6a96460af -r11ed3bb42c590253675ed5083ecce17d5b0273e9 --- ext/libicpf/src/libicpf/file.h (.../file.h) (revision 8995004f8741e2dfa77d64667be130d6a96460af) +++ ext/libicpf/src/libicpf/file.h (.../file.h) (revision 11ed3bb42c590253675ed5083ecce17d5b0273e9) @@ -70,9 +70,6 @@ BEGIN_ICPF_NAMESPACE -// An alias class -typedef file archive; - /** \brief Structure describes the data inside a data block * * Structure contain crc fields to make sure data block is consistent. @@ -168,30 +165,8 @@ bool is_loading() const { return (m_uiFlags & FA_READ) != 0; }; // storing&reading data - file& operator<<(bool val); ///< Stores a given 'val' parameter in the file - file& operator>>(bool& val); ///< Reads a value of a given type from the file - file& operator<<(tchar_t val); ///< Stores a given 'val' parameter in the file - file& operator>>(tchar_t& val); ///< Reads a value of a given type from the file - file& operator<<(uchar_t val); ///< Stores a given 'val' parameter in the file - file& operator>>(uchar_t& val); ///< Reads a value of a given type from the file - file& operator<<(short_t val); ///< Stores a given 'val' parameter in the file - file& operator>>(short_t& val); ///< Reads a value of a given type from the file - file& operator<<(ushort_t val); ///< Stores a given 'val' parameter in the file - file& operator>>(ushort_t& val); ///< Reads a value of a given type from the file - file& operator<<(int_t val); ///< Stores a given 'val' parameter in the file - file& operator>>(int_t& val); ///< Reads a value of a given type from the file - file& operator<<(uint_t val); ///< Stores a given 'val' parameter in the file - file& operator>>(uint_t& val); ///< Reads a value of a given type from the file - file& operator<<(ll_t val); ///< Stores a given 'val' parameter in the file - file& operator>>(ll_t& val); ///< Reads a value of a given type from the file - file& operator<<(ull_t val); ///< Stores a given 'val' parameter in the file - file& operator>>(ull_t& val); ///< Reads a value of a given type from the file + /// Stores some integral type as a part of serialization data block -/* /// Stores some integral type as a part of serialization data block - template file& operator<<(T tData) { swrite(&tData, sizeof(T)); return *this; }; - /// Reads some integral type from a serialization data block - template file& operator>>(T& tData) { sread(&tData, sizeof(T)); return *this; };*/ - // specialized serialization stuff // file& operator<<(icpf::string& str); ///< Stores a CString object in this file (only usable when used in an MFC program) // file& operator>>(icpf::string& str); ///< Reads a CString object from this file (only usable when used in an mfc program) @@ -240,6 +215,89 @@ uint_t m_uiDataBlockFlags; ///< Flags of the current serialization block }; +// An alias class +typedef file archive; + +template +inline file& operator<<(file& rFile, const T& tData) +{ + rFile.swrite((ptr_t)&tData, sizeof(T)); + return rFile; +} + +template<> +inline file& operator<<(file& rFile, const tchar_t *const &pszText) +{ + size_t stLen = _tcslen(pszText); + rFile << stLen; + rFile.swrite((ptr_t)pszText, stLen*sizeof(tchar_t)); + return rFile; +} + +#ifdef _MFC_VER +template<> +inline file& operator<<(file& rFile, const CString &strText) +{ + return rFile<<(const tchar_t*)strText; +} + +template<> +inline file& operator<<(file& rFile, const CStringArray& arrStr) +{ + size_t stCount = arrStr.GetCount(); + rFile.swrite(&stCount, sizeof(stCount)); + + for(size_t stIndex = 0; stIndex != stCount; ++stIndex) + { + rFile<<((const tchar_t*)arrStr.GetAt(stIndex)); + } + return rFile; +} +#endif + +/// Reads some integral type from a serialization data block +template +inline file& operator>>(file& rFile, T& tData) +{ + rFile.sread(&tData, sizeof(T)); + return rFile; +} + +#ifdef _MFC_VER +template<> +inline file& operator>>(file& rFile, CString& str) +{ + str.Empty(); + + size_t stCount = 0; + rFile >> stCount; + if(stCount) + { + PTSTR pszBuffer = str.GetBufferSetLength(stCount + 1); + rFile.sread((ptr_t)pszBuffer, stCount * sizeof(tchar_t)); + pszBuffer[stCount] = _T('\0'); + str.ReleaseBuffer(); + } + return rFile; +} + +template<> +inline file& operator>>(file& rFile, CStringArray& arrStrings) +{ + arrStrings.RemoveAll(); + size_t stCount = 0; + rFile>>(stCount); + + CString str; + for(size_t stIndex = 0; stIndex != stCount; ++stIndex) + { + rFile >> (str); + arrStrings.Add(str); + } + return rFile; +} +#endif + END_ICPF_NAMESPACE #endif