corelib/include/ebcl/inline/Filesystem.hh

276 lines
6.1 KiB
C++
Raw Normal View History

2017-12-27 10:49:31 +01:00
/******************************************************************************/
/* FILESYSTEM ABSTRACTION - INLINE CODE ***************************************/
/******************************************************************************/
#ifndef _H_EBCL_INLINE_FILESYSTEM
#define _H_EBCL_INLINE_FILESYSTEM
#include <ebcl/Filesystem.hh>
namespace ebcl {
/*= T_FSPathStyle ============================================================*/
inline constexpr 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;
}
2018-12-23 18:17:55 +01:00
inline M_DEFINE_SWAP( T_FSPathStyle )
{
lhs.swap( rhs );
}
/*----------------------------------------------------------------------------*/
inline constexpr bool T_FSPathStyle::caseSensitive( ) const noexcept
{
return caseSensitive_;
}
inline constexpr T_FSPathStyle& T_FSPathStyle::caseSensitive( bool cs ) noexcept
{
caseSensitive_ = cs;
return *this;
}
inline constexpr bool T_FSPathStyle::hasDriveLetter( ) const noexcept
{
return hasDriveLetter_;
}
inline constexpr T_FSPathStyle& T_FSPathStyle::hasDriveLetter( bool hdl ) noexcept
{
hasDriveLetter_ = hdl;
return *this;
}
inline constexpr T_Flags< E_FSPathSeparator > T_FSPathStyle::pathSeparators( ) const noexcept
{
return pathSeparators_;
}
inline constexpr T_FSPathStyle& T_FSPathStyle::pathSeparator(
T_Flags< E_FSPathSeparator > ps ) noexcept
{
assert( ps );
pathSeparators_ = ps;
return *this;
}
/*----------------------------------------------------------------------------*/
inline constexpr bool T_FSPathStyle::isSeparator(
const T_Character chr ) const noexcept
{
return ( ( pathSeparators_ & E_FSPathSeparator::SLASH ) && chr == '/' )
|| ( ( pathSeparators_ & E_FSPathSeparator::SLASH ) && chr == '\\' );
}
/*----------------------------------------------------------------------------*/
inline constexpr T_FSPathStyle T_FSPathStyle::Unix( )
{
return T_FSPathStyle{ true , false ,
T_Flags< E_FSPathSeparator >{ E_FSPathSeparator::SLASH } };
}
inline constexpr T_FSPathStyle T_FSPathStyle::Windows( )
{
return T_FSPathStyle{ false , true ,
T_Flags< E_FSPathSeparator >{ E_FSPathSeparator::BACKSLASH } };
}
inline constexpr T_FSPathStyle T_FSPathStyle::System( )
{
#ifdef _WIN32
return T_FSPathStyle::Windows( );
#else
return T_FSPathStyle::Unix( );
#endif
}
2017-12-27 10:49:31 +01:00
/*= T_FSPath =================================================================*/
2018-12-23 18:17:55 +01:00
inline T_FSPath::T_FSPath( T_FSPathStyle style ) noexcept
: style_{ style } , root_{ } , components_{ } , valid_{ true }
2017-12-27 10:49:31 +01:00
{ }
/*----------------------------------------------------------------------------*/
inline T_FSPath::T_FSPath(
T_FSPath const& other ) noexcept
2018-12-23 18:17:55 +01:00
: style_{ other.style_ } , root_{ other.root_ } ,
components_{ other.components_ } , valid_{ other.valid_ }
2017-12-27 10:49:31 +01:00
{ }
inline T_FSPath& T_FSPath::operator =(
T_FSPath const& other ) noexcept
{
2018-12-23 18:17:55 +01:00
style_ = other.style_;
2017-12-27 10:49:31 +01:00
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_;
}
2018-12-23 18:17:55 +01:00
inline T_FSPathStyle const& T_FSPath::style( ) const noexcept
{
return style_;
}
2017-12-27 10:49:31 +01:00
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_ );
}
/*----------------------------------------------------------------------------*/
2018-12-23 18:17:55 +01:00
inline T_String T_FSPath::toString(
T_OptPathSeparator separator ) const noexcept
2017-12-27 10:49:31 +01:00
{
T_StringBuilder sb;
2018-12-23 18:17:55 +01:00
appendTo( sb , separator );
2017-12-27 10:49:31 +01:00
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