Index: src/ch/FileInfo.h =================================================================== diff -u -N -rbd08c279240bac9e7902f8da6a9251e0252ec324 -r860b25a7b72cd40f83d810f7c72a5e2a76f88987 --- src/ch/FileInfo.h (.../FileInfo.h) (revision bd08c279240bac9e7902f8da6a9251e0252ec324) +++ src/ch/FileInfo.h (.../FileInfo.h) (revision 860b25a7b72cd40f83d810f7c72a5e2a76f88987) @@ -257,76 +257,95 @@ class CFileInfoArray { public: - CFileInfoArray(CClipboardArray& A_rClipboardArray) : - m_rClipboard(A_rClipboardArray) - { - } + CFileInfoArray(CClipboardArray& rClipboardArray); + ~CFileInfoArray(); + // Adds a new object info to this container void AddFileInfo(const CFileInfoPtr& spFileInfo); + /// Retrieves count of elements in this object size_t GetSize() const; + + /// Retrieves an element at the specified index CFileInfoPtr GetAt(size_t stIndex) const; + + /// Retrieves a copy of the element at a specified index CFileInfo GetCopyAt(size_t stIndex) const; - + + /// Removes all elements from this object void Clear(); - // store/restore + // specialized operations on contents of m_vFiles + /// Calculates the size of the first stCount file info objects + unsigned long long CalculatePartialSize(size_t stCount); + + /// Calculates the size of all file info objects inside this object + unsigned long long CalculateTotalSize(); + + /// Stores infos about elements in the archive template - void Store(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags) + void Store(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags); + + /// Restores info from the archive + template + void Load(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags); + +protected: + CClipboardArray& m_rClipboard; + std::vector m_vFiles; + mutable boost::shared_mutex m_lock; +}; + +template +void CFileInfoArray::Store(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags) +{ + size_t stCount = m_vFiles.size(); + ar << stCount; + for(std::vector::iterator iterFile = m_vFiles.begin(); iterFile != m_vFiles.end(); ++iterFile) { - size_t stCount = m_vFiles.size(); - ar << stCount; - for(std::vector::iterator iterFile = m_vFiles.begin(); iterFile != m_vFiles.end(); ++iterFile) + if(bOnlyFlags) { - if(bOnlyFlags) - { - uint_t uiFlags = (*iterFile)->GetFlags(); - ar << uiFlags; - } - else - ar << *(*iterFile); + uint_t uiFlags = (*iterFile)->GetFlags(); + ar << uiFlags; } + else + ar << *(*iterFile); } +} - template - void Load(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags) +template +void CFileInfoArray::Load(Archive& ar, unsigned int /*uiVersion*/, bool bOnlyFlags) +{ + size_t stCount; + ar >> stCount; + + if(!bOnlyFlags) { - size_t stCount; - ar >> stCount; + m_vFiles.clear(); + m_vFiles.reserve(stCount); + } + else if(stCount != m_vFiles.size()) + THROW(_T("Invalid count of flags received"), 0, 0, 0); - if(!bOnlyFlags) + CFileInfoPtr spFileInfo; + + uint_t uiFlags = 0; + for(size_t stIndex = 0; stIndex < stCount; stIndex++) + { + if(bOnlyFlags) { - m_vFiles.clear(); - m_vFiles.reserve(stCount); + CFileInfoPtr& spFileInfo = m_vFiles.at(stIndex); + ar >> uiFlags; + spFileInfo->SetFlags(uiFlags); } - 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++) + else { - if(bOnlyFlags) - { - CFileInfoPtr& spFileInfo = m_vFiles.at(stIndex); - ar >> uiFlags; - spFileInfo->SetFlags(uiFlags); - } - else - { - spFileInfo.reset(new CFileInfo); - spFileInfo->SetClipboard(&m_rClipboard); - ar >> *spFileInfo; - m_vFiles.push_back(spFileInfo); - } + spFileInfo.reset(new CFileInfo); + spFileInfo->SetClipboard(&m_rClipboard); + ar >> *spFileInfo; + m_vFiles.push_back(spFileInfo); } } +} -protected: - CClipboardArray& m_rClipboard; - std::vector m_vFiles; - mutable boost::shared_mutex m_lock; -}; - #endif