More progress on de-std::-ifying the code

This commit is contained in:
Emmanuel BENOîT 2017-11-04 09:17:31 +01:00
parent a28fc34394
commit 173bc86ea9
9 changed files with 92 additions and 81 deletions

View file

@ -42,7 +42,7 @@ DEMO = \
IMGUI_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(IMGUI)))) IMGUI_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(IMGUI))))
DEMO_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(DEMO)))) DEMO_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(DEMO))))
OBJS = $(IMGUI_OBJS) $(DEMO_OBJS) OBJS = $(IMGUI_OBJS) $(DEMO_OBJS)
LIBEBCL = $(OUTDIR)/libebcorelib.a LIBEBCL = $(OUTDIR)/ebcl/libebcorelib.a
PCH=externals.hh.gch PCH=externals.hh.gch
DEMO_DEPS = $(DEMO_OBJS:$(OUTDIR)/%.o=$(OUTDIR)/%.d) DEMO_DEPS = $(DEMO_OBJS:$(OUTDIR)/%.o=$(OUTDIR)/%.d)

View file

@ -122,14 +122,14 @@ void OPLoadVariable::execute(
/*= OPLoadInput ==============================================================*/ /*= OPLoadInput ==============================================================*/
OPLoadInput::OPLoadInput( OPLoadInput::OPLoadInput(
std::string const& input ) T_String const& input )
: T_Op( OP_LOAD_VARIABLE ) , input( input ) : T_Op( OP_LOAD_VARIABLE ) , input( input )
{ } { }
void OPLoadInput::execute( void OPLoadInput::execute(
T_Context& ctx ) const T_Context& ctx ) const
{ {
const auto i( Globals::Sync( ).inputPos( input.c_str( ) ) ); const auto i( Globals::Sync( ).inputPos( input ) );
ctx.opStack.add( Globals::Sync( ).inputs( )[ i ] ); ctx.opStack.add( Globals::Sync( ).inputs( )[ i ] );
} }

View file

@ -180,10 +180,10 @@ namespace cops {
struct OPLoadInput : public T_Op struct OPLoadInput : public T_Op
{ {
explicit OPLoadInput( explicit OPLoadInput(
std::string const& input ); T_String const& input );
void execute( void execute(
T_Context& ctx ) const override; T_Context& ctx ) const override;
std::string input; T_String input;
}; };
struct OPStoreVariable : public T_Op struct OPStoreVariable : public T_Op

View file

@ -6,7 +6,7 @@ DEBUG = n
OPTIMIZE = y OPTIMIZE = y
BUILD_TESTS = n BUILD_TESTS = n
OUTDIR = ../output OUTDIR = ../output/ebcl
export BUILD_STATIC_LIB BUILD_DYNAMIC_LIB DEBUG OPTIMIZE BUILD_TESTS export BUILD_STATIC_LIB BUILD_DYNAMIC_LIB DEBUG OPTIMIZE BUILD_TESTS
export OUTDIR export OUTDIR

View file

@ -43,28 +43,29 @@ void T_FilesWatcher::check( )
// Handle events from inotify // Handle events from inotify
inotify_event ie; inotify_event ie;
while ( read( fd , &ie , sizeof( ie ) ) == sizeof( ie ) ) { while ( read( fd , &ie , sizeof( ie ) ) == sizeof( ie ) ) {
printf( "inotify wd %d / evt %x\n" , ie.wd , ie.mask ); fflush( stdout ); // printf( "inotify wd %d / evt %x\n" , ie.wd , ie.mask ); fflush( stdout );
if ( ( ie.mask & ( IN_CLOSE_WRITE | IN_DELETE_SELF ) ) == 0 ) { if ( ( ie.mask & ( IN_CLOSE_WRITE | IN_DELETE_SELF ) ) == 0 ) {
printf( " -> skipping this event\n" ); // printf( " -> skipping this event\n" );
continue; continue;
} }
const auto pos( inotify_.find( ie.wd ) ); T_String const* name( inotify_.get( ie.wd ) );
if ( pos == inotify_.end( ) ) { if ( !name ) {
printf( " -> no matching file\n" ); fflush( stdout ); // printf( " -> no matching file\n" ); fflush( stdout );
continue; continue;
} }
printf( " -> file '%s'\n" , pos->second.c_str( ) ); printf( " -> file '%s'\n" , name->toOSString( ).data( ) );
auto& entry( fileWatchers_.find( pos->second )->second ); auto* entry( fileWatchers_.get( *name ) );
entry.trigger( ); assert( entry );
entry->trigger( );
if ( ( ie.mask & IN_DELETE_SELF ) != 0 ) { if ( ( ie.mask & IN_DELETE_SELF ) != 0 ) {
printf( " -> deleted, added as missing\n" ); fflush( stdout ); //printf( " -> deleted, added as missing\n" ); fflush( stdout );
inotify_rm_watch( fd , entry.wd ); inotify_rm_watch( fd , entry->wd );
missing_.push_back( pos->second ); missing_.add( *name );
entry.wd = -2; inotify_.remove( entry->wd );
inotify_.erase( entry.wd ); entry->wd = -2;
} }
} }
@ -72,15 +73,16 @@ void T_FilesWatcher::check( )
for ( auto it = missing_.begin( ) ; it < missing_.end( ) ; ++it ) { for ( auto it = missing_.begin( ) ; it < missing_.end( ) ; ++it ) {
auto const& path( *it ); auto const& path( *it );
//printf( "Checking missing file '%s'\n" , path.c_str( ) ); fflush( stdout ); //printf( "Checking missing file '%s'\n" , path.c_str( ) ); fflush( stdout );
const auto p( fileWatchers_.find( path ) ); auto* const p( fileWatchers_.get( path ) );
//printf( " -> found? %c\n" , p != fileWatchers_.end( ) ? 'Y' : 'N' ); //printf( " -> found? %c\n" , p != fileWatchers_.end( ) ? 'Y' : 'N' );
assert( p != fileWatchers_.end( ) ); assert( p );
//printf( " -> wd = %d\n" , p->second.wd ); //printf( " -> wd = %d\n" , p->second.wd );
assert( p->second.wd < 0 ); assert( p->wd < 0 );
auto& we( p->second ); auto& we( *p );
const auto nwd( inotify_add_watch( fd , path.c_str( ) , const auto nwd( inotify_add_watch( fd ,
IN_CLOSE_WRITE | IN_DELETE_SELF ) ); (char*) path.toOSString( ).data( ) ,
IN_CLOSE_WRITE | IN_DELETE_SELF ) );
//printf( " -> inotify add watch %d\n" , nwd ); fflush( stdout ); //printf( " -> inotify add watch %d\n" , nwd ); fflush( stdout );
if ( nwd < 0 ) { if ( nwd < 0 ) {
//printf( " -> still missing\n" ); fflush( stdout ); //printf( " -> still missing\n" ); fflush( stdout );
@ -96,8 +98,9 @@ void T_FilesWatcher::check( )
// Update cache // Update cache
we.wd = nwd; we.wd = nwd;
missing_.erase( it ); inotify_.add( nwd , path );
inotify_.emplace( nwd , path ); missing_.remove( it.pos( ) );
it --;
} }
} }
@ -114,55 +117,61 @@ void T_FilesWatcher::T_File_::trigger( )
} }
void T_FilesWatcher::watchFile( void T_FilesWatcher::watchFile(
__rd__ std::string const& path , T_String const& path ,
__rd__ T_WatchedFiles* const watcher ) T_WatchedFiles* const watcher )
{ {
//printf( "creating watch on '%s' for watcher %p\n" , path.c_str( ) , watcher ); fflush( stdout ); //printf( "creating watch on '%s' for watcher %p\n" , path.c_str( ) , watcher ); fflush( stdout );
auto const exFilePos( fileWatchers_.find( path ) ); auto* const exFilePos( fileWatchers_.get( path ) );
if ( exFilePos != fileWatchers_.end( ) ) { if ( exFilePos ) {
//printf( " -> existing\n" ); fflush( stdout ); //printf( " -> existing\n" ); fflush( stdout );
auto& wl( exFilePos->second.watchers ); auto& wl( exFilePos->watchers );
if ( !Contains( wl , watcher ) ) { if ( !wl.contains( watcher ) ) {
wl.push_back( watcher ); wl.add( watcher );
} }
} else { } else {
T_File_ f; T_File_ f;
f.wd = inotify_add_watch( fd , path.c_str( ) , f.wd = inotify_add_watch( fd , (char*) path.toOSString( ).data( ) ,
IN_CLOSE_WRITE | IN_DELETE_SELF ); IN_CLOSE_WRITE | IN_DELETE_SELF );
//printf( " -> inotify wd %d\n" , f.wd ); fflush( stdout ); //printf( " -> inotify wd %d\n" , f.wd ); fflush( stdout );
if ( f.wd == -1 ) { if ( f.wd == -1 ) {
missing_.push_back( path ); missing_.add( path );
//printf( " -> missing\n" ); fflush( stdout ); //printf( " -> missing\n" ); fflush( stdout );
} else { } else {
inotify_.emplace( f.wd , path ); inotify_.add( f.wd , path );
//printf( " -> found\n" ); fflush( stdout ); //printf( " -> found\n" ); fflush( stdout );
} }
f.watchers.push_back( watcher ); f.watchers.add( watcher );
fileWatchers_.emplace( path , std::move( f ) ); fileWatchers_.add( path , std::move( f ) );
} }
} }
void T_FilesWatcher::unwatchAll( void T_FilesWatcher::unwatchAll(
__rd__ T_WatchedFiles* const watcher ) T_WatchedFiles* const watcher )
{ {
for ( auto& entry : fileWatchers_ ) { for ( auto i = 0u ; i < fileWatchers_.size( ) ; ) {
auto& wl( entry.second.watchers ); auto const& path( fileWatchers_.keys( )[ i ] );
const auto pos( find( wl , watcher ) ); auto& fw( *fileWatchers_.get( path ) );
if ( pos == wl.end( ) ) { auto& wl( fw.watchers );
const auto pos( wl.indexOf( watcher ) );
if ( pos == -1 ) {
i ++;
continue; continue;
} }
wl.erase( pos );
wl.remove( pos );
if ( wl.empty( ) ) { if ( wl.empty( ) ) {
const auto wd( entry.second.wd ); const auto wd( fw.wd );
if ( wd < 0 ) { if ( wd < 0 ) {
auto const pos( find( missing_ , entry.first ) ); auto const pos( missing_.indexOf( path ) );
assert( pos != missing_.end( ) ); assert( pos != -1 );
missing_.erase( pos ); missing_.remove( pos );
} else { } else {
inotify_rm_watch( fd , wd ); inotify_rm_watch( fd , wd );
inotify_.erase( wd ); inotify_.remove( wd );
} }
fileWatchers_.erase( entry.first ); fileWatchers_.remove( path );
} else {
i ++;
} }
} }
} }
@ -181,18 +190,18 @@ T_WatchedFiles::T_WatchedFiles( T_WatchedFiles&& other ) noexcept
} }
T_WatchedFiles::T_WatchedFiles( T_WatchedFiles::T_WatchedFiles(
__rw__ T_FilesWatcher& watcher , T_FilesWatcher& watcher ,
__rd__ const F_OnFileChanges callback ) const F_OnFileChanges callback )
: watcher( &watcher ) , callback( callback ) , triggered( false ) : watcher( &watcher ) , callback( callback ) , triggered( false )
{ {
watcher.watched_.push_back( this ); watcher.watched_.add( this );
} }
T_WatchedFiles::~T_WatchedFiles( ) T_WatchedFiles::~T_WatchedFiles( )
{ {
if ( watcher ) { if ( watcher ) {
watcher->unwatchAll( this ); watcher->unwatchAll( this );
watcher->watched_.erase( find( watcher->watched_ , this ) ); watcher->watched_.remove( watcher->watched_.indexOf( this ) );
} }
} }
@ -204,7 +213,7 @@ void T_WatchedFiles::clear( )
} }
bool T_WatchedFiles::watch( bool T_WatchedFiles::watch(
__rd__ std::string const& file ) T_String const& file )
{ {
if ( !watcher ) { if ( !watcher ) {
return false; return false;

View file

@ -32,19 +32,19 @@ struct T_FilesWatcher
private: private:
struct T_File_ { struct T_File_ {
int wd; int wd;
std::vector< T_WatchedFiles* > watchers; T_Array< T_WatchedFiles* > watchers;
void trigger( ); void trigger( );
}; };
int fd; int fd;
std::map< std::string , T_File_ > fileWatchers_; T_KeyValueTable< T_String , T_File_ > fileWatchers_;
std::map< int , std::string > inotify_; T_KeyValueTable< int , T_String > inotify_;
std::vector< std::string > missing_; T_Array< T_String > missing_;
std::vector< T_WatchedFiles* > watched_; T_Array< T_WatchedFiles* > watched_;
void watchFile( __rd__ std::string const& path , void watchFile( T_String const& path ,
__rd__ T_WatchedFiles* const watcher ); T_WatchedFiles* const watcher );
void unwatchAll( __rd__ T_WatchedFiles* const watcher ); void unwatchAll( T_WatchedFiles* const watcher );
}; };
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -58,17 +58,17 @@ struct T_WatchedFiles
T_WatchedFiles( T_WatchedFiles&& ) noexcept; T_WatchedFiles( T_WatchedFiles&& ) noexcept;
T_WatchedFiles( T_WatchedFiles(
__rw__ T_FilesWatcher& watcher , T_FilesWatcher& watcher ,
__rd__ const F_OnFileChanges callback ); const F_OnFileChanges callback );
~T_WatchedFiles( ); ~T_WatchedFiles( );
void clear( ); void clear( );
bool watch( __rd__ std::string const& file ); bool watch( T_String const& file );
private: private:
T_FilesWatcher* watcher; T_FilesWatcher* watcher;
const F_OnFileChanges callback; const F_OnFileChanges callback;
bool triggered; bool triggered;
}; };
using P_WatchedFiles = std::unique_ptr< T_WatchedFiles >; using P_WatchedFiles = T_OwnPtr< T_WatchedFiles >;

