From f1aef3cdcc5c83fc3cc99659646e393c3b366e6d Mon Sep 17 00:00:00 2001 From: Michal Simon Date: Wed, 3 Jun 2020 21:32:08 +0200 Subject: [PATCH] [XrdCl] Apply PIMPL idiom to FileSystemUtils. --- src/XrdCl/XrdClFileSystemUtils.cc | 59 +++++++++++++++++++++++++++++++ src/XrdCl/XrdClFileSystemUtils.hh | 25 +++++++------ 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/XrdCl/XrdClFileSystemUtils.cc b/src/XrdCl/XrdClFileSystemUtils.cc index 8cc21078060..c6a63be7913 100644 --- a/src/XrdCl/XrdClFileSystemUtils.cc +++ b/src/XrdCl/XrdClFileSystemUtils.cc @@ -34,6 +34,65 @@ namespace XrdCl { + //---------------------------------------------------------------------------- + // The data holder implementation + //---------------------------------------------------------------------------- + struct FileSystemUtils::SpaceInfoImpl + { + SpaceInfoImpl( uint64_t total, uint64_t free, uint64_t used, + uint64_t largestChunk ): + pTotal( total ), + pFree( free ), + pUsed( used ), + pLargestChunk( largestChunk ) + { + } + + uint64_t pTotal; + uint64_t pFree; + uint64_t pUsed; + uint64_t pLargestChunk; + }; + + //---------------------------------------------------------------------------- + // Constructor + //---------------------------------------------------------------------------- + FileSystemUtils::SpaceInfo::SpaceInfo( uint64_t total, uint64_t free, uint64_t used, + uint64_t largestChunk ): + pImpl( new SpaceInfoImpl( total, free, used, largestChunk ) ) + { + } + + //--------------------------------------------------------------------------- + // Destructor (needs to be here due to the unique_ptr guarding PIMPL) + //--------------------------------------------------------------------------- + FileSystemUtils::SpaceInfo::~SpaceInfo() + { + } + + //---------------------------------------------------------------------------- + // Amount of total space in MB + //---------------------------------------------------------------------------- + uint64_t FileSystemUtils::SpaceInfo::GetTotal() const { return pImpl->pTotal; } + + //---------------------------------------------------------------------------- + // Amount of free space in MB + //---------------------------------------------------------------------------- + uint64_t FileSystemUtils::SpaceInfo::GetFree() const { return pImpl->pFree; } + + //---------------------------------------------------------------------------- + // Amount of used space in MB + //---------------------------------------------------------------------------- + uint64_t FileSystemUtils::SpaceInfo::GetUsed() const { return pImpl->pUsed; } + + //---------------------------------------------------------------------------- + // Largest single chunk of free space + //---------------------------------------------------------------------------- + uint64_t FileSystemUtils::SpaceInfo::GetLargestFreeChunk() const + { + return pImpl->pLargestChunk; + } + //---------------------------------------------------------------------------- // Recursively get space information for given path //---------------------------------------------------------------------------- diff --git a/src/XrdCl/XrdClFileSystemUtils.hh b/src/XrdCl/XrdClFileSystemUtils.hh index 3b5fe14bf5f..e59d60c4cfa 100644 --- a/src/XrdCl/XrdClFileSystemUtils.hh +++ b/src/XrdCl/XrdClFileSystemUtils.hh @@ -29,6 +29,7 @@ #include #include +#include namespace XrdCl { @@ -40,6 +41,11 @@ namespace XrdCl //---------------------------------------------------------------------------- class FileSystemUtils { + //------------------------------------------------------------------------ + // Forward declaration for PIMPL + //------------------------------------------------------------------------ + struct SpaceInfoImpl; + public: //------------------------------------------------------------------------ //! Container for space information @@ -48,35 +54,32 @@ namespace XrdCl { public: SpaceInfo( uint64_t total, uint64_t free, uint64_t used, - uint64_t largestChunk ): - pTotal( total ), pFree( free ), pUsed( used ), - pLargestChunk( largestChunk ) { } + uint64_t largestChunk ); + + ~SpaceInfo(); //-------------------------------------------------------------------- //! Amount of total space in MB //-------------------------------------------------------------------- - uint64_t GetTotal() const { return pTotal; } + uint64_t GetTotal() const; //-------------------------------------------------------------------- //! Amount of free space in MB //-------------------------------------------------------------------- - uint64_t GetFree() const { return pFree; } + uint64_t GetFree() const; //-------------------------------------------------------------------- //! Amount of used space in MB //-------------------------------------------------------------------- - uint64_t GetUsed() const { return pUsed; } + uint64_t GetUsed() const; //-------------------------------------------------------------------- //! Largest single chunk of free space //-------------------------------------------------------------------- - uint64_t GetLargestFreeChunk() const { return pLargestChunk; } + uint64_t GetLargestFreeChunk() const; private: - uint64_t pTotal; - uint64_t pFree; - uint64_t pUsed; - uint64_t pLargestChunk; + std::unique_ptr pImpl; }; //------------------------------------------------------------------------