Index: src/ch/DataBuffer.cpp =================================================================== diff -u -r45cf96558ba334192ef42687d4dac01c46d6ffd8 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/DataBuffer.cpp (.../DataBuffer.cpp) (revision 45cf96558ba334192ef42687d4dac01c46d6ffd8) +++ src/ch/DataBuffer.cpp (.../DataBuffer.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -18,11 +18,37 @@ ***************************************************************************/ #include "stdafx.h" #include "DataBuffer.h" +#include "..\libchcore\TBinarySerializer.h" +#include "..\libchcore\SerializationHelpers.h" #ifdef _DEBUG #define new DEBUG_NEW #endif +void BUFFERSIZES::SerializeLoad(chcore::TReadBinarySerializer& rSerializer) +{ + using chcore::Serializers::Serialize; + + Serialize(rSerializer, m_uiDefaultSize); + Serialize(rSerializer, m_uiOneDiskSize); + Serialize(rSerializer, m_uiTwoDisksSize); + Serialize(rSerializer, m_uiCDSize); + Serialize(rSerializer, m_uiLANSize); + Serialize(rSerializer, m_bOnlyDefault); +} + +void BUFFERSIZES::SerializeStore(chcore::TWriteBinarySerializer& rSerializer) +{ + using chcore::Serializers::Serialize; + + Serialize(rSerializer, m_uiDefaultSize); + Serialize(rSerializer, m_uiOneDiskSize); + Serialize(rSerializer, m_uiTwoDisksSize); + Serialize(rSerializer, m_uiCDSize); + Serialize(rSerializer, m_uiLANSize); + Serialize(rSerializer, m_bOnlyDefault); +} + bool BUFFERSIZES::operator==(const BUFFERSIZES& bsSizes) const { return (m_uiDefaultSize == bsSizes.m_uiDefaultSize Index: src/ch/DataBuffer.h =================================================================== diff -u -r45cf96558ba334192ef42687d4dac01c46d6ffd8 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/DataBuffer.h (.../DataBuffer.h) (revision 45cf96558ba334192ef42687d4dac01c46d6ffd8) +++ src/ch/DataBuffer.h (.../DataBuffer.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -39,16 +39,8 @@ #pragma warning (disable: 4201) struct BUFFERSIZES { - template - void serialize(Archive& ar, unsigned int /*uiVersion*/) - { - ar & m_uiDefaultSize; - ar & m_uiOneDiskSize; - ar & m_uiTwoDisksSize; - ar & m_uiCDSize; - ar & m_uiLANSize; - ar & m_bOnlyDefault; - } + void SerializeLoad(chcore::TReadBinarySerializer& rSerializer); + void SerializeStore(chcore::TWriteBinarySerializer& rSerializer); bool operator==(const BUFFERSIZES& bsSizes) const; Index: src/ch/FileFilter.cpp =================================================================== diff -u -r633a533cb6e741d44fe28aa56339e1d2709b1b27 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/FileFilter.cpp (.../FileFilter.cpp) (revision 633a533cb6e741d44fe28aa56339e1d2709b1b27) +++ src/ch/FileFilter.cpp (.../FileFilter.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -20,6 +20,8 @@ #include "FileInfo.h" #include "FileFilter.h" #include "../libchcore/TConfig.h" +#include "../libchcore/TBinarySerializer.h" +#include "../libchcore/SerializationHelpers.h" //////////////////////////////////////////////////////////////////////////// bool _tcicmp(TCHAR c1, TCHAR c2) @@ -303,6 +305,86 @@ m_iDirectory = 0; } +void CFileFilter::Serialize(chcore::TReadBinarySerializer& rSerializer) +{ + using chcore::Serializers::Serialize; + + Serialize(rSerializer, m_bUseMask); + Serialize(rSerializer, m_astrMask); + + Serialize(rSerializer, m_bUseExcludeMask); + Serialize(rSerializer, m_astrExcludeMask); + + Serialize(rSerializer, m_bUseSize); + Serialize(rSerializer, m_iSizeType1); + Serialize(rSerializer, m_ullSize1); + Serialize(rSerializer, m_bUseSize2); + Serialize(rSerializer, m_iSizeType2); + Serialize(rSerializer, m_ullSize2); + + Serialize(rSerializer, m_bUseDate); + Serialize(rSerializer, m_iDateType); // created/last modified/last accessed + Serialize(rSerializer, m_iDateType1); // before/after + Serialize(rSerializer, m_bDate1); + Serialize(rSerializer, m_tDate1); + Serialize(rSerializer, m_bTime1); + Serialize(rSerializer, m_tTime1); + + Serialize(rSerializer, m_bUseDate2); + Serialize(rSerializer, m_iDateType2); + Serialize(rSerializer, m_bDate2); + Serialize(rSerializer, m_tDate2); + Serialize(rSerializer, m_bTime2); + Serialize(rSerializer, m_tTime2); + + Serialize(rSerializer, m_bUseAttributes); + Serialize(rSerializer, m_iArchive); + Serialize(rSerializer, m_iReadOnly); + Serialize(rSerializer, m_iHidden); + Serialize(rSerializer, m_iSystem); + Serialize(rSerializer, m_iDirectory); +} + +void CFileFilter::Serialize(chcore::TWriteBinarySerializer& rSerializer) const +{ + using chcore::Serializers::Serialize; + + Serialize(rSerializer, m_bUseMask); + Serialize(rSerializer, m_astrMask); + + Serialize(rSerializer, m_bUseExcludeMask); + Serialize(rSerializer, m_astrExcludeMask); + + Serialize(rSerializer, m_bUseSize); + Serialize(rSerializer, m_iSizeType1); + Serialize(rSerializer, m_ullSize1); + Serialize(rSerializer, m_bUseSize2); + Serialize(rSerializer, m_iSizeType2); + Serialize(rSerializer, m_ullSize2); + + Serialize(rSerializer, m_bUseDate); + Serialize(rSerializer, m_iDateType); // created/last modified/last accessed + Serialize(rSerializer, m_iDateType1); // before/after + Serialize(rSerializer, m_bDate1); + Serialize(rSerializer, m_tDate1); + Serialize(rSerializer, m_bTime1); + Serialize(rSerializer, m_tTime1); + + Serialize(rSerializer, m_bUseDate2); + Serialize(rSerializer, m_iDateType2); + Serialize(rSerializer, m_bDate2); + Serialize(rSerializer, m_tDate2); + Serialize(rSerializer, m_bTime2); + Serialize(rSerializer, m_tTime2); + + Serialize(rSerializer, m_bUseAttributes); + Serialize(rSerializer, m_iArchive); + Serialize(rSerializer, m_iReadOnly); + Serialize(rSerializer, m_iHidden); + Serialize(rSerializer, m_iSystem); + Serialize(rSerializer, m_iDirectory); +} + bool CFileFilter::Match(const CFileInfoPtr& spInfo) const { // check by mask @@ -616,6 +698,18 @@ return true; } +void CFiltersArray::Serialize(chcore::TReadBinarySerializer& rSerializer) +{ + using chcore::Serializers::Serialize; + Serialize(rSerializer, m_vFilters); +} + +void CFiltersArray::Serialize(chcore::TWriteBinarySerializer& rSerializer) const +{ + using chcore::Serializers::Serialize; + Serialize(rSerializer, m_vFilters); +} + bool CFiltersArray::IsEmpty() const { return m_vFilters.empty(); Index: src/ch/FileFilter.h =================================================================== diff -u -re30c2b40bd1b533d8740edc88d80b2fb340f3466 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/FileFilter.h (.../FileFilter.h) (revision e30c2b40bd1b533d8740edc88d80b2fb340f3466) +++ src/ch/FileFilter.h (.../FileFilter.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -53,45 +53,9 @@ void StoreInConfig(chcore::TConfig& rConfig) const; void ReadFromConfig(const chcore::TConfig& rConfig); - template - void serialize(Archive& ar, unsigned int /*uiVersion*/) - { - ar & m_bUseMask; - ar & m_astrMask; + void Serialize(chcore::TReadBinarySerializer& rSerializer); + void Serialize(chcore::TWriteBinarySerializer& rSerializer) const; - ar & m_bUseExcludeMask; - ar & m_astrExcludeMask; - - ar & m_bUseSize; - ar & m_iSizeType1; - ar & m_ullSize1; - ar & m_bUseSize2; - ar & m_iSizeType2; - ar & m_ullSize2; - - ar & m_bUseDate; - ar & m_iDateType; // created/last modified/last accessed - ar & m_iDateType1; // before/after - ar & m_bDate1; - ar & m_tDate1; - ar & m_bTime1; - ar & m_tTime1; - - ar & m_bUseDate2; - ar & m_iDateType2; - ar & m_bDate2; - ar & m_tDate2; - ar & m_bTime2; - ar & m_tTime2; - - ar & m_bUseAttributes; - ar & m_iArchive; - ar & m_iReadOnly; - ar & m_iHidden; - ar & m_iSystem; - ar & m_iDirectory; - } - protected: bool MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const; bool Scan(LPCTSTR& lpszMask, LPCTSTR& lpszString) const; @@ -150,11 +114,8 @@ void StoreInConfig(chcore::TConfig& rConfig, PCTSTR pszNodeName) const; bool ReadFromConfig(const chcore::TConfig& rConfig, PCTSTR pszNodeName); - template - void serialize(Archive& ar, unsigned int /*uiVersion*/) - { - ar & m_vFilters; - } + void Serialize(chcore::TReadBinarySerializer& rSerializer); + void Serialize(chcore::TWriteBinarySerializer& rSerializer) const; bool IsEmpty() const; Index: src/ch/FileInfo.cpp =================================================================== diff -u -r1456ff2ae4a98c83f18d20dc253a24f26ddf521d -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 1456ff2ae4a98c83f18d20dc253a24f26ddf521d) +++ src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -27,6 +27,8 @@ #include "ch.h" #include "../libicpf/exception.h" #include +#include "../libchcore/TBinarySerializer.h" +#include "../libchcore/SerializationHelpers.h" #ifdef _DEBUG #undef THIS_FILE @@ -135,6 +137,40 @@ return m_pathFile; } +void CFileInfo::Serialize(chcore::TReadBinarySerializer& rSerializer) +{ + using chcore::Serializers::Serialize; + + Serialize(rSerializer, m_pathFile); + Serialize(rSerializer, m_stSrcIndex); + Serialize(rSerializer, m_dwAttributes); + Serialize(rSerializer, m_uhFileSize); + Serialize(rSerializer, m_ftCreation.dwHighDateTime); + Serialize(rSerializer, m_ftCreation.dwLowDateTime); + Serialize(rSerializer, m_ftLastAccess.dwHighDateTime); + Serialize(rSerializer, m_ftLastAccess.dwLowDateTime); + Serialize(rSerializer, m_ftLastWrite.dwHighDateTime); + Serialize(rSerializer, m_ftLastWrite.dwLowDateTime); + Serialize(rSerializer, m_uiFlags); +} + +void CFileInfo::Serialize(chcore::TWriteBinarySerializer& rSerializer) const +{ + using chcore::Serializers::Serialize; + + Serialize(rSerializer, m_pathFile); + Serialize(rSerializer, m_stSrcIndex); + Serialize(rSerializer, m_dwAttributes); + Serialize(rSerializer, m_uhFileSize); + Serialize(rSerializer, m_ftCreation.dwHighDateTime); + Serialize(rSerializer, m_ftCreation.dwLowDateTime); + Serialize(rSerializer, m_ftLastAccess.dwHighDateTime); + Serialize(rSerializer, m_ftLastAccess.dwLowDateTime); + Serialize(rSerializer, m_ftLastWrite.dwHighDateTime); + Serialize(rSerializer, m_ftLastWrite.dwLowDateTime); + Serialize(rSerializer, m_uiFlags); +} + /////////////////////////////////////////////////////////////////////// // Array CFileInfoArray::CFileInfoArray(const chcore::TPathContainer& rBasePaths) : @@ -200,6 +236,61 @@ return ullSize; } +void CFileInfoArray::Serialize(chcore::TReadBinarySerializer& rSerializer, bool bOnlyFlags) +{ + using chcore::Serializers::Serialize; + + size_t stCount; + Serialize(rSerializer, stCount); + + if(!bOnlyFlags) + { + m_vFiles.clear(); + m_vFiles.reserve(stCount); + } + else if(stCount != m_vFiles.size()) + THROW(_T("Invalid count of flags received"), 0, 0, 0); + + CFileInfoPtr spFileInfo; + + uint_t uiFlags = 0; + for(size_t stIndex = 0; stIndex < stCount; stIndex++) + { + if(bOnlyFlags) + { + CFileInfoPtr& rspFileInfo = m_vFiles.at(stIndex); + Serialize(rSerializer, uiFlags); + rspFileInfo->SetFlags(uiFlags); + } + else + { + spFileInfo.reset(new CFileInfo); + spFileInfo->SetClipboard(&m_rBasePaths); + Serialize(rSerializer, *spFileInfo); + m_vFiles.push_back(spFileInfo); + } + } +} + +void CFileInfoArray::Serialize(chcore::TWriteBinarySerializer& rSerializer, bool bOnlyFlags) const +{ + using chcore::Serializers::Serialize; + + size_t stCount = m_vFiles.size(); + Serialize(rSerializer, stCount); + + for(std::vector::const_iterator iterFile = m_vFiles.begin(); iterFile != m_vFiles.end(); ++iterFile) + { + if(bOnlyFlags) + { + uint_t uiFlags = (*iterFile)->GetFlags(); + Serialize(rSerializer, uiFlags); + } + else + Serialize(rSerializer, *(*iterFile)); + } +} + unsigned long long CFileInfoArray::CalculatePartialSize(size_t stCount) { unsigned long long ullSize = 0; Index: src/ch/FileInfo.h =================================================================== diff -u -r1456ff2ae4a98c83f18d20dc253a24f26ddf521d -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/FileInfo.h (.../FileInfo.h) (revision 1456ff2ae4a98c83f18d20dc253a24f26ddf521d) +++ src/ch/FileInfo.h (.../FileInfo.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -84,21 +84,8 @@ // operators bool operator==(const CFileInfo& rInfo); - template - void serialize(Archive& ar, unsigned int /*uiVersion*/) - { - ar & m_pathFile; - ar & m_stSrcIndex; - ar & m_dwAttributes; - ar & m_uhFileSize; - ar & m_ftCreation.dwHighDateTime; - ar & m_ftCreation.dwLowDateTime; - ar & m_ftLastAccess.dwHighDateTime; - ar & m_ftLastAccess.dwLowDateTime; - ar & m_ftLastWrite.dwHighDateTime; - ar & m_ftLastWrite.dwLowDateTime; - ar & m_uiFlags; - } + void Serialize(chcore::TReadBinarySerializer& rSerializer); + void Serialize(chcore::TWriteBinarySerializer& rSerializer) const; private: chcore::TSmartPath m_pathFile; // contains relative path (first path is in CClipboardArray) @@ -146,70 +133,14 @@ unsigned long long CalculateTotalSize(); /// Stores infos about elements in the archive - template - void Store(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags) const; + void Serialize(chcore::TReadBinarySerializer& rSerializer, bool bOnlyFlags); + void Serialize(chcore::TWriteBinarySerializer& rSerializer, bool bOnlyFlags) const; - /// Restores info from the archive - template - void Load(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags); - protected: const chcore::TPathContainer& m_rBasePaths; std::vector m_vFiles; mutable boost::shared_mutex m_lock; }; -template -void CFileInfoArray::Store(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags) const -{ - size_t stCount = m_vFiles.size(); - ar << stCount; - for(std::vector::const_iterator iterFile = m_vFiles.begin(); iterFile != m_vFiles.end(); ++iterFile) - { - if(bOnlyFlags) - { - uint_t uiFlags = (*iterFile)->GetFlags(); - ar << uiFlags; - } - else - ar << *(*iterFile); - } -} - -template -void CFileInfoArray::Load(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags) -{ - size_t stCount; - ar >> stCount; - - if(!bOnlyFlags) - { - m_vFiles.clear(); - m_vFiles.reserve(stCount); - } - else if(stCount != m_vFiles.size()) - THROW(_T("Invalid count of flags received"), 0, 0, 0); - - CFileInfoPtr spFileInfo; - - uint_t uiFlags = 0; - for(size_t stIndex = 0; stIndex < stCount; stIndex++) - { - if(bOnlyFlags) - { - CFileInfoPtr& rspFileInfo = m_vFiles.at(stIndex); - ar >> uiFlags; - rspFileInfo->SetFlags(uiFlags); - } - else - { - spFileInfo.reset(new CFileInfo); - spFileInfo->SetClipboard(&m_rBasePaths); - ar >> *spFileInfo; - m_vFiles.push_back(spFileInfo); - } - } -} - #endif Index: src/ch/MainWnd.cpp =================================================================== diff -u -r63b228192b1d342075d81fd1974f40da98b44386 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 63b228192b1d342075d81fd1974f40da98b44386) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -38,6 +38,7 @@ #include "../libchcore/TConfig.h" #include "FileSupport.h" #include "StringHelpers.h" +#include "../libchcore/TCoreException.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -166,95 +167,123 @@ lpCreateStruct->dwExStyle |= WS_EX_TOPMOST; if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; + + bool bCaughtError = false; + const size_t stMaxErrInfo = 1024; + boost::shared_array szErrInfo(new wchar_t[stMaxErrInfo]); - // get msg id of taskbar created message - m_uiTaskbarRestart = RegisterWindowMessage(_T("TaskbarCreated")); + try + { + // get msg id of taskbar created message + m_uiTaskbarRestart = RegisterWindowMessage(_T("TaskbarCreated")); - // Create the tray icon - ShowTrayIcon(); + // Create the tray icon + ShowTrayIcon(); - // initialize CTaskArray - m_tasks.Create(m_pFeedbackFactory); + // initialize CTaskArray + m_tasks.Create(m_pFeedbackFactory); - // load last state - LOG_INFO(_T("Loading existing tasks...")); - CString strPath; - GetApp().GetProgramDataPath(strPath); - strPath += _T("\\Tasks\\"); - m_tasks.SetTasksDir(chcore::PathFromString(strPath)); + // load last state + LOG_INFO(_T("Loading existing tasks...")); + CString strPath; + GetApp().GetProgramDataPath(strPath); + strPath += _T("\\Tasks\\"); + m_tasks.SetTasksDir(chcore::PathFromString(strPath)); - // load tasks - m_tasks.LoadDataProgress(); + // load tasks + m_tasks.LoadDataProgress(); - // import tasks specified at command line (before loading current tasks) - const TCommandLineParser& cmdLine = GetApp().GetCommandLine(); - ProcessCommandLine(cmdLine); + // import tasks specified at command line (before loading current tasks) + const TCommandLineParser& cmdLine = GetApp().GetCommandLine(); + ProcessCommandLine(cmdLine); - // start clipboard monitoring - LOG_INFO(_T("Starting clipboard monitor...")); - CClipboardMonitor::StartMonitor(&m_tasks); + // start clipboard monitoring + LOG_INFO(_T("Starting clipboard monitor...")); + CClipboardMonitor::StartMonitor(&m_tasks); - EUpdatesFrequency eFrequency = (EUpdatesFrequency)GetPropValue(GetConfig()); - if(eFrequency != eFreq_Never) - { - unsigned long long ullMinInterval = 0; - switch(eFrequency) + EUpdatesFrequency eFrequency = (EUpdatesFrequency)GetPropValue(GetConfig()); + if(eFrequency != eFreq_Never) { - case eFreq_Daily: - ullMinInterval = 1*24*60*60; - break; - case eFreq_Weekly: - ullMinInterval = 7*24*60*60; - break; - case eFreq_OnceEvery2Weeks: - ullMinInterval = 14*24*60*60; - break; - case eFreq_Monthly: - ullMinInterval = 30*24*60*60; // we don't really care if it is a day less or more - break; - case eFreq_Quarterly: - ullMinInterval = 90*24*60*60; - break; - case eFreq_EveryStartup: - default: - ullMinInterval = 0; - } + unsigned long long ullMinInterval = 0; + switch(eFrequency) + { + case eFreq_Daily: + ullMinInterval = 1*24*60*60; + break; + case eFreq_Weekly: + ullMinInterval = 7*24*60*60; + break; + case eFreq_OnceEvery2Weeks: + ullMinInterval = 14*24*60*60; + break; + case eFreq_Monthly: + ullMinInterval = 30*24*60*60; // we don't really care if it is a day less or more + break; + case eFreq_Quarterly: + ullMinInterval = 90*24*60*60; + break; + case eFreq_EveryStartup: + default: + ullMinInterval = 0; + } - // get last check time stored in configuration - unsigned long long ullCurrentStamp = _time64(NULL); - unsigned long long ullTimestamp = GetPropValue(GetConfig()); + // get last check time stored in configuration + unsigned long long ullCurrentStamp = _time64(NULL); + unsigned long long ullTimestamp = GetPropValue(GetConfig()); - // perform checking for updates only when the minimal interval has passed - if(ullCurrentStamp - ullTimestamp >= ullMinInterval) - { - LOG_INFO(_T("Checking for updates...")); + // perform checking for updates only when the minimal interval has passed + if(ullCurrentStamp - ullTimestamp >= ullMinInterval) + { + LOG_INFO(_T("Checking for updates...")); - CUpdaterDlg* pDlg = new CUpdaterDlg(true); - pDlg->m_bAutoDelete = true; + CUpdaterDlg* pDlg = new CUpdaterDlg(true); + pDlg->m_bAutoDelete = true; - pDlg->Create(); - chcore::TConfig& rConfig = GetConfig(); - try - { - SetPropValue(rConfig, _time64(NULL)); - rConfig.Write(); + pDlg->Create(); + chcore::TConfig& rConfig = GetConfig(); + try + { + SetPropValue(rConfig, _time64(NULL)); + rConfig.Write(); + } + catch(icpf::exception& /*e*/) + { + LOG_ERROR(_T("Storing last update check timestamp in configuration failed")); + } } - catch(icpf::exception& /*e*/) - { - LOG_ERROR(_T("Storing last update check timestamp in configuration failed")); - } } - } - // start saving timer - SetTimer(1023, GetPropValue(GetConfig()), NULL); + // start saving timer + SetTimer(1023, GetPropValue(GetConfig()), NULL); - SetTimer(3245, TM_AUTOREMOVE, NULL); - SetTimer(8743, TM_ACCEPTING, NULL); // ends wait state in tasks + SetTimer(3245, TM_AUTOREMOVE, NULL); + SetTimer(8743, TM_ACCEPTING, NULL); // ends wait state in tasks - if (GetPropValue(GetConfig())) - PostMessage(WM_SHOWMINIVIEW); + if (GetPropValue(GetConfig())) + PostMessage(WM_SHOWMINIVIEW); + } + catch(chcore::TCoreException& e) + { + bCaughtError = true; + e.GetErrorInfo(szErrInfo.get(), stMaxErrInfo); + } + catch(std::exception& e) + { + bCaughtError = true; + _snwprintf_s(szErrInfo.get(), stMaxErrInfo, _TRUNCATE, _T("%S"), e.what()); + szErrInfo.get()[stMaxErrInfo - 1] = _T('\0'); + } + catch(...) + { + bCaughtError = true; + _snwprintf_s(szErrInfo.get(), stMaxErrInfo, _TRUNCATE, _T("Caught an unknown exception")); + } + if(bCaughtError) + { + LOG_ERROR(szErrInfo.get()); + return -1; + } return 0; } Fisheye: Tag 5fd6beaad9f1eccb664b997d151acb59961e4827 refers to a dead (removed) revision in file `src/ch/SerializationHelpers.h'. Fisheye: No comparison available. Pass `N' to diff? Index: src/ch/Stdafx.h =================================================================== diff -u -rb684bec49aaaea4b89ab2e599497f4085d8698a3 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/Stdafx.h (.../Stdafx.h) (revision b684bec49aaaea4b89ab2e599497f4085d8698a3) +++ src/ch/Stdafx.h (.../Stdafx.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -49,7 +49,6 @@ #include "../common/ErrorConstants.h" #include "../libchcore/TLogger.h" #include "../libchcore/TConfigSerializers.h" -#include "SerializationHelpers.h" #ifdef _UNICODE #if defined _M_IX86 Index: src/ch/TBasePathData.cpp =================================================================== diff -u -r16a61d123d45e60dea731a6620f6f47acccd8c43 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/TBasePathData.cpp (.../TBasePathData.cpp) (revision 16a61d123d45e60dea731a6620f6f47acccd8c43) +++ src/ch/TBasePathData.cpp (.../TBasePathData.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -22,6 +22,8 @@ // ============================================================================ #include "stdafx.h" #include "TBasePathData.h" +#include "..\libchcore\TBinarySerializer.h" +#include "..\libchcore\SerializationHelpers.h" ////////////////////////////////////////////////////////////////////////////// // TBasePathData @@ -51,6 +53,22 @@ return m_pathDst; } +void TBasePathData::Serialize(chcore::TReadBinarySerializer& rSerializer, bool bData) +{ + if(bData) + chcore::Serializers::Serialize(rSerializer, m_bMove); + else + chcore::Serializers::Serialize(rSerializer, m_pathDst); +} + +void TBasePathData::Serialize(chcore::TWriteBinarySerializer& rSerializer, bool bData) +{ + if(bData) + chcore::Serializers::Serialize(rSerializer, m_bMove); + else + chcore::Serializers::Serialize(rSerializer, m_pathDst); +} + ////////////////////////////////////////////////////////////////////////////// // TBasePathDataContainer @@ -124,3 +142,50 @@ boost::shared_lock lock(m_lock); return m_vEntries.size(); } + +void TBasePathDataContainer::Serialize(chcore::TReadBinarySerializer& rSerializer, bool bData) +{ + using chcore::Serializers::Serialize; + + size_t stCount; + Serialize(rSerializer, stCount); + + boost::unique_lock lock(m_lock); + + if(!bData && m_vEntries.size() != stCount) + THROW(_T("Count of entries with data differs from the count of state entries"), 0, 0, 0); + + if(bData) + { + m_vEntries.clear(); + m_vEntries.reserve(stCount); + } + + TBasePathDataPtr spEntry; + for(size_t stIndex = 0; stIndex < stCount; ++stIndex) + { + if(bData) + spEntry.reset(new TBasePathData); + else + spEntry = m_vEntries.at(stIndex); + spEntry->Serialize(rSerializer, bData); + + if(bData) + m_vEntries.push_back(spEntry); + } +} + +void TBasePathDataContainer::Serialize(chcore::TWriteBinarySerializer& rSerializer, bool bData) +{ + using chcore::Serializers::Serialize; + + boost::shared_lock lock(m_lock); + // write data + size_t stCount = m_vEntries.size(); + Serialize(rSerializer, stCount); + + BOOST_FOREACH(const TBasePathDataPtr& spEntry, m_vEntries) + { + spEntry->Serialize(rSerializer, bData); + } +} Index: src/ch/TBasePathData.h =================================================================== diff -u -ra77ea347e3787d330b37917be4c72be480419c93 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/TBasePathData.h (.../TBasePathData.h) (revision a77ea347e3787d330b37917be4c72be480419c93) +++ src/ch/TBasePathData.h (.../TBasePathData.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -48,14 +48,8 @@ chcore::TSmartPath GetDestinationPath() const; bool IsDestinationPathSet() const { return !m_pathDst.IsEmpty(); } - template - void Serialize(Archive& ar, unsigned int /*uiVersion*/, bool bData) - { - if(bData) - ar & m_bMove; - else - ar & m_pathDst; - } + void Serialize(chcore::TReadBinarySerializer& rSerializer, bool bData); + void Serialize(chcore::TWriteBinarySerializer& rSerializer, bool bData); private: bool m_bMove; // specifies if we can use MoveFile (if will be moved) @@ -89,12 +83,9 @@ void Clear(); // serialization - template - void Store(Archive& ar, unsigned int /*uiVersion*/, bool bData) const; + void Serialize(chcore::TReadBinarySerializer& rSerializer, bool bData); + void Serialize(chcore::TWriteBinarySerializer& rSerializer, bool bData); - template - void Load(Archive& ar, unsigned int /*uiVersion*/, bool bData); - private: TBasePathDataContainer(const TBasePathDataContainer& rSrc); TBasePathDataContainer& operator=(const TBasePathDataContainer& rSrc); @@ -106,49 +97,4 @@ mutable boost::shared_mutex m_lock; }; -template -void TBasePathDataContainer::Store(Archive& ar, unsigned int /*uiVersion*/, bool bData) const -{ - boost::shared_lock lock(m_lock); - // write data - size_t stCount = m_vEntries.size(); - ar << stCount; - - BOOST_FOREACH(const TBasePathDataPtr& spEntry, m_vEntries) - { - spEntry->Serialize(ar, 0, bData); - } -} - -template -void TBasePathDataContainer::Load(Archive& ar, unsigned int /*uiVersion*/, bool bData) -{ - size_t stCount; - ar >> stCount; - - boost::unique_lock lock(m_lock); - - if(!bData && m_vEntries.size() != stCount) - THROW(_T("Count of entries with data differs from the count of state entries"), 0, 0, 0); - - if(bData) - { - m_vEntries.clear(); - m_vEntries.reserve(stCount); - } - - TBasePathDataPtr spEntry; - for(size_t stIndex = 0; stIndex < stCount; ++stIndex) - { - if(bData) - spEntry.reset(new TBasePathData); - else - spEntry = m_vEntries.at(stIndex); - spEntry->Serialize(ar, 0, bData); - - if(bData) - m_vEntries.push_back(spEntry); - } -} - #endif // __TBASEPATHDATA_H__ Index: src/ch/TBasicProgressInfo.cpp =================================================================== diff -u -r6e8aa26e2428e3bc71099255c5911f57bc722100 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/TBasicProgressInfo.cpp (.../TBasicProgressInfo.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) +++ src/ch/TBasicProgressInfo.cpp (.../TBasicProgressInfo.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -22,6 +22,8 @@ // ============================================================================ #include "stdafx.h" #include "TBasicProgressInfo.h" +#include "..\libchcore\TBinarySerializer.h" +#include "..\libchcore\SerializationHelpers.h" TTaskBasicProgressInfo::TTaskBasicProgressInfo() : @@ -90,3 +92,40 @@ boost::unique_lock lock(m_lock); ++m_stSubOperationIndex; } + +void TTaskBasicProgressInfo::Serialize(chcore::TReadBinarySerializer& rSerializer) +{ + using chcore::Serializers::Serialize; + + size_t stCurrentIndex = 0; + Serialize(rSerializer, stCurrentIndex); + + unsigned long long ullCurrentFileProcessedSize = 0; + Serialize(rSerializer, ullCurrentFileProcessedSize); + + size_t stSubOperationIndex = 0; + Serialize(rSerializer, stSubOperationIndex); + + boost::unique_lock lock(m_lock); + + m_stCurrentIndex = stCurrentIndex; + m_ullCurrentFileProcessedSize = ullCurrentFileProcessedSize; + m_stSubOperationIndex = stSubOperationIndex; +} + +void TTaskBasicProgressInfo::Serialize(chcore::TWriteBinarySerializer& rSerializer) const +{ + using chcore::Serializers::Serialize; + + m_lock.lock_shared(); + + size_t stCurrentIndex = m_stCurrentIndex; + unsigned long long ullCurrentFileProcessedSize = m_ullCurrentFileProcessedSize; + size_t stSubOperationIndex = m_stSubOperationIndex; + + m_lock.unlock_shared(); + + Serialize(rSerializer, stCurrentIndex); + Serialize(rSerializer, ullCurrentFileProcessedSize); + Serialize(rSerializer, stSubOperationIndex); +} Index: src/ch/TBasicProgressInfo.h =================================================================== diff -u -r6e8aa26e2428e3bc71099255c5911f57bc722100 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/TBasicProgressInfo.h (.../TBasicProgressInfo.h) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) +++ src/ch/TBasicProgressInfo.h (.../TBasicProgressInfo.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -23,7 +23,6 @@ #ifndef __TBASICPROGRESSINFO_H__ #define __TBASICPROGRESSINFO_H__ - /////////////////////////////////////////////////////////////////////////// // TTaskBasicProgressInfo @@ -45,43 +44,12 @@ size_t GetSubOperationIndex() const; void IncreaseSubOperationIndex(); - template - void load(Archive& ar, unsigned int /*uiVersion*/) - { - size_t stCurrentIndex = 0; - ar >> stCurrentIndex; + void Serialize(chcore::TReadBinarySerializer& rSerializer); + void Serialize(chcore::TWriteBinarySerializer& rSerializer) const; - unsigned long long ullCurrentFileProcessedSize = 0; - ar >> ullCurrentFileProcessedSize; +private: + TTaskBasicProgressInfo(const TTaskBasicProgressInfo& rSrc); - size_t stSubOperationIndex = 0; - ar >> stSubOperationIndex; - - boost::unique_lock lock(m_lock); - - m_stCurrentIndex = stCurrentIndex; - m_ullCurrentFileProcessedSize = ullCurrentFileProcessedSize; - m_stSubOperationIndex = stSubOperationIndex; - } - - template - void save(Archive& ar, unsigned int /*uiVersion*/) const - { - m_lock.lock_shared(); - - size_t stCurrentIndex = m_stCurrentIndex; - unsigned long long ullCurrentFileProcessedSize = m_ullCurrentFileProcessedSize; - size_t stSubOperationIndex = m_stSubOperationIndex; - - m_lock.unlock_shared(); - - ar << stCurrentIndex; - ar << ullCurrentFileProcessedSize; - ar << stSubOperationIndex; - } - - BOOST_SERIALIZATION_SPLIT_MEMBER(); - private: volatile size_t m_stSubOperationIndex; // index of sub-operation from TOperationDescription volatile size_t m_stCurrentIndex; // index to the m_files array stating currently processed item Index: src/ch/ch.vc90.vcproj =================================================================== diff -u -r633a533cb6e741d44fe28aa56339e1d2709b1b27 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/ch/ch.vc90.vcproj (.../ch.vc90.vcproj) (revision 633a533cb6e741d44fe28aa56339e1d2709b1b27) +++ src/ch/ch.vc90.vcproj (.../ch.vc90.vcproj) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -451,7 +451,7 @@ > lock(m_lock); //////////////////////////////// @@ -154,27 +158,26 @@ //////////////////////////////// // now rarely changing task progress data chcore::TSmartPath pathRarelyChangingPath = GetRelatedPathNL(ePathType_TaskRarelyChangingState); - std::ifstream ifs(pathRarelyChangingPath.ToString(), ios_base::in | ios_base::binary); - boost::archive::binary_iarchive ar(ifs); + chcore::TReadBinarySerializer readSerializer; + readSerializer.Init(pathRarelyChangingPath); - m_arrSourcePathsInfo.Load(ar, 0, true); - m_files.Load(ar, 0, false); + m_arrSourcePathsInfo.Serialize(readSerializer, true); + m_files.Serialize(readSerializer, false); CalculateTotalSizeNL(); /////////////////////////////////// // and often changing data chcore::TSmartPath pathOftenChangingPath = GetRelatedPathNL(ePathType_TaskOftenChangingState); - std::ifstream ifs2(pathOftenChangingPath.ToString(), ios_base::in | ios_base::binary); - boost::archive::binary_iarchive ar2(ifs2); + readSerializer.Init(pathOftenChangingPath); - ar2 >> m_tTaskBasicProgressInfo; + Serialize(readSerializer, m_tTaskBasicProgressInfo); CalculateProcessedSizeNL(); // load task state, convert "waiting" state to "processing" int iState = eTaskState_None; - ar2 >> iState; + Serialize(readSerializer, iState); if(iState >= eTaskState_None && iState < eTaskState_Max) { if(iState == eTaskState_Waiting) @@ -188,15 +191,17 @@ } time_t timeElapsed = 0; - ar2 >> timeElapsed; + Serialize(readSerializer, timeElapsed); m_localStats.SetTimeElapsed(timeElapsed); - m_arrSourcePathsInfo.Load(ar2, 0, false); - m_files.Load(ar2, 0, true); + m_arrSourcePathsInfo.Serialize(readSerializer, false); + m_files.Serialize(readSerializer, true); } void CTask::Store() { + using chcore::Serializers::Serialize; + boost::upgrade_lock lock(m_lock); BOOST_ASSERT(!m_strTaskDirectory.IsEmpty()); @@ -216,39 +221,39 @@ // rarely changing data if(m_bRareStateModified) { - std::ofstream ofs(GetRelatedPathNL(ePathType_TaskRarelyChangingState).ToString(), ios_base::out | ios_base::binary); - boost::archive::binary_oarchive ar(ofs); + chcore::TWriteBinarySerializer writeSerializer; + writeSerializer.Init(GetRelatedPathNL(ePathType_TaskRarelyChangingState)); - m_arrSourcePathsInfo.Store(ar, 0, true); - m_files.Store(ar, 0, false); + m_arrSourcePathsInfo.Serialize(writeSerializer, true); + m_files.Serialize(writeSerializer, false); } if(m_bOftenStateModified) { - std::ofstream ofs(GetRelatedPathNL(ePathType_TaskOftenChangingState).ToString(), ios_base::out | ios_base::binary); - boost::archive::binary_oarchive ar(ofs); + chcore::TWriteBinarySerializer writeSerializer; + writeSerializer.Init(GetRelatedPathNL(ePathType_TaskOftenChangingState)); - ar << m_tTaskBasicProgressInfo; + Serialize(writeSerializer, m_tTaskBasicProgressInfo); // store current state (convert from waiting to processing state before storing) int iState = m_eCurrentState; if(iState == eTaskState_Waiting) iState = eTaskState_Processing; - ar << iState; + Serialize(writeSerializer, iState); time_t timeElapsed = m_localStats.GetTimeElapsed(); - ar << timeElapsed; + Serialize(writeSerializer, timeElapsed); - m_arrSourcePathsInfo.Store(ar, 0, false); + m_arrSourcePathsInfo.Serialize(writeSerializer, false); chcore::ESubOperationType eSubOperation = m_tTaskDefinition.GetOperationPlan().GetSubOperationAt(m_tTaskBasicProgressInfo.GetSubOperationIndex()); if(eSubOperation != chcore::eSubOperation_Scanning) - m_files.Store(ar, 0, true); + m_files.Serialize(writeSerializer, true); else { - size_t st(0); - ar << st; + size_t stFakeSize(0); + Serialize(writeSerializer, stFakeSize); } } } @@ -1183,12 +1188,6 @@ // add read task to array Add(spTask); } - catch(std::exception& e) - { - CString strFmt; - strFmt.Format(_T("Cannot load task data: %s (reason: %S)"), pathFound.ToString(), e.what()); - LOG_ERROR(strFmt); - } catch(icpf::exception& e) { CString strMsg; @@ -1199,6 +1198,12 @@ strFmt.Format(_T("Cannot load task data: %s (reason: %s)"), pathFound.ToString(), (PCTSTR)strMsg); LOG_ERROR(strFmt); } + catch(std::exception& e) + { + CString strFmt; + strFmt.Format(_T("Cannot load task data: %s (reason: %S)"), pathFound.ToString(), e.what()); + LOG_ERROR(strFmt); + } } finder.Close(); } Index: src/chext/chext.vc90.vcproj =================================================================== diff -u -r633a533cb6e741d44fe28aa56339e1d2709b1b27 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/chext/chext.vc90.vcproj (.../chext.vc90.vcproj) (revision 633a533cb6e741d44fe28aa56339e1d2709b1b27) +++ src/chext/chext.vc90.vcproj (.../chext.vc90.vcproj) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -47,7 +47,7 @@ + +BEGIN_CHCORE_NAMESPACE + +namespace Serializers +{ + struct GeneralSerializer + { + template static void StoreValue(Serializer& rSerializer, const T& tValue) { tValue.Serialize(rSerializer); } + template static void LoadValue(Serializer& rSerializer, T& tValue) { tValue.Serialize(rSerializer); } + }; + + struct NativeSerializer + { + template static void StoreValue(Serializer& rSerializer, const T& tValue) { rSerializer.Store(tValue); } + template static void LoadValue(Serializer& rSerializer, T& tValue) { rSerializer.Load(tValue); } + }; + + struct EnumSerializer + { + template static void StoreValue(Serializer& rSerializer, const T& tValue) { Serialize(rSerializer, (int)tValue); } + template static void LoadValue(Serializer& rSerializer, T& tValue) { Serialize(rSerializer, *(int*)tValue); } + }; + + struct StlContainerSerializer + { + template static void StoreValue(Serializer& rSerializer, const T& tValue) + { + typedef typename T::value_type ItemType; + + Serialize(rSerializer, tValue.size()); + BOOST_FOREACH(const ItemType& rItem, tValue) + { + Serialize(rSerializer, rItem); + } + } + template static void LoadValue(Serializer& rSerializer, T& tValue) + { + typedef typename T::value_type ItemType; + ItemType item; + + size_t stCount = 0; + Serialize(rSerializer, stCount); + while(stCount--) + { + Serialize(rSerializer, item); + + std::back_inserter(tValue) = item; + } + } + }; + + template + struct is_serializer_native_type + { + static const bool value = boost::mpl::has_key::value; + }; + + // Main interface for serialization + template + inline void Serialize(TReadBinarySerializer& rSerializer, T& tValue) + { + typedef typename + boost::mpl::if_, EnumSerializer, + boost::mpl::if_, StlContainerSerializer, + boost::mpl::if_, NativeSerializer, + GeneralSerializer>::type >::type >::type SerializerType; + SerializerType::LoadValue(rSerializer, tValue); + } + + template + inline void Serialize(TWriteBinarySerializer& rSerializer, const T& tValue) + { + typedef typename + boost::mpl::if_, EnumSerializer, + boost::mpl::if_, StlContainerSerializer, + boost::mpl::if_, NativeSerializer, + GeneralSerializer>::type >::type >::type SerializerType; + SerializerType::StoreValue(rSerializer, tValue); + } + +#ifdef _MFC_VER + template<> + inline void Serialize(TReadBinarySerializer& rSerializer, CString& tValue) + { + TString strVal; + Serialize(rSerializer, strVal); + tValue = strVal; + } + + template<> + inline void Serialize(TWriteBinarySerializer& rSerializer, const CString& tValue) + { + Serialize(rSerializer, (PCTSTR)tValue); + } + + template<> + inline void Serialize(TReadBinarySerializer& rSerializer, CTime& tValue) + { + long long llTime = 0; + Serialize(rSerializer, llTime); + tValue = CTime(llTime); + } + + template<> + inline void Serialize(TWriteBinarySerializer& rSerializer, const CTime& tValue) + { + long long llTime = tValue.GetTime(); + Serialize(rSerializer, llTime); + } +#endif +} + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/TBinarySerializer.cpp =================================================================== diff -u --- src/libchcore/TBinarySerializer.cpp (revision 0) +++ src/libchcore/TBinarySerializer.cpp (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -0,0 +1,494 @@ +// ============================================================================ +// Copyright (C) 2001-2011 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +/// @file TBinarySerializer.h +/// @date 2011/06/20 +/// @brief Contains declaration of TBinarySerializer class. +// ============================================================================ +#include "stdafx.h" +#include "TBinarySerializer.h" +#include +#include + +#include "TPath.h" +#include "ErrorCodes.h" + +BEGIN_CHCORE_NAMESPACE + +///////////////////////////////////////////////////////////////////////////////////////// +// class TReadBinarySerializer + +TReadBinarySerializer::TReadBinarySerializer() +{ +} + +TReadBinarySerializer::~TReadBinarySerializer() +{ + try + { + Close(); + } + catch(...) + { + } +} + +void TReadBinarySerializer::Init(const TSmartPath& pathFile) +{ + Close(); + + try + { + m_spInputStream = boost::make_shared(pathFile.ToString(), std::ios_base::in | std::ios_base::binary); + m_spArchive = boost::make_shared(std::tr1::ref(*m_spInputStream)); + } + catch(std::exception& e) + { + m_spArchive.reset(); + m_spInputStream.reset(); + + THROW_CORE_EXCEPTION_STD(eErr_CannotReadArchive, e); + } +} + +void TReadBinarySerializer::Close() +{ + // order is important - first close the archive, then input stream + m_spArchive.reset(); + m_spInputStream.reset(); +} + +void TReadBinarySerializer::Load(bool& bValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & bValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(short& shValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & shValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(unsigned short& ushValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & ushValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(int& iValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & iValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(unsigned int& uiValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & uiValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(long& lValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & lValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(unsigned long& ulValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & ulValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(long long& llValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & llValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(unsigned long long& ullValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & ullValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(float& fValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & fValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(double& dValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & dValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +void TReadBinarySerializer::Load(TString& strValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + std::wstring wstrData; + (*m_spArchive) & wstrData; + strValue = wstrData.c_str(); + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeLoadError, e); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// +// class TWriteBinarySerializer + +TWriteBinarySerializer::TWriteBinarySerializer() +{ +} + +TWriteBinarySerializer::~TWriteBinarySerializer() +{ + try + { + Close(); + } + catch(...) + { + } +} + +void TWriteBinarySerializer::Init(const TSmartPath& pathFile) +{ + try + { + m_spOutputStream = boost::make_shared(pathFile.ToString(), std::ios_base::out | std::ios_base::binary); + m_spArchive = boost::make_shared(std::tr1::ref(*m_spOutputStream)); + } + catch(std::exception&) + { + m_spArchive.reset(); + m_spOutputStream.reset(); + THROW_CORE_EXCEPTION(eErr_CannotWriteArchive); + } +} + +void TWriteBinarySerializer::Close() +{ + m_spArchive.reset(); + m_spOutputStream.reset(); +} + +void TWriteBinarySerializer::Store(bool bValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & bValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(short shValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & shValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(unsigned short ushValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & ushValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(int iValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & iValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(unsigned int uiValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & uiValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(long lValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & lValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(unsigned long ulValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & ulValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(long long llValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & llValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(unsigned long long ullValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & ullValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(float fValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & fValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(double dValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + (*m_spArchive) & dValue; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(const TString& strValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + std::wstring wstrData((const wchar_t*)strValue); + (*m_spArchive) & wstrData; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +void TWriteBinarySerializer::Store(const wchar_t* strValue) +{ + if(!m_spArchive) + THROW_CORE_EXCEPTION(eErr_UseOfUninitializedObject); + + try + { + std::wstring wstrData(strValue); + (*m_spArchive) & wstrData; + } + catch (std::exception& e) + { + THROW_CORE_EXCEPTION_STD(eErr_SerializeStoreError, e); + } +} + +END_CHCORE_NAMESPACE Index: src/libchcore/TBinarySerializer.h =================================================================== diff -u --- src/libchcore/TBinarySerializer.h (revision 0) +++ src/libchcore/TBinarySerializer.h (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -0,0 +1,110 @@ +// ============================================================================ +// Copyright (C) 2001-2011 by Jozef Starosczyk +// ixen@copyhandler.com +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU Library General Public License +// (version 2) as published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// ============================================================================ +/// @file TBinarySerializer.h +/// @date 2011/06/20 +/// @brief Contains declaration of TBinarySerializer class. +// ============================================================================ +#ifndef __TBINARYSERIALIZER_H__ +#define __TBINARYSERIALIZER_H__ + +#include "libchcore.h" +#include +#include +#include +#pragma warning(push) +#pragma warning(disable: 4996) + #include + #include +#pragma warning(pop) + +BEGIN_CHCORE_NAMESPACE + +class TSmartPath; +class TString; + +class LIBCHCORE_API TReadBinarySerializer +{ +public: + typedef boost::mpl::set NativeTypes; + +public: + TReadBinarySerializer(); + ~TReadBinarySerializer(); + + void Init(const TSmartPath& pathFile); + void Close(); + + void Load(bool& bValue); + void Load(short& shValue); + void Load(unsigned short& ushValue); + void Load(int& iValue); + void Load(unsigned int& uiValue); + void Load(long& lValue); + void Load(unsigned long& ulValue); + void Load(long long& llValue); + void Load(unsigned long long& ullValue); + void Load(float& fValue); + void Load(double& dValue); + void Load(TString& strValue); + +private: +#pragma warning(push) +#pragma warning(disable: 4251) + boost::shared_ptr m_spInputStream; + boost::shared_ptr m_spArchive; +#pragma warning(pop) +}; + +class LIBCHCORE_API TWriteBinarySerializer +{ +public: + typedef boost::mpl::set NativeTypes; + +public: + TWriteBinarySerializer(); + ~TWriteBinarySerializer(); + + void Init(const TSmartPath& pathFile); + void Close(); + + void Store(bool bValue); + void Store(short shValue); + void Store(unsigned short ushValue); + void Store(int iValue); + void Store(unsigned int uiValue); + void Store(long lValue); + void Store(unsigned long ulValue); + void Store(long long llValue); + void Store(unsigned long long ullValue); + void Store(float fValue); + void Store(double dValue); + void Store(const TString& strValue); + void Store(const wchar_t* strValue); + +private: +#pragma warning(push) +#pragma warning(disable: 4251) + boost::shared_ptr m_spOutputStream; + boost::shared_ptr m_spArchive; +#pragma warning(pop) +}; + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/TConfig.cpp =================================================================== diff -u -rbe5d5dfa17e79a1db8e64ad2d2ed5faea30399cb -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TConfig.cpp (.../TConfig.cpp) (revision be5d5dfa17e79a1db8e64ad2d2ed5faea30399cb) +++ src/libchcore/TConfig.cpp (.../TConfig.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -26,12 +26,15 @@ #include #include #include "../libicpf/exception.h" +#include "TBinarySerializer.h" +#include "SerializationHelpers.h" #pragma warning(push) #pragma warning(disable: 4702 4512) #include #pragma warning(pop) #include +#include BEGIN_CHCORE_NAMESPACE @@ -244,6 +247,95 @@ } } +void TConfig::SerializeLoad(TReadBinarySerializer& rSerializer) +{ + using namespace Serializers; + + boost::property_tree::wiptree propTree; + + SerializeLoadNode(rSerializer, propTree); + + boost::unique_lock lock(m_lock); + m_propTree = propTree; +} + +void TConfig::SerializeLoadNode(TReadBinarySerializer& rSerializer, boost::property_tree::wiptree& treeNode) +{ + using namespace Serializers; + + size_t stCount = 0; + Serialize(rSerializer, stCount); + + while(stCount--) + { + // name of the node + TString strNodeName; + Serialize(rSerializer, strNodeName); + + bool bValue = false; + Serialize(rSerializer, bValue); + + if(bValue) + { + // value + TString strNodeValue; + Serialize(rSerializer, strNodeValue); + + treeNode.add((PCTSTR)strNodeName, (PCTSTR)strNodeValue); + } + else + { + boost::property_tree::wiptree& rSubnodeTree = treeNode.add_child((PCTSTR)strNodeName, boost::property_tree::wiptree()); + SerializeLoadNode(rSerializer, rSubnodeTree); + } + } +} + +void TConfig::SerializeStore(TWriteBinarySerializer& rSerializer) +{ + using namespace Serializers; + + boost::property_tree::wiptree propTree; + + // make a copy of internal tree (with locking) to avoid locking within serialization operation + { + boost::shared_lock lock(m_lock); + propTree = m_propTree; + } + + // serialize the copy + SerializeStoreNode(rSerializer, propTree); +} + +void TConfig::SerializeStoreNode(TWriteBinarySerializer& rSerializer, boost::property_tree::wiptree& treeNode) +{ + using namespace Serializers; + Serialize(rSerializer, treeNode.size()); + + for(boost::property_tree::wiptree::iterator iterNode = treeNode.begin(); iterNode != treeNode.end(); ++iterNode) + { + // is this node the leaf one? + boost::property_tree::wiptree& rSubNode = (*iterNode).second; + + // name of the node + Serialize(rSerializer, (*iterNode).first.c_str()); + + bool bValue = rSubNode.empty(); + Serialize(rSerializer, bValue); + + if(bValue) + { + // value + Serialize(rSerializer, rSubNode.data().c_str()); + } + else + { + // store children + SerializeStoreNode(rSerializer, rSubNode); + } + } +} + void TConfig::ReadFromString(const TString& strInput) { if(strInput.IsEmpty()) Index: src/libchcore/TConfig.h =================================================================== diff -u -rbe5d5dfa17e79a1db8e64ad2d2ed5faea30399cb -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TConfig.h (.../TConfig.h) (revision be5d5dfa17e79a1db8e64ad2d2ed5faea30399cb) +++ src/libchcore/TConfig.h (.../TConfig.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -33,6 +33,9 @@ BEGIN_CHCORE_NAMESPACE +class TReadBinarySerializer; +class TWriteBinarySerializer; + // class defines configuration change notification record; not to be used outside class TConfigNotifier { @@ -96,6 +99,9 @@ void Read(PCTSTR pszFile); void Write(bool bOnlyIfModified = false); + void SerializeLoad(TReadBinarySerializer& rSerializer); + void SerializeStore(TWriteBinarySerializer& rSerializer); + void ReadFromString(const TString& strInput); void WriteToString(TString& strOutput); @@ -159,6 +165,9 @@ void ClearNL(); + void SerializeStoreNode(TWriteBinarySerializer& rSerializer, boost::property_tree::wiptree& treeNode); + void SerializeLoadNode(TReadBinarySerializer& rSerializer, boost::property_tree::wiptree& treeNode); + private: #pragma warning(push) #pragma warning(disable: 4251) Index: src/libchcore/TCoreException.cpp =================================================================== diff -u -re9926b6e83984d0f30bf2008b93874c7c483d95c -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TCoreException.cpp (.../TCoreException.cpp) (revision e9926b6e83984d0f30bf2008b93874c7c483d95c) +++ src/libchcore/TCoreException.cpp (.../TCoreException.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -19,34 +19,51 @@ #include "stdafx.h" #include "TCoreException.h" +BEGIN_CHCORE_NAMESPACE + // ============================================================================ /// chcore::TCoreException::TCoreException /// @date 2009/11/30 /// -/// @brief Constructs the core exception object. -/// @param[in] eErrorCode - error code -/// @param[in] pszInternalError - internal error message +/// @brief Constructs core exception object with additional data. +/// @param[in] eErrorCode - error code +/// @param[in] pszFile - source file name +/// @param[in] stLineNumber - source line number +/// @param[in] pszFunction - function name in which the problem occured. // ============================================================================ -BEGIN_CHCORE_NAMESPACE +TCoreException::TCoreException(EGeneralErrors eErrorCode, const tchar_t* pszFile, size_t stLineNumber, const tchar_t* pszFunction) : + m_eErrorCode(eErrorCode), + m_pszFile(pszFile), + m_stLineNumber(stLineNumber), + m_pszFunction(pszFunction) +{ + BOOST_ASSERT(false); +} // ============================================================================ /// chcore::TCoreException::TCoreException /// @date 2009/11/30 /// /// @brief Constructs core exception object with additional data. -/// @param[in] eErrorCode - error code -/// @param[in] pszInternalError - error description +/// @param[in] eErrorCode - error code +/// @param[in] stdException - standard exception info /// @param[in] pszFile - source file name /// @param[in] stLineNumber - source line number /// @param[in] pszFunction - function name in which the problem occured. // ============================================================================ -TCoreException::TCoreException(EGeneralErrors eErrorCode, const tchar_t* pszFile, size_t stLineNumber, const tchar_t* pszFunction) : +TCoreException::TCoreException(EGeneralErrors eErrorCode, std::exception& stdException, const tchar_t* pszFile, size_t stLineNumber, const tchar_t* pszFunction) : + std::exception(stdException), m_eErrorCode(eErrorCode), m_pszFile(pszFile), - m_strLineNumber(stLineNumber), + m_stLineNumber(stLineNumber), m_pszFunction(pszFunction) { - BOOST_ASSERT(false); } +void TCoreException::GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const +{ + _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("Error code: %ld\r\nFile: %s\r\nFunction: %s\r\nLine no: %lu"), m_eErrorCode, m_pszFile, m_pszFunction, m_stLineNumber); + pszBuffer[stMaxBuffer - 1] = _T('\0'); +} + END_CHCORE_NAMESPACE Index: src/libchcore/TCoreException.h =================================================================== diff -u -re9926b6e83984d0f30bf2008b93874c7c483d95c -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TCoreException.h (.../TCoreException.h) (revision e9926b6e83984d0f30bf2008b93874c7c483d95c) +++ src/libchcore/TCoreException.h (.../TCoreException.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -20,27 +20,32 @@ #define __TEXCEPTION_H__ #include "libchcore.h" +#include "ErrorCodes.h" BEGIN_CHCORE_NAMESPACE // throws core exception object #define THROW_CORE_EXCEPTION(error_code)\ throw TCoreException(error_code, __FILEW__, __LINE__, __FUNCTIONW__) +#define THROW_CORE_EXCEPTION_STD(error_code, std_exception)\ + throw TCoreException(error_code, std_exception, __FILEW__, __LINE__, __FUNCTIONW__) -class LIBCHCORE_API TCoreException +class LIBCHCORE_API TCoreException : public virtual std::exception { public: - TCoreException(EGeneralErrors eErrorCode); TCoreException(EGeneralErrors eErrorCode, const tchar_t* pszFile, size_t stLineNumber, const tchar_t* pszFunction); + TCoreException(EGeneralErrors eErrorCode, std::exception& stdException, const tchar_t* pszFile, size_t stLineNumber, const tchar_t* pszFunction); // error information EGeneralErrors GetErrorCode() const { return m_eErrorCode; } // location info const wchar_t* GetSourceFile() const { return m_pszFile; } - size_t GetSourceLineNumber() const { return m_strLineNumber; } + size_t GetSourceLineNumber() const { return m_stLineNumber; } const wchar_t* GetFunctionName() const { return m_pszFunction; } + void GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const; + private: TCoreException() {} @@ -51,7 +56,7 @@ // where it happened? const wchar_t* m_pszFile; const wchar_t* m_pszFunction; - size_t m_strLineNumber; + size_t m_stLineNumber; }; END_CHCORE_NAMESPACE Index: src/libchcore/TPath.cpp =================================================================== diff -u -re9926b6e83984d0f30bf2008b93874c7c483d95c -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TPath.cpp (.../TPath.cpp) (revision e9926b6e83984d0f30bf2008b93874c7c483d95c) +++ src/libchcore/TPath.cpp (.../TPath.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -26,6 +26,8 @@ #pragma warning(pop) #include "../libicpf/exception.h" #include +#include "TBinarySerializer.h" +#include "SerializationHelpers.h" BEGIN_CHCORE_NAMESPACE @@ -1020,6 +1022,20 @@ return m_pPath->m_strPath.GetLength(); } +void TSmartPath::Serialize(TReadBinarySerializer& rSerializer) +{ + PrepareToWrite(); + Serializers::Serialize(rSerializer, m_pPath->m_strPath); +} + +void TSmartPath::Serialize(TWriteBinarySerializer& rSerializer) const +{ + if(m_pPath) + Serializers::Serialize(rSerializer, m_pPath->m_strPath); + else + Serializers::Serialize(rSerializer, TString()); +} + // ============================================================================ /// chcore::TSmartPath::StoreInConfig /// @date 2011/04/05 @@ -1028,7 +1044,7 @@ /// @param[in] rConfig - configuration object to store information in. /// @param[in] pszPropName - property name under which to store the path. // ============================================================================ -void TSmartPath::StoreInConfig(chcore::TConfig& rConfig, PCTSTR pszPropName) const +void TSmartPath::StoreInConfig(TConfig& rConfig, PCTSTR pszPropName) const { rConfig.SetValue(pszPropName, m_pPath ? m_pPath->m_strPath : TString()); } @@ -1042,7 +1058,7 @@ /// @param[in] pszPropName - property name from under which to read the path. /// @return True if path properly read, false otherwise. // ============================================================================ -bool TSmartPath::ReadFromConfig(const chcore::TConfig& rConfig, PCTSTR pszPropName) +bool TSmartPath::ReadFromConfig(const TConfig& rConfig, PCTSTR pszPropName) { TString wstrPath; if(rConfig.GetValue(pszPropName, wstrPath)) @@ -1280,7 +1296,7 @@ return m_vPaths.empty(); } -void TPathContainer::StoreInConfig(chcore::TConfig& rConfig, PCTSTR pszPropName) const +void TPathContainer::StoreInConfig(TConfig& rConfig, PCTSTR pszPropName) const { TStringArray vPaths; @@ -1293,7 +1309,7 @@ rConfig.SetValue(pszPropName, vPaths); } -bool TPathContainer::ReadFromConfig(const chcore::TConfig& rConfig, PCTSTR pszPropName) +bool TPathContainer::ReadFromConfig(const TConfig& rConfig, PCTSTR pszPropName) { m_vPaths.clear(); Index: src/libchcore/TPath.h =================================================================== diff -u -r0cd863a6e51b221c4f7bf6e7b83ddfc43a5d433f -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TPath.h (.../TPath.h) (revision 0cd863a6e51b221c4f7bf6e7b83ddfc43a5d433f) +++ src/libchcore/TPath.h (.../TPath.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -19,7 +19,6 @@ #ifndef __TPATH_H__ #define __TPATH_H__ -#include #include "libchcore.h" #include "TConfig.h" @@ -134,30 +133,12 @@ size_t GetLength() const; // Serialization - template - void load(Archive& ar, unsigned int /*uiVersion*/) - { - PrepareToWrite(); - ar & m_pPath->m_strPath; - } + void Serialize(TReadBinarySerializer& rSerializer); + void Serialize(TWriteBinarySerializer& rSerializer) const; - template - void save(Archive& ar, unsigned int /*uiVersion*/) const - { - if(m_pPath) - ar & m_pPath->m_strPath; - else - { - tstring_t strEmpty; - ar & strEmpty; - } - } + void StoreInConfig(TConfig& rConfig, PCTSTR pszPropName) const; + bool ReadFromConfig(const TConfig& rConfig, PCTSTR pszPropName); - void StoreInConfig(chcore::TConfig& rConfig, PCTSTR pszPropName) const; - bool ReadFromConfig(const chcore::TConfig& rConfig, PCTSTR pszPropName); - - BOOST_SERIALIZATION_SPLIT_MEMBER(); - protected: void PrepareToWrite(); @@ -192,8 +173,8 @@ size_t GetCount() const; bool IsEmpty() const; - void StoreInConfig(chcore::TConfig& rConfig, PCTSTR pszPropName) const; - bool ReadFromConfig(const chcore::TConfig& rConfig, PCTSTR pszPropName); + void StoreInConfig(TConfig& rConfig, PCTSTR pszPropName) const; + bool ReadFromConfig(const TConfig& rConfig, PCTSTR pszPropName); private: #pragma warning(push) Index: src/libchcore/TString.cpp =================================================================== diff -u -re9926b6e83984d0f30bf2008b93874c7c483d95c -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TString.cpp (.../TString.cpp) (revision e9926b6e83984d0f30bf2008b93874c7c483d95c) +++ src/libchcore/TString.cpp (.../TString.cpp) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -87,7 +87,7 @@ { TInternalStringData* pStringData = TInternalStringData::Allocate(stNewSize); - size_t stDataToCopy = min(pStringData->m_stBufferSize - 1, m_stStringLength); + size_t stDataToCopy = std::min(pStringData->m_stBufferSize - 1, m_stStringLength); // copy as much data from the current buffer as possible wcsncpy_s(pStringData->GetData(), pStringData->m_stBufferSize, GetData(), stDataToCopy); @@ -358,7 +358,7 @@ if(tStart >= stCurrentLength) return TString(); - size_t stRealLength = min(tLen, stCurrentLength - tStart); + size_t stRealLength = std::min(tLen, stCurrentLength - tStart); TString strNew(m_pszStringData + tStart, stRealLength); @@ -437,7 +437,7 @@ } else { - size_t stRealLength = min(tLen, stCurrentLength - tStart); + size_t stRealLength = std::min(tLen, stCurrentLength - tStart); EnsureWritable(stRealLength + 1); wmemmove(m_pszStringData, m_pszStringData + tStart, stRealLength); @@ -473,7 +473,7 @@ EnsureWritable(stCurrentLength + 1); - size_t stCountToDelete = min(stCurrentLength - stIndex, stCount); + size_t stCountToDelete = std::min(stCurrentLength - stIndex, stCount); wmemmove(m_pszStringData + stIndex, m_pszStringData + stIndex + stCountToDelete, stCurrentLength - stCountToDelete); m_pszStringData[stCurrentLength - stCountToDelete] = _T('\0'); Index: src/libchcore/TString.h =================================================================== diff -u -re9926b6e83984d0f30bf2008b93874c7c483d95c -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TString.h (.../TString.h) (revision e9926b6e83984d0f30bf2008b93874c7c483d95c) +++ src/libchcore/TString.h (.../TString.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -24,7 +24,7 @@ #define __TSTRING_H__ #include "libchcore.h" -#include +#include BEGIN_CHCORE_NAMESPACE @@ -87,7 +87,7 @@ void SetStringLength(size_t stLength) { BOOST_ASSERT(stLength < m_stBufferSize); - m_stStringLength = min(stLength, m_stBufferSize - 1); + m_stStringLength = std::min(stLength, m_stBufferSize - 1); } private: @@ -214,24 +214,6 @@ bool IsEmpty() const; ///< Returns true if the TString is empty /**@}*/ - // Serialization - template - void load(Archive& ar, unsigned int /*uiVersion*/) - { - std::wstring wstrData; - ar & wstrData; - SetString(wstrData.c_str()); - } - - template - void save(Archive& ar, unsigned int /*uiVersion*/) const - { - std::wstring wstrData = m_pszStringData ? m_pszStringData : _T(""); - ar & wstrData; - } - - BOOST_SERIALIZATION_SPLIT_MEMBER(); - protected: void SetString(const wchar_t* pszStr); ///< Makes a copy of a given unicode TString and store it in internal TString buffer void SetString(const wchar_t* pszStart, size_t stCount); Index: src/libchcore/TTaskDefinition.h =================================================================== diff -u -r0cd863a6e51b221c4f7bf6e7b83ddfc43a5d433f -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TTaskDefinition.h (.../TTaskDefinition.h) (revision 0cd863a6e51b221c4f7bf6e7b83ddfc43a5d433f) +++ src/libchcore/TTaskDefinition.h (.../TTaskDefinition.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -29,6 +29,9 @@ BEGIN_CHCORE_NAMESPACE +class TReadBinarySerializer; +class TWriteBinarySerializer; + /////////////////////////////////////////////////////////////////////////// // TTaskDefinition @@ -45,17 +48,17 @@ TString GetTaskUniqueID() const; // Source paths - void AddSourcePath(const chcore::TSmartPath& tPath); - chcore::TSmartPath GetSourcePathAt(size_t stIndex) const; + void AddSourcePath(const TSmartPath& tPath); + TSmartPath GetSourcePathAt(size_t stIndex) const; size_t GetSourcePathCount() const; - void SetSourcePaths(const chcore::TPathContainer& rvPaths); - const chcore::TPathContainer& GetSourcePaths() const; + void SetSourcePaths(const TPathContainer& rvPaths); + const TPathContainer& GetSourcePaths() const; void ClearSourcePaths(); // Destination path - void SetDestinationPath(const chcore::TSmartPath& pathDestination); - chcore::TSmartPath GetDestinationPath() const; + void SetDestinationPath(const TSmartPath& pathDestination); + TSmartPath GetDestinationPath() const; // Operation type void SetOperationType(EOperationType eOperation); @@ -78,16 +81,16 @@ TString m_strTaskUniqueID; ///< Unique ID of the task that will process this request (generated automatically) // basic information - chcore::TPathContainer m_vSourcePaths; - chcore::TSmartPath m_pathDestinationPath; + TPathContainer m_vSourcePaths; + TSmartPath m_pathDestinationPath; TOperationPlan m_tOperationPlan; ///< Describes the operation along with sub-operations to be performed on the task input data // Task version unsigned long long m_ullTaskVersion; // Global task settings - chcore::TConfig m_tConfiguration; + TConfig m_tConfiguration; // Other info (volatile, not to be saved to xml) mutable bool m_bModified; ///< Some parameters has been modified and this object needs to be serialized again Index: src/libchcore/TTaskOperationPlan.h =================================================================== diff -u -r633a533cb6e741d44fe28aa56339e1d2709b1b27 -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/TTaskOperationPlan.h (.../TTaskOperationPlan.h) (revision 633a533cb6e741d44fe28aa56339e1d2709b1b27) +++ src/libchcore/TTaskOperationPlan.h (.../TTaskOperationPlan.h) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -24,11 +24,13 @@ #define __TTASKOPERATIONPLAN_H__ #include "libchcore.h" -#include #include "EOperationTypes.h" BEGIN_CHCORE_NAMESPACE +class TReadBinarySerializer; +class TWriteBinarySerializer; + enum ESubOperationType { eSubOperation_None, @@ -60,14 +62,9 @@ ESubOperationType GetSubOperationAt(size_t stIndex) const; double GetEstimatedTimeAt(size_t stIndex) const; - template - void load(Archive& ar, unsigned int /*uiVersion*/); + void Serialize(chcore::TReadBinarySerializer& rSerializer); + void Serialize(chcore::TWriteBinarySerializer& rSerializer) const; - template - void save(Archive& ar, unsigned int /*uiVersion*/) const; - - BOOST_SERIALIZATION_SPLIT_MEMBER(); - private: EOperationType m_eOperation; #pragma warning(push) @@ -78,20 +75,6 @@ #pragma warning(pop) }; -template -void TOperationPlan::load(Archive& ar, unsigned int /*uiVersion*/) -{ - EOperationType eOperation = eOperation_None; - ar >> eOperation; - SetOperationType(eOperation); -} - -template -void TOperationPlan::save(Archive& ar, unsigned int /*uiVersion*/) const -{ - ar << GetOperationType(); -} - END_CHCORE_NAMESPACE #endif Index: src/libchcore/libchcore.vc90.vcproj =================================================================== diff -u -rbe5d5dfa17e79a1db8e64ad2d2ed5faea30399cb -r5fd6beaad9f1eccb664b997d151acb59961e4827 --- src/libchcore/libchcore.vc90.vcproj (.../libchcore.vc90.vcproj) (revision be5d5dfa17e79a1db8e64ad2d2ed5faea30399cb) +++ src/libchcore/libchcore.vc90.vcproj (.../libchcore.vc90.vcproj) (revision 5fd6beaad9f1eccb664b997d151acb59961e4827) @@ -44,7 +44,7 @@ + + + +