View file

@ -823,7 +823,9 @@ void T_ShaderManager::initProgram(
} ); } );
for ( auto entry : code.files ) { for ( auto entry : code.files ) {
if ( entry.second ) { if ( entry.second ) {
program.watch->watch( "shaders/" + entry.first ); ebcl::T_StringBuilder sb( "shaders/" );
sb << entry.first.c_str( );
program.watch->watch( std::move( sb ) );
} else { } else {
missing_[ entry.first ].insert( name ); missing_[ entry.first ].insert( name );
} }

18
sync.cc
View file

@ -253,7 +253,7 @@ void T_SyncManager::checkCurveFile( )
printf( "CURVE INIT\n" ); printf( "CURVE INIT\n" );
bool missing; bool missing;
if ( loadCurves_( missing ) || !missing ) { if ( loadCurves_( missing ) || !missing ) {
watcher_ = std::make_unique< T_WatchedFiles >( watcher_ = NewOwned< T_WatchedFiles >(
Globals::Watcher( ) , Globals::Watcher( ) ,
[this] { curvesChanged_( ); } ); [this] { curvesChanged_( ); } );
watcher_->watch( "curves.json" ); watcher_->watch( "curves.json" );
@ -278,7 +278,7 @@ void T_SyncManager::curvesChanged_( )
{ {
bool missing; bool missing;
if ( !loadCurves_( missing ) && missing ) { if ( !loadCurves_( missing ) && missing ) {
watcher_.reset( ); watcher_.clear( );
} }
} }
@ -381,7 +381,7 @@ bool T_SyncManager::loadCurvesData_(
bool T_SyncManager::loadSegmentData_( bool T_SyncManager::loadSegmentData_(
T_SyncSegment& segment , T_SyncSegment& segment ,
std::string const& curve , T_String const& curve ,
T_JSONObject const& sd ) T_JSONObject const& sd )
{ {
auto const& sType( jsonGet< std::string >( sd , "type" ) ); auto const& sType( jsonGet< std::string >( sd , "type" ) );
@ -389,7 +389,7 @@ bool T_SyncManager::loadSegmentData_(
const auto p( SegmentTypes_.find( sType ) ); const auto p( SegmentTypes_.find( sType ) );
if ( p == SegmentTypes_.end( ) ) { if ( p == SegmentTypes_.end( ) ) {
printf( "Curves data: curve '%s': invalid segment type '%s'\n" , printf( "Curves data: curve '%s': invalid segment type '%s'\n" ,
curve.c_str( ) , sType.c_str( ) ); curve.toOSString( ).data( ) , sType.c_str( ) );
return false; return false;
} }
segment.type = p->second; segment.type = p->second;
@ -399,19 +399,19 @@ bool T_SyncManager::loadSegmentData_(
if ( vList.size( ) < 2 ) { if ( vList.size( ) < 2 ) {
printf( "Curves data: curve '%s': segment doesn't have enough values\n" , printf( "Curves data: curve '%s': segment doesn't have enough values\n" ,
curve.c_str( ) ); curve.toOSString( ).data( ) );
return false; return false;
} }
if ( vList.size( ) != dList.size( ) + 1 ) { if ( vList.size( ) != dList.size( ) + 1 ) {
printf( "Curves data: curve '%s': segment values / durations count mismatch\n" , printf( "Curves data: curve '%s': segment values / durations count mismatch\n" ,
curve.c_str( ) ); curve.toOSString( ).data( ) );
return false; return false;
} }
for ( auto const& vv : vList ) { for ( auto const& vv : vList ) {
if ( !vv.is< double >( ) ) { if ( !vv.is< double >( ) ) {
printf( "Curves data: curve '%s': non-numeric entry in segment values\n" , printf( "Curves data: curve '%s': non-numeric entry in segment values\n" ,
curve.c_str( ) ); curve.toOSString( ).data( ) );
return false; return false;
} }
segment.values.add( vv.get< double >( ) ); segment.values.add( vv.get< double >( ) );
@ -420,14 +420,14 @@ bool T_SyncManager::loadSegmentData_(
for ( auto const& dv : dList ) { for ( auto const& dv : dList ) {
if ( !dv.is< double >( ) ) { if ( !dv.is< double >( ) ) {
printf( "Curves data: curve '%s': non-numeric entry in segment durations\n" , printf( "Curves data: curve '%s': non-numeric entry in segment durations\n" ,
curve.c_str( ) ); curve.toOSString( ).data( ) );
return false; return false;
} }
const double dvn( dv.get< double >( ) ); const double dvn( dv.get< double >( ) );
if ( fmod( dvn , 1.0 ) != 0.0 || dvn <= 0 ) { if ( fmod( dvn , 1.0 ) != 0.0 || dvn <= 0 ) {
printf( "Curves data: curve '%s': invalid segment duration %f\n" , printf( "Curves data: curve '%s': invalid segment duration %f\n" ,
curve.c_str( ) , dvn ); curve.toOSString( ).data( ) , dvn );
return false; return false;
} }
segment.durations.add( dvn ); segment.durations.add( dvn );

View file

@ -184,9 +184,9 @@ struct T_SyncManager
void clearInputs( ) void clearInputs( )
{ values_.clear( ); } { values_.clear( ); }
bool addInput( std::string const& name , bool addInput( T_String const& name ,
const float initial = 0.f ) noexcept const float initial = 0.f ) noexcept
{ return values_.addValue( name.c_str( ) , initial ); } { return values_.addValue( name , initial ); }
uint32_t inputPos( T_String const& name ) const noexcept uint32_t inputPos( T_String const& name ) const noexcept
{ return values_.indexOf( name ); } { return values_.indexOf( name ); }
@ -208,7 +208,7 @@ struct T_SyncManager
picojson::value const& root ); picojson::value const& root );
bool loadSegmentData_( bool loadSegmentData_(
T_SyncSegment& segment , T_SyncSegment& segment ,
std::string const& curve , T_String const& curve ,
T_JSONObject const& sd ); T_JSONObject const& sd );
// --------------------------------------------------------------------- // ---------------------------------------------------------------------