demotool/c-project.cc

63 lines
1.3 KiB
C++
Raw Normal View History

2017-11-24 14:13:39 +01:00
#include "externals.hh"
#include "c-project.hh"
/*= A_ProjectPathListener ====================================================*/
A_ProjectPathListener::~A_ProjectPathListener( ) {}
/*= T_Project ================================================================*/
void T_Project::setBasePath(
2017-12-27 14:15:49 +01:00
T_FSPath const& path ) noexcept
2017-11-24 14:13:39 +01:00
{
2017-12-27 14:15:49 +01:00
assert( path.isValid( ) );
if ( basePath_ == path ) {
2017-11-24 14:13:39 +01:00
return;
}
2017-12-27 14:15:49 +01:00
if ( path.isRelative( ) ) {
basePath_ = ( Filesystem::Cwd( ) + path ).canonical( );
2017-11-24 14:13:39 +01:00
} else {
2017-12-27 14:15:49 +01:00
basePath_ = path.canonical( );
2017-11-24 14:13:39 +01:00
}
const auto n{ listeners_.size( ) };
for ( auto i = 0u ; i < n ; i ++ ) {
listeners_[ i ]->projectPathChanged( );
}
}
/*----------------------------------------------------------------------------*/
2017-12-27 14:53:19 +01:00
T_FSPath T_Project::pathOf(
T_FSPath const& file ) const noexcept
2017-11-24 14:13:39 +01:00
{
if ( file.isAbsolute( ) ) {
if ( file.canonical( ).isUnder( basePath_ ) ) {
return file;
}
return basePath_;
}
2017-12-27 14:53:19 +01:00
return ( basePath_ + file ).canonical( );
2017-11-24 14:13:39 +01:00
}
2017-12-27 14:53:19 +01:00
T_FSPath T_Project::pathOf(
2017-11-24 14:13:39 +01:00
char const* file ) const noexcept
{
2017-12-27 14:53:19 +01:00
return pathOf( T_String{ file } );
}
T_String T_Project::strPathOf(
T_FSPath const& file ) const noexcept
{
return pathOf( file ).toString( );
}
T_String T_Project::strPathOf(
char const* file ) const noexcept
{
return strPathOf( T_String{ file } );
2017-11-24 14:13:39 +01:00
}