Project path manager added

This commit is contained in:
Emmanuel BENOîT 2017-11-24 14:13:39 +01:00
parent d846fac3f6
commit 97478cf1e8
3 changed files with 96 additions and 0 deletions

View file

@ -27,6 +27,7 @@ COMMON = \
common.cc \
c-camera.cc \
c-filewatcher.cc \
c-project.cc \
c-utilities.cc \
c-undo.cc \
\

57
c-project.cc Normal file
View file

@ -0,0 +1,57 @@
#include "externals.hh"
#include "c-project.hh"
/*= A_ProjectPathListener ====================================================*/
A_ProjectPathListener::~A_ProjectPathListener( ) {}
/*= T_Project ================================================================*/
void T_Project::setBasePath(
T_String const& path ) noexcept
{
if ( !path || path[ path.length( ) - 1 ] != '/' ) {
setBasePathInternal( path );
} else {
setBasePathInternal( path.substr( 0 , path.length( ) - 1 ) );
}
}
void T_Project::setBasePathInternal(
T_String path ) noexcept
{
if ( ( path && basePath_ == path )
|| ( !path && basePath_ == "." ) ) {
return;
}
if ( !path ) {
basePath_ = T_String::Pooled( "." );
} else {
basePath_ = std::move( path );
}
const auto n{ listeners_.size( ) };
for ( auto i = 0u ; i < n ; i ++ ) {
listeners_[ i ]->projectPathChanged( );
}
}
/*----------------------------------------------------------------------------*/
T_String T_Project::pathOf(
T_String const& file ) const noexcept
{
T_StringBuilder sb;
sb << basePath_ << '/' << file;
return std::move( sb );
}
T_String T_Project::pathOf(
char const* file ) const noexcept
{
T_StringBuilder sb;
sb << basePath_ << '/' << file;
return std::move( sb );
}

38
c-project.hh Normal file
View file

@ -0,0 +1,38 @@
#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
#include <ebcl/Sets.hh>
class A_ProjectPathListener
{
public:
virtual ~A_ProjectPathListener( ) = 0;
virtual void projectPathChanged( ) noexcept = 0;
};
struct T_Project
{
void setBasePath( T_String const& path ) noexcept;
T_String const& basePath( ) const noexcept
{ return basePath_; }
T_String pathOf( T_String const& file ) const noexcept;
T_String pathOf( char const* file ) const noexcept;
void addListener( A_ProjectPathListener* listener ) noexcept
{ listeners_.add( listener ); }
void removeListener( A_ProjectPathListener* listener ) noexcept
{ listeners_.remove( listener ); }
private:
T_String basePath_{ T_String::Pooled( "." ) };
ebcl::T_Set< A_ProjectPathListener* > listeners_{
ebcl::UseTag< ebcl::ArrayBacked< 16 > >( )
};
void setBasePathInternal( T_String path ) noexcept;
};