corelib/include/ebcl/inline/Filesystem.hh
Emmanuel BENOîT ee02f9c5c7 Filesystem - Path style abstraction
A class that carries information about a filesystem path's style: case
sensitivity, path separator and whether it supports drive letters.
2018-12-19 08:30:11 +01:00

254 lines
5.4 KiB
C++

/******************************************************************************/
/* FILESYSTEM ABSTRACTION - INLINE CODE ***************************************/
/******************************************************************************/
#ifndef _H_EBCL_INLINE_FILESYSTEM
#define _H_EBCL_INLINE_FILESYSTEM
#include <ebcl/Filesystem.hh>
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
: root_{ } , components_{ } , valid_{ true }
{ }
/*----------------------------------------------------------------------------*/
inline T_FSPath::T_FSPath(
T_FSPath const& other ) noexcept
: root_{ other.root_ } , components_{ other.components_ } ,
valid_{ other.valid_ }
{ }
inline T_FSPath& T_FSPath::operator =(
T_FSPath const& other ) noexcept
{
root_ = other.root_;
components_ = other.components_;
valid_ = other.valid_;
return *this;
}
/*----------------------------------------------------------------------------*/
inline T_FSPath::T_FSPath( T_FSPath&& other ) noexcept
: T_FSPath{ }
{
swap( other );
}
inline T_FSPath& T_FSPath::operator =(
T_FSPath&& other ) noexcept
{
root_ = T_String{ };
components_.free( );
valid_ = true;
return swap( other );
}
/*----------------------------------------------------------------------------*/
inline T_FSPath& T_FSPath::swap(
T_FSPath& other ) noexcept
{
using std::swap;
swap( root_ , other.root_ );
swap( components_ , other.components_ );
swap( valid_ , other.valid_ );
return *this;
}
inline M_DEFINE_SWAP( T_FSPath )
{
lhs.swap( rhs );
}
/*----------------------------------------------------------------------------*/
inline bool T_FSPath::isValid( ) const noexcept
{
return valid_;
}
inline T_String const& T_FSPath::root( ) const noexcept
{
return root_;
}
inline T_FSPath::T_Components const& T_FSPath::components( ) const noexcept
{
return components_;
}
inline bool T_FSPath::isRelative( ) const noexcept
{
return !root_;
}
inline bool T_FSPath::isAbsolute( ) const noexcept
{
return bool( root_ );
}
/*----------------------------------------------------------------------------*/
inline T_String T_FSPath::toString( ) const noexcept
{
T_StringBuilder sb;
appendTo( sb );
return T_String{ std::move( sb ) };
}
inline M_DEFINE_HASH( T_FSPath )
{
return item.computeHash( );
}
inline M_LSHIFT_OP( T_StringBuilder , T_FSPath const& )
{
value.appendTo( obj );
return obj;
}
/*----------------------------------------------------------------------------*/
inline bool T_FSPath::operator ==(
T_FSPath const& other ) const noexcept
{
return compareTo( other ) == 0;
}
inline bool T_FSPath::operator !=(
T_FSPath const& other ) const noexcept
{
return compareTo( other ) != 0;
}
inline bool T_FSPath::operator <(
T_FSPath const& other ) const noexcept
{
return compareTo( other ) < 0;
}
inline bool T_FSPath::operator <=(
T_FSPath const& other ) const noexcept
{
return compareTo( other ) <= 0;
}
inline bool T_FSPath::operator >(
T_FSPath const& other ) const noexcept
{
return compareTo( other ) > 0;
}
inline bool T_FSPath::operator >=(
T_FSPath const& other ) const noexcept
{
return compareTo( other ) >= 0;
}
/*----------------------------------------------------------------------------*/
inline bool T_FSPath::isChildOf(
T_FSPath const& other ) const noexcept
{
return other.isParentOf( *this );
}
inline bool T_FSPath::isUnder(
T_FSPath const& other ) const noexcept
{
return other.isAbove( *this );
}
} // namespace ebcl
#endif // _H_EBCL_INLINE_FILESYSTEM