Index: src/libchcore/TFileInfoArray.cpp =================================================================== diff -u -N -re92d7e2b63df1305b23aa04132c45ad8747dc22c -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 --- src/libchcore/TFileInfoArray.cpp (.../TFileInfoArray.cpp) (revision e92d7e2b63df1305b23aa04132c45ad8747dc22c) +++ src/libchcore/TFileInfoArray.cpp (.../TFileInfoArray.cpp) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) @@ -26,158 +26,157 @@ #include "ISerializerContainer.h" #include -BEGIN_CHCORE_NAMESPACE - -/////////////////////////////////////////////////////////////////////// -// Array -TFileInfoArray::TFileInfoArray() : - m_bComplete(false), - m_oidLastObjectID(0) +namespace chcore { -} + /////////////////////////////////////////////////////////////////////// + // Array + TFileInfoArray::TFileInfoArray() : + m_bComplete(false), + m_oidLastObjectID(0) + { + } -TFileInfoArray::~TFileInfoArray() -{ -} + TFileInfoArray::~TFileInfoArray() + { + } -void TFileInfoArray::AddFileInfo(const TFileInfoPtr& spFileInfo) -{ - boost::unique_lock lock(m_lock); - spFileInfo->SetObjectID(++m_oidLastObjectID); - m_vFiles.push_back(spFileInfo); -} + void TFileInfoArray::AddFileInfo(const TFileInfoPtr& spFileInfo) + { + boost::unique_lock lock(m_lock); + spFileInfo->SetObjectID(++m_oidLastObjectID); + m_vFiles.push_back(spFileInfo); + } -file_count_t TFileInfoArray::GetSize() const -{ - boost::shared_lock lock(m_lock); - return boost::numeric_cast(m_vFiles.size()); -} + file_count_t TFileInfoArray::GetSize() const + { + boost::shared_lock lock(m_lock); + return boost::numeric_cast(m_vFiles.size()); + } -TFileInfoPtr TFileInfoArray::GetAt(file_count_t fcIndex) const -{ - boost::shared_lock lock(m_lock); - - if(fcIndex >= m_vFiles.size()) - THROW(_T("Out of bounds"), 0, 0, 0); - - return m_vFiles.at(boost::numeric_cast(fcIndex)); -} + TFileInfoPtr TFileInfoArray::GetAt(file_count_t fcIndex) const + { + boost::shared_lock lock(m_lock); -TFileInfo TFileInfoArray::GetCopyAt(file_count_t fcIndex) const -{ - boost::shared_lock lock(m_lock); - - if(fcIndex >= m_vFiles.size()) - THROW(_T("Out of bounds"), 0, 0, 0); - const TFileInfoPtr& spInfo = m_vFiles.at(boost::numeric_cast(fcIndex)); - if(!spInfo) - THROW(_T("Invalid pointer"), 0, 0, 0); + if (fcIndex >= m_vFiles.size()) + THROW(_T("Out of bounds"), 0, 0, 0); - return *spInfo; -} + return m_vFiles.at(boost::numeric_cast(fcIndex)); + } -void TFileInfoArray::Clear() -{ - boost::unique_lock lock(m_lock); - m_bComplete = false; - BOOST_FOREACH(const TFileInfoPtr& spFileInfo, m_vFiles) + TFileInfo TFileInfoArray::GetCopyAt(file_count_t fcIndex) const { - m_setRemovedObjects.Add(spFileInfo->GetObjectID()); - } - m_vFiles.clear(); -} + boost::shared_lock lock(m_lock); -unsigned long long TFileInfoArray::CalculateTotalSize() const -{ - unsigned long long ullSize = 0; + if (fcIndex >= m_vFiles.size()) + THROW(_T("Out of bounds"), 0, 0, 0); + const TFileInfoPtr& spInfo = m_vFiles.at(boost::numeric_cast(fcIndex)); + if (!spInfo) + THROW(_T("Invalid pointer"), 0, 0, 0); - boost::shared_lock lock(m_lock); - BOOST_FOREACH(const TFileInfoPtr& spFileInfo, m_vFiles) + return *spInfo; + } + + void TFileInfoArray::Clear() { - ullSize += spFileInfo->GetLength64(); + boost::unique_lock lock(m_lock); + m_bComplete = false; + BOOST_FOREACH(const TFileInfoPtr& spFileInfo, m_vFiles) + { + m_setRemovedObjects.Add(spFileInfo->GetObjectID()); + } + m_vFiles.clear(); } - return ullSize; -} + unsigned long long TFileInfoArray::CalculateTotalSize() const + { + unsigned long long ullSize = 0; -void TFileInfoArray::SetComplete(bool bComplete) -{ - boost::unique_lock lock(m_lock); - m_bComplete = bComplete; -} + boost::shared_lock lock(m_lock); + BOOST_FOREACH(const TFileInfoPtr& spFileInfo, m_vFiles) + { + ullSize += spFileInfo->GetLength64(); + } -bool TFileInfoArray::IsComplete() const -{ - boost::shared_lock lock(m_lock); - return m_bComplete; -} + return ullSize; + } -unsigned long long TFileInfoArray::CalculatePartialSize(file_count_t fcCount) -{ - unsigned long long ullSize = 0; + void TFileInfoArray::SetComplete(bool bComplete) + { + boost::unique_lock lock(m_lock); + m_bComplete = bComplete; + } - boost::shared_lock lock(m_lock); - if(fcCount > m_vFiles.size()) - THROW(_T("Invalid argument"), 0, 0, 0); - - for(std::vector::iterator iter = m_vFiles.begin(); iter != m_vFiles.begin() + boost::numeric_cast(fcCount); ++iter) + bool TFileInfoArray::IsComplete() const { - ullSize += (*iter)->GetLength64(); + boost::shared_lock lock(m_lock); + return m_bComplete; } - return ullSize; -} + unsigned long long TFileInfoArray::CalculatePartialSize(file_count_t fcCount) + { + unsigned long long ullSize = 0; -void TFileInfoArray::Store(const ISerializerContainerPtr& spContainer) const -{ - boost::shared_lock lock(m_lock); + boost::shared_lock lock(m_lock); + if (fcCount > m_vFiles.size()) + THROW(_T("Invalid argument"), 0, 0, 0); - InitColumns(spContainer); + for (std::vector::iterator iter = m_vFiles.begin(); iter != m_vFiles.begin() + boost::numeric_cast(fcCount); ++iter) + { + ullSize += (*iter)->GetLength64(); + } - // store only if there is a complete collection of items inside - // (this container is used in the directory scanning process. There is no - // point storing only partially scanned data in the serializer as we - // can't use this data after loading serialized data (dir scan will have - // to scan again)). - if(m_bComplete) + return ullSize; + } + + void TFileInfoArray::Store(const ISerializerContainerPtr& spContainer) const { - spContainer->DeleteRows(m_setRemovedObjects); - m_setRemovedObjects.Clear(); + boost::shared_lock lock(m_lock); - BOOST_FOREACH(const TFileInfoPtr& spFileInfo, m_vFiles) + InitColumns(spContainer); + + // store only if there is a complete collection of items inside + // (this container is used in the directory scanning process. There is no + // point storing only partially scanned data in the serializer as we + // can't use this data after loading serialized data (dir scan will have + // to scan again)). + if (m_bComplete) { - spFileInfo->Store(spContainer); + spContainer->DeleteRows(m_setRemovedObjects); + m_setRemovedObjects.Clear(); + + BOOST_FOREACH(const TFileInfoPtr& spFileInfo, m_vFiles) + { + spFileInfo->Store(spContainer); + } } } -} -void TFileInfoArray::Load(const ISerializerContainerPtr& spContainer, const TBasePathDataContainerPtr& spBasePaths) -{ - InitColumns(spContainer); - - std::vector vEntries; - ISerializerRowReaderPtr spRowReader = spContainer->GetRowReader(); - while(spRowReader->Next()) + void TFileInfoArray::Load(const ISerializerContainerPtr& spContainer, const TBasePathDataContainerPtr& spBasePaths) { - TFileInfoPtr spFileInfo(new TFileInfo); - spFileInfo->Load(spRowReader, spBasePaths); + InitColumns(spContainer); - vEntries.push_back(spFileInfo); + std::vector vEntries; + ISerializerRowReaderPtr spRowReader = spContainer->GetRowReader(); + while (spRowReader->Next()) + { + TFileInfoPtr spFileInfo(new TFileInfo); + spFileInfo->Load(spRowReader, spBasePaths); - m_oidLastObjectID = std::max(m_oidLastObjectID, spFileInfo->GetObjectID()); - } + vEntries.push_back(spFileInfo); - boost::unique_lock lock(m_lock); - m_vFiles = std::move(vEntries); - m_bComplete = !m_vFiles.empty(); // we're marking empty/non-empty based on scanned file count; this is due to the - // fact, that no scanned files are stored in DB unless scanning is complete; -} + m_oidLastObjectID = std::max(m_oidLastObjectID, spFileInfo->GetObjectID()); + } -void TFileInfoArray::InitColumns(const ISerializerContainerPtr& spContainer) const -{ - IColumnsDefinition& rColumns = spContainer->GetColumnsDefinition(); - if(rColumns.IsEmpty()) - TFileInfo::InitColumns(rColumns); -} + boost::unique_lock lock(m_lock); + m_vFiles = std::move(vEntries); + m_bComplete = !m_vFiles.empty(); // we're marking empty/non-empty based on scanned file count; this is due to the + // fact, that no scanned files are stored in DB unless scanning is complete; + } -END_CHCORE_NAMESPACE + void TFileInfoArray::InitColumns(const ISerializerContainerPtr& spContainer) const + { + IColumnsDefinition& rColumns = spContainer->GetColumnsDefinition(); + if (rColumns.IsEmpty()) + TFileInfo::InitColumns(rColumns); + } +}