Skip to content

Commit

Permalink
[XrdCl] Apply PIMPL idiom to FileSystemUtils.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal committed Jun 3, 2020
1 parent 1c27a86 commit f1aef3c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 11 deletions.
59 changes: 59 additions & 0 deletions src/XrdCl/XrdClFileSystemUtils.cc
Expand Up @@ -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
//----------------------------------------------------------------------------
Expand Down
25 changes: 14 additions & 11 deletions src/XrdCl/XrdClFileSystemUtils.hh
Expand Up @@ -29,6 +29,7 @@

#include <string>
#include <stdint.h>
#include <memory>

namespace XrdCl
{
Expand All @@ -40,6 +41,11 @@ namespace XrdCl
//----------------------------------------------------------------------------
class FileSystemUtils
{
//------------------------------------------------------------------------
// Forward declaration for PIMPL
//------------------------------------------------------------------------
struct SpaceInfoImpl;

public:
//------------------------------------------------------------------------
//! Container for space information
Expand All @@ -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<SpaceInfoImpl> pImpl;
};

//------------------------------------------------------------------------
Expand Down

0 comments on commit f1aef3c

Please sign in to comment.