diff --git a/include/ebcl/Filesystem.hh b/include/ebcl/Filesystem.hh index 8c33398..f614a38 100644 --- a/include/ebcl/Filesystem.hh +++ b/include/ebcl/Filesystem.hh @@ -5,13 +5,68 @@ #ifndef _H_EBCL_FILESYSTEM #define _H_EBCL_FILESYSTEM -#include #include +#include namespace ebcl { /*= FILESYSTEM PATH ==========================================================*/ +// Supported filesystem path separators +enum class E_FSPathSeparator +{ + SLASH , BACKSLASH +}; + +// The style of a filesystem path. +class T_FSPathStyle +{ + private: + bool caseSensitive_; + bool hasDriveLetter_; + T_Flags< E_FSPathSeparator > pathSeparators_; + + public: + //---------------------------------------------------------------------- + // Constructors and assignment operators + + T_FSPathStyle( ) = delete; + + // Initialise the filesystem path style, specifying: + // - whether it is case-sensitive, + // - whether is can use a drive letter as its root, + // - which separators it supports + T_FSPathStyle( bool cs , bool hdl , T_Flags< E_FSPathSeparator > ps ) noexcept; + + // Default copy/move constructors/assignement operators + T_FSPathStyle( T_FSPathStyle const& ) noexcept = default; + T_FSPathStyle& operator =( T_FSPathStyle const& ) noexcept = default; + T_FSPathStyle( T_FSPathStyle&& ) noexcept = default; + T_FSPathStyle& operator =( T_FSPathStyle&& ) noexcept = default; + + T_FSPathStyle& swap( T_FSPathStyle& other ) noexcept; + + //---------------------------------------------------------------------- + // Accessors + + bool caseSensitive( ) const noexcept; + T_FSPathStyle& caseSensitive( bool cs ) noexcept; + + bool hasDriveLetter( ) const noexcept; + T_FSPathStyle& hasDriveLetter( bool hdl ) noexcept; + + T_Flags< E_FSPathSeparator > pathSeparators( ) const noexcept; + T_FSPathStyle& pathSeparator( T_Flags< E_FSPathSeparator > ps ) noexcept; + + //---------------------------------------------------------------------- + // Pre-initialised styles + + static T_FSPathStyle Unix( ); + static T_FSPathStyle Windows( ); + static T_FSPathStyle System( ); +}; + + class T_FSPath { public: diff --git a/include/ebcl/inline/Filesystem.hh b/include/ebcl/inline/Filesystem.hh index 00af515..b1de402 100644 --- a/include/ebcl/inline/Filesystem.hh +++ b/include/ebcl/inline/Filesystem.hh @@ -9,6 +9,90 @@ namespace ebcl { +/*= T_FSPathStyle ============================================================*/ + +inline T_FSPathStyle::T_FSPathStyle( + bool cs , + bool hdl , + T_Flags< E_FSPathSeparator > ps ) noexcept + : caseSensitive_{ cs } , hasDriveLetter_{ hdl } , pathSeparators_{ ps } +{ + assert( ps ); +} + +/*----------------------------------------------------------------------------*/ + +inline T_FSPathStyle& T_FSPathStyle::swap( + T_FSPathStyle& other ) noexcept +{ + using std::swap; + swap( caseSensitive_ , other.caseSensitive_ ); + swap( hasDriveLetter_ , other.hasDriveLetter_ ); + swap( pathSeparators_ , other.pathSeparators_ ); + return *this; +} + +/*----------------------------------------------------------------------------*/ + +inline bool T_FSPathStyle::caseSensitive( ) const noexcept +{ + return caseSensitive_; +} + +inline T_FSPathStyle& T_FSPathStyle::caseSensitive( bool cs ) noexcept +{ + caseSensitive_ = cs; + return *this; +} + +inline bool T_FSPathStyle::hasDriveLetter( ) const noexcept +{ + return hasDriveLetter_; +} + +inline T_FSPathStyle& T_FSPathStyle::hasDriveLetter( bool hdl ) noexcept +{ + hasDriveLetter_ = hdl; + return *this; +} + +inline T_Flags< E_FSPathSeparator > T_FSPathStyle::pathSeparators( ) const noexcept +{ + return pathSeparators_; +} + +inline T_FSPathStyle& T_FSPathStyle::pathSeparator( + T_Flags< E_FSPathSeparator > ps ) noexcept +{ + assert( ps ); + pathSeparators_ = ps; + return *this; +} + +/*----------------------------------------------------------------------------*/ + +inline T_FSPathStyle T_FSPathStyle::Unix( ) +{ + return T_FSPathStyle{ true , false , + T_Flags< E_FSPathSeparator >{ E_FSPathSeparator::SLASH } }; +} + +inline T_FSPathStyle T_FSPathStyle::Windows( ) +{ + return T_FSPathStyle{ false , true , + T_Flags< E_FSPathSeparator >{ E_FSPathSeparator::BACKSLASH } }; +} + +inline T_FSPathStyle T_FSPathStyle::System( ) +{ +#ifdef _WIN32 + return T_FSPathStyle::Windows( ); +#else + return T_FSPathStyle::Unix( ); +#endif +} + + /*= T_FSPath =================================================================*/ inline T_FSPath::T_FSPath( ) noexcept