From 46664170cd0e41a6dc684ed0243e0a7822c4e7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 4 Nov 2017 09:29:06 +0100 Subject: [PATCH] More std::string removal --- odbg.cc | 65 +++++++++++++++++++++++++-------------------------------- odbg.hh | 29 ++++++++++++------------- 2 files changed, 43 insertions(+), 51 deletions(-) diff --git a/odbg.cc b/odbg.cc index 9e63f11..99e16b0 100644 --- a/odbg.cc +++ b/odbg.cc @@ -4,7 +4,7 @@ namespace { - const std::string NormalOutput_ = "(DISABLED)"; + char const NormalOutput_[] = "(DISABLED)"; } @@ -87,9 +87,9 @@ void T_OutputDebugger::makeUI( ) } void T_OutputDebugger::registerTexture( - __rw__ T_Texture& texture , - __rd__ const E_ODbgMode mode , - __rd__ std::string const& name ) + T_Texture& texture , + const E_ODbgMode mode , + T_String const& name ) { texture.debugIndex_ = registerTexture( texture.id_ , texture.levels_ , mode , name ); @@ -128,16 +128,18 @@ void T_OutputDebugger::debugOutput( ) /*----------------------------------------------------------------------------*/ void T_OutputDebugger::registerSubmode( - __rd__ const E_ODbgMode mode , - __rd__ std::string const& name , - __rd__ std::string const& shader , - __rd__ F_SubmodeSetup setup ) + const E_ODbgMode mode , + T_String const& name , + T_String const& shader , + F_SubmodeSetup setup ) { assert( mode != E_ODbgMode::__COUNT__ ); + ebcl::T_StringBuilder sb( "debug/" ); + sb << shader << ".glsl" << '\0'; submodes_[ int( mode ) ].add( T_Submode_{ name , Globals::Shaders( ).pipeline({ - "fullscreen.v.glsl" , "debug/" + shader + ".glsl" }) , + "fullscreen.v.glsl" , sb.data( ) }) , setup } ); } @@ -145,29 +147,24 @@ void T_OutputDebugger::registerSubmode( void T_OutputDebugger::initSubmodeCombo( ) { for ( auto sm = 0u ; sm < int( E_ODbgMode::__COUNT__ ) ; sm ++ ) { - size_t reqSize = 1; + imguiStrings.clear( ); for ( auto const& m : submodes_[ sm ] ) { - reqSize += 1 + m.name.length( ); + imguiStrings << m.name << '\0'; } - assert( reqSize > 1 ); + imguiStrings << '\0'; - smCombo_[ sm ] = new char[ reqSize ]; - char* ptr = smCombo_[ sm ]; - for ( auto const& m : submodes_[ sm ] ) { - strcpy( ptr , m.name.c_str( ) ); - ptr += 1 + m.name.length( ); - } - *ptr = 0; + smCombo_[ sm ] = new char[ imguiStrings.size( ) ]; + memcpy( smCombo_[ sm ] , imguiStrings.data( ) , imguiStrings.size( ) ); } } /*----------------------------------------------------------------------------*/ int32_t T_OutputDebugger::registerTexture( - __rd__ const GLuint id , - __rd__ const uint32_t levels , - __rd__ const E_ODbgMode mode , - __rd__ std::string const& name ) + const GLuint id , + const uint32_t levels , + const E_ODbgMode mode , + T_String const& name ) { assert( mode != E_ODbgMode::__COUNT__ ); assert( id != 0 ); @@ -186,7 +183,7 @@ int32_t T_OutputDebugger::registerTexture( } void T_OutputDebugger::unregisterTexture( - __rd__ const uint32_t index ) + const uint32_t index ) { assert( index < outputs_.size( ) ); assert( outputs_[ index ].id != 0 ); @@ -210,30 +207,24 @@ void T_OutputDebugger::clearSelectorItems( ) void T_OutputDebugger::makeSelectorItems( ) { - size_t requiredSize = 2 + NormalOutput_.length( ); + imguiStrings.clear( ); + imguiStrings << NormalOutput_ << '\0'; + uint32_t nrLeft = nRegistered_, i = 0; selectorMapping_.add( -1 ); while ( nrLeft ) { assert( i < outputs_.size( ) ); if ( outputs_[ i ].id != 0 ) { - requiredSize += 1 + outputs_[ i ].name.length( ); + imguiStrings << outputs_[ i ].name << '\0'; selectorMapping_.add( i ); nrLeft --; } i ++; } + imguiStrings << '\0'; assert( selectorMapping_.size( ) == 1 + nRegistered_ ); - assert( requiredSize >= 2 + NormalOutput_.length( ) + 2 * nRegistered_ ); - selectorItems_ = new char[ requiredSize ]; - char* ptr = selectorItems_; - strcpy( ptr , NormalOutput_.c_str( ) ); - ptr += NormalOutput_.length( ) + 1; - for ( i = 1 ; i < selectorMapping_.size( ) ; i ++ ) { - auto const& name( outputs_[ selectorMapping_[ i ] ].name ); - strcpy( ptr , name.c_str( ) ); - ptr += name.length( ) + 1; - } - *ptr = 0; + selectorItems_ = new char[ imguiStrings.size( ) ]; + memcpy( selectorItems_ , imguiStrings.data( ) , imguiStrings.size( ) ); } diff --git a/odbg.hh b/odbg.hh index eb79cd1..b95374e 100644 --- a/odbg.hh +++ b/odbg.hh @@ -22,9 +22,9 @@ struct T_OutputDebugger ~T_OutputDebugger( ); void registerTexture( - __rw__ T_Texture& texture , - __rd__ const E_ODbgMode mode , - __rd__ std::string const& name ); + T_Texture& texture , + const E_ODbgMode mode , + T_String const& name ); bool& uiEnabled( ) { return enabled_; } @@ -40,7 +40,7 @@ struct T_OutputDebugger GLuint id; uint32_t levels; E_ODbgMode mode; - std::string name; + T_String name; // int submode; int lod; @@ -49,7 +49,7 @@ struct T_OutputDebugger using F_SubmodeSetup = std::function< void( GLuint ) >; struct T_Submode_ { - std::string name; + T_String name; T_ShaderPipeline pipeline; F_SubmodeSetup setup; }; @@ -59,25 +59,26 @@ struct T_OutputDebugger T_Array< T_Texture_ > outputs_; T_Array< T_Submode_ > submodes_[ int( E_ODbgMode::__COUNT__ ) ]; char* smCombo_[ int( E_ODbgMode::__COUNT__ ) ]; + ebcl::T_StringBuilder imguiStrings; int32_t selected_ = -1; char* selectorItems_; T_Array< int32_t > selectorMapping_; void registerSubmode( - __rd__ const E_ODbgMode mode , - __rd__ std::string const& name , - __rd__ std::string const& shader , - __rd__ F_SubmodeSetup setup = F_SubmodeSetup( ) ); + const E_ODbgMode mode , + T_String const& name , + T_String const& shader , + F_SubmodeSetup setup = F_SubmodeSetup( ) ); void initSubmodeCombo( ); int32_t registerTexture( - __rd__ const GLuint id , - __rd__ const uint32_t levels , - __rd__ const E_ODbgMode mode , - __rd__ std::string const& name ); + const GLuint id , + const uint32_t levels , + const E_ODbgMode mode , + T_String const& name ); void unregisterTexture( - __rd__ const uint32_t index ); + const uint32_t index ); void makeSelectorItems( ); void clearSelectorItems( );