diff --git a/alib2abstraction/src/registry/CastRegistry.cpp b/alib2abstraction/src/registry/CastRegistry.cpp index 07ae0efc882403a5188f684e0251689981d04e20..774df447676e7eed9b4b6346b369ddacf255f829 100644 --- a/alib2abstraction/src/registry/CastRegistry.cpp +++ b/alib2abstraction/src/registry/CastRegistry.cpp @@ -16,6 +16,17 @@ ext::map < ext::pair < std::string, std::string >, std::unique_ptr < CastRegistr return casts; } +void CastRegistry::unregisterCast ( const std::string & target, const std::string & param ) { + if ( getEntries ( ).erase ( ext::tie ( target, param ) ) == 0u ) + throw std::invalid_argument ( "Entry from " + param + " to " + target + " not registered." ); +} + +void CastRegistry::registerCast ( std::string target, std::string param, std::unique_ptr < Entry > entry ) { + auto iter = getEntries ( ).insert ( std::make_pair ( ext::make_pair ( std::move ( target ), std::move ( param ) ), std::move ( entry ) ) ); + if ( ! iter.second ) + throw std::invalid_argument ( "Entry from " + iter.first->first.second + " to " + iter.first->first.first + " already registered." ); +} + std::shared_ptr < abstraction::OperationAbstraction > CastRegistry::getAbstraction ( const std::string & target, const std::string & param ) { auto entry = getEntries ( ).end ( ); for ( auto iter = getEntries ( ).begin ( ); iter != getEntries ( ).end ( ); ++ iter ) diff --git a/alib2abstraction/src/registry/CastRegistry.hpp b/alib2abstraction/src/registry/CastRegistry.hpp index 2a421c10c825f5587f5d4e02a54b23d43666f9f9..11655e85f358ca06b7485fa87fe114dcde13370e 100644 --- a/alib2abstraction/src/registry/CastRegistry.hpp +++ b/alib2abstraction/src/registry/CastRegistry.hpp @@ -64,10 +64,7 @@ private: static ext::map < ext::pair < std::string, std::string >, std::unique_ptr < Entry > > & getEntries ( ); public: - static void unregisterCast ( const std::string & target, const std::string & param ) { - if ( getEntries ( ).erase ( ext::tie ( target, param ) ) == 0u ) - throw std::invalid_argument ( "Entry from " + param + " to " + target + " not registered." ); - } + static void unregisterCast ( const std::string & target, const std::string & param ); template < class TargetType, class ParamType > static void unregisterCast ( ) { @@ -77,11 +74,11 @@ public: unregisterCast ( target, param ); } + static void registerCast ( std::string target, std::string param, std::unique_ptr < Entry > entry ); + template < class TargetType, class ParamType > static void registerCast ( std::string target, std::string param, bool isExplicit = false ) { - auto iter = getEntries ( ).insert ( std::make_pair ( ext::make_pair ( std::move ( target ), std::move ( param ) ), std::unique_ptr < Entry > ( new DefaultEntryImpl < TargetType, ParamType > ( isExplicit ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry from " + iter.first->first.second + " to " + iter.first->first.first + " already registered." ); + registerCast ( std::move ( target ), std::move ( param ), std::unique_ptr < Entry > ( new DefaultEntryImpl < TargetType, ParamType > ( isExplicit ) ) ); } template < class TargetType, class ParamType > @@ -94,9 +91,7 @@ public: template < class TargetType, class ParamType > static void registerCastAlgorithm ( std::string target, std::string param, TargetType ( * callback ) ( const ParamType & ), bool isExplicit = false ) { - auto iter = getEntries ( ).insert ( std::make_pair ( ext::make_pair ( std::move ( target ), std::move ( param ) ), std::unique_ptr < Entry > ( new AlgorithmEntryImpl < TargetType, const ParamType & > ( callback, isExplicit ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry from " + iter.first->first.second + " to " + iter.first->first.first + " already registered." ); + registerCast ( std::move ( target ), std::move ( param ), std::unique_ptr < Entry > ( new AlgorithmEntryImpl < TargetType, const ParamType & > ( callback, isExplicit ) ) ); } template < class TargetType, class ParamType > @@ -109,9 +104,7 @@ public: template < class TargetType, class ParamType > static void registerCastAlgorithm ( std::string target, std::string param, TargetType ( * callback ) ( ParamType ), bool isExplicit = false ) { - auto iter = getEntries ( ).insert ( std::make_pair ( ext::make_pair ( std::move ( target ), std::move ( param ) ), std::unique_ptr < Entry > ( new AlgorithmEntryImpl < TargetType, ParamType > ( callback, isExplicit ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry from " + iter.first->first.second + " to " + iter.first->first.first + " already registered." ); + registerCast ( std::move ( target ), std::move ( param ), std::unique_ptr < Entry > ( new AlgorithmEntryImpl < TargetType, ParamType > ( callback, isExplicit ) ) ); } template < class TargetType, class ParamType > diff --git a/alib2abstraction/src/registry/ContainerRegistry.cpp b/alib2abstraction/src/registry/ContainerRegistry.cpp index 5dcbc02f8de8d86a8c0813ee1e73dbce4e3a9a93..0c481d1257472bab70a973a715ad07a15197fa5b 100644 --- a/alib2abstraction/src/registry/ContainerRegistry.cpp +++ b/alib2abstraction/src/registry/ContainerRegistry.cpp @@ -16,6 +16,31 @@ ext::map < std::string, ext::list < ext::pair < std::string, std::unique_ptr < C return containerGroups; } +void ContainerRegistry::unregisterSet ( const std::string & param ) { + std::string container = "Set"; + + auto & group = getEntries ( ) [ container ]; + auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry ) { + return entry.first == param; + } ); + if ( iter == group.end ( ) ) + throw std::invalid_argument ( "Callback for " + param + " in contaier " + container + " not registered." ); + group.erase ( iter ); +} + +void ContainerRegistry::registerSet ( std::string param, std::unique_ptr < Entry > entry ) { + std::string container = "Set"; + + auto & group = getEntries ( ) [ container ]; + auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const ext::pair < std::string, std::unique_ptr < Entry > > & elem ) { + return elem.first == param; + } ); + if ( iter != group.end ( ) ) + throw std::invalid_argument ( "Callback for " + param + " in contaier " + container + " already registered." ); + + group.insert ( group.end ( ), ext::make_pair ( std::move ( param ), std::move ( entry ) ) ); +} + bool ContainerRegistry::hasAbstraction ( const std::string & container ) { return getEntries ( ).contains ( container ); } diff --git a/alib2abstraction/src/registry/ContainerRegistry.hpp b/alib2abstraction/src/registry/ContainerRegistry.hpp index cd336aee97c89b65b2ffcba1fb7ba79eb93a7613..55509370338e53aa9e627b2a335d21814975bb95 100644 --- a/alib2abstraction/src/registry/ContainerRegistry.hpp +++ b/alib2abstraction/src/registry/ContainerRegistry.hpp @@ -40,17 +40,7 @@ private: static ext::map < std::string, ext::list < ext::pair < std::string, std::unique_ptr < Entry > > > > & getEntries ( ); public: - static void unregisterSet ( const std::string & param ) { - std::string container = "Set"; - - auto & group = getEntries ( ) [ container ]; - auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry ) { - return entry.first == param; - } ); - if ( iter == group.end ( ) ) - throw std::invalid_argument ( "Callback for " + param + " in contaier " + container + " not registered." ); - group.erase ( iter ); - } + static void unregisterSet ( const std::string & param ); template < class ParamTypes > static void unregisterSet ( ) { @@ -58,16 +48,11 @@ public: unregisterSet ( param ); } + static void registerSet ( std::string param, std::unique_ptr < Entry > entry ); + template < class ParamTypes > static void registerSet ( std::string param ) { - std::string container = "Set"; - - auto & group = getEntries ( ) [ container ]; - for ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry : group ) - if ( entry.first == param ) - throw std::invalid_argument ( "Callback for " + param + " in contaier " + container + " already registered." ); - - group.insert ( group.end ( ), ext::make_pair ( std::move ( param ), std::make_unique < SetEntryImpl < ParamTypes > > ( ) ) ); + registerSet ( std::move ( param ), std::make_unique < SetEntryImpl < ParamTypes > > ( ) ); } template < class ParamTypes > diff --git a/alib2abstraction/src/registry/ImmediateRegistry.cpp b/alib2abstraction/src/registry/ImmediateRegistry.cpp index ad26da2e80b2283e0dd4ef41614e66df3a39ca27..0915015deb1278e92b7dd6e29c3d21633edb12d2 100644 --- a/alib2abstraction/src/registry/ImmediateRegistry.cpp +++ b/alib2abstraction/src/registry/ImmediateRegistry.cpp @@ -14,6 +14,17 @@ ext::map < std::string, std::unique_ptr < ImmediateRegistry::Entry > > & Immedia return fileWriters; } +void ImmediateRegistry::unregisterImmediate ( const std::string & result ) { + if ( getEntries ( ).erase ( result ) == 0u ) + throw std::invalid_argument ( "Entry " + result + " not registered." ); +} + +void ImmediateRegistry::registerImmediate ( std::string result, std::unique_ptr < Entry > entry ) { + auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( result ), std::move ( entry ) ) ); + if ( ! iter.second ) + throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); +} + std::shared_ptr < abstraction::OperationAbstraction > ImmediateRegistry::getAbstraction ( const std::string & result, std::string value ) { auto res = getEntries ( ).find ( result ); if ( res == getEntries ( ).end ( ) ) diff --git a/alib2abstraction/src/registry/ImmediateRegistry.hpp b/alib2abstraction/src/registry/ImmediateRegistry.hpp index 68b4cc662dc54a19de8936759418832d499ec1d4..35fd25efe8ccdea3d969aac0a0bf1363f864a23b 100644 --- a/alib2abstraction/src/registry/ImmediateRegistry.hpp +++ b/alib2abstraction/src/registry/ImmediateRegistry.hpp @@ -39,10 +39,7 @@ private: static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ); public: - static void unregisterImmediate ( const std::string & result ) { - if ( getEntries ( ).erase ( result ) == 0u ) - throw std::invalid_argument ( "Entry " + result + " not registered." ); - } + static void unregisterImmediate ( const std::string & result ); template < class ResultType > static void unregisterImmediate ( ) { @@ -50,11 +47,11 @@ public: unregisterImmediate ( result ); } + static void registerImmediate ( std::string result, std::unique_ptr < Entry > entry ); + template < class ResultType > static void registerImmediate ( std::string result ) { - auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( result ), std::unique_ptr < Entry > ( new EntryImpl < ResultType > ( ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); + registerImmediate ( std::move ( result ), std::unique_ptr < Entry > ( new EntryImpl < ResultType > ( ) ) ); } template < class ResultType > diff --git a/alib2abstraction/src/registry/NormalizeRegistry.cpp b/alib2abstraction/src/registry/NormalizeRegistry.cpp index 99bc4a61ade4824e6fba6d08f570b48c9877974d..ab70b426833da30a569584c6bda5ca64d5b3d383 100644 --- a/alib2abstraction/src/registry/NormalizeRegistry.cpp +++ b/alib2abstraction/src/registry/NormalizeRegistry.cpp @@ -14,6 +14,20 @@ ext::map < std::string, std::list < std::unique_ptr < NormalizeRegistry::Entry > return entries; } +void NormalizeRegistry::unregisterNormalize ( const std::string & param, std::list < std::unique_ptr < Entry > >::const_iterator iter ) { + auto & entry = getEntries ( ) [ param ]; + + if ( ! ext::range_contains_iterator ( entry.begin ( ), entry.end ( ), iter ) ) + throw std::invalid_argument ( "Normalization entry not found in " + param + "." ); + + entry.erase ( iter ); +} + +std::list < std::unique_ptr < NormalizeRegistry::Entry > >::const_iterator NormalizeRegistry::registerNormalize ( std::string param, std::unique_ptr < Entry > entry ) { + auto & collection = getEntries ( ) [ std::move ( param ) ]; + return collection.insert ( collection.end ( ), std::move ( entry ) ); +} + std::shared_ptr < abstraction::OperationAbstraction > NormalizeRegistry::getAbstraction ( const std::string & param ) { auto res = getEntries ( ).find ( param ); if ( res == getEntries ( ).end ( ) || res->second.empty ( ) ) diff --git a/alib2abstraction/src/registry/NormalizeRegistry.hpp b/alib2abstraction/src/registry/NormalizeRegistry.hpp index 356da9ebdbed83a6e04c524ef8a26cd0cc323098..9706699e1b62314f60aa9c40024081627d580569 100644 --- a/alib2abstraction/src/registry/NormalizeRegistry.hpp +++ b/alib2abstraction/src/registry/NormalizeRegistry.hpp @@ -43,14 +43,7 @@ private: static ext::map < std::string, std::list < std::unique_ptr < Entry > > > & getEntries ( ); public: - static void unregisterNormalize ( const std::string & param, std::list < std::unique_ptr < Entry > >::const_iterator iter ) { - auto & entry = getEntries ( ) [ param ]; - - if ( ! ext::range_contains_iterator ( entry.begin ( ), entry.end ( ), iter ) ) - throw std::invalid_argument ( "Normalization entry not found in " + param + "." ); - - entry.erase ( iter ); - } + static void unregisterNormalize ( const std::string & param, std::list < std::unique_ptr < Entry > >::const_iterator iter ); template < class ParamType > static void unregisterNormalize ( std::list < std::unique_ptr < Entry > >::const_iterator iter ) { @@ -58,10 +51,11 @@ public: unregisterNormalize ( param, iter ); } + static std::list < std::unique_ptr < Entry > >::const_iterator registerNormalize ( std::string param, std::unique_ptr < Entry > entry ); + template < class ParamType > static std::list < std::unique_ptr < Entry > >::const_iterator registerNormalize ( std::string param ) { - auto & entry = getEntries ( ) [ std::move ( param ) ]; - return entry.insert ( entry.end ( ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ); + return registerNormalize ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ); } template < class ParamType > diff --git a/alib2abstraction/src/registry/ValuePrinterRegistry.cpp b/alib2abstraction/src/registry/ValuePrinterRegistry.cpp index 93868482cb1d5349598daf31c886041781c9d3ef..fced34393e5c1b016116e2a365c9a66937c8519a 100644 --- a/alib2abstraction/src/registry/ValuePrinterRegistry.cpp +++ b/alib2abstraction/src/registry/ValuePrinterRegistry.cpp @@ -22,6 +22,17 @@ std::shared_ptr < abstraction::OperationAbstraction > ValuePrinterRegistry::getA return res->second->getAbstraction ( os ); } +void ValuePrinterRegistry::unregisterValuePrinter ( const std::string & param ) { + if ( getEntries ( ).erase ( param ) == 0u ) + throw std::invalid_argument ( "Entry " + param + " not registered." ); +} + +void ValuePrinterRegistry::registerValuePrinter ( std::string param, std::unique_ptr < Entry > entry ) { + auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::move ( entry ) ) ); + if ( ! iter.second ) + throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); +} + template < > std::shared_ptr < abstraction::OperationAbstraction > ValuePrinterRegistry::EntryImpl < void >::getAbstraction ( std::ostream & os ) const { return std::make_shared < abstraction::ValuePrinterAbstraction < void > > ( os ); diff --git a/alib2abstraction/src/registry/ValuePrinterRegistry.hpp b/alib2abstraction/src/registry/ValuePrinterRegistry.hpp index 4eb5c7674bfee8b86b35beffa556b239b1c751fa..a37c2129bfcc1ff16054afe7c78a03a986c48498 100644 --- a/alib2abstraction/src/registry/ValuePrinterRegistry.hpp +++ b/alib2abstraction/src/registry/ValuePrinterRegistry.hpp @@ -39,10 +39,7 @@ private: static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ); public: - static void unregisterValuePrinter ( const std::string & param ) { - if ( getEntries ( ).erase ( param ) == 0u ) - throw std::invalid_argument ( "Entry " + param + " not registered." ); - } + static void unregisterValuePrinter ( const std::string & param ); template < class ParamType > static void unregisterValuePrinter ( ) { @@ -50,11 +47,11 @@ public: unregisterValuePrinter ( param ); } + static void registerValuePrinter ( std::string param, std::unique_ptr < Entry > entry ); + template < class ParamType > static void registerValuePrinter ( std::string param ) { - auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); + registerValuePrinter ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ); } template < class ParamType > diff --git a/alib2raw/src/registry/RawReaderRegistry.cpp b/alib2raw/src/registry/RawReaderRegistry.cpp index 804427355337ab1e18046f8cd64503cfd8912179..68e8e70b763137a663d42425bf3bf3bb4a1042a8 100644 --- a/alib2raw/src/registry/RawReaderRegistry.cpp +++ b/alib2raw/src/registry/RawReaderRegistry.cpp @@ -16,6 +16,17 @@ ext::map < std::string, std::unique_ptr < RawReaderRegistry::Entry > > & RawRead return readers; } +void RawReaderRegistry::unregisterRawReader ( const std::string & type ) { + if ( getEntries ( ).erase ( type ) == 0u ) + throw std::invalid_argument ( "Entry " + type + " not registered." ); +} + +void RawReaderRegistry::registerRawReader ( std::string type, std::unique_ptr < Entry > entry ) { + auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( type ), std::move ( entry ) ) ); + if ( ! iter.second ) + throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); +} + std::shared_ptr < abstraction::OperationAbstraction > RawReaderRegistry::getAbstraction ( const std::string & type ) { for ( const std::pair < const std::string, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { if ( ext::is_same_type ( entry.first, type ) ) diff --git a/alib2raw/src/registry/RawReaderRegistry.hpp b/alib2raw/src/registry/RawReaderRegistry.hpp index 23ca593a0b6ddf1d949aa1188deedf3ca3e19808..2dec588b0a7eb6c9d4978b94852b2bad1d086f96 100644 --- a/alib2raw/src/registry/RawReaderRegistry.hpp +++ b/alib2raw/src/registry/RawReaderRegistry.hpp @@ -37,10 +37,7 @@ private: static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ); public: - static void unregisterRawReader ( const std::string & type ) { - if ( getEntries ( ).erase ( type ) == 0u ) - throw std::invalid_argument ( "Entry " + type + " not registered." ); - } + static void unregisterRawReader ( const std::string & type ); template < class ReturnType > static void unregisterRawReader ( ) { @@ -48,11 +45,11 @@ public: unregisterRawReader ( type ); } + static void registerRawReader ( std::string type, std::unique_ptr < Entry > entry ); + template < class ReturnType > static void registerRawReader ( std::string type ) { - auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( type ), std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); + registerRawReader ( std::move ( type ), std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ); } template < class ReturnType > diff --git a/alib2raw/src/registry/RawWriterRegistry.cpp b/alib2raw/src/registry/RawWriterRegistry.cpp index 94eb942eb181b4b208e746a6810a63a25d9e313b..69144b48cedeff3af5be47b9076771dbda6e5b4b 100644 --- a/alib2raw/src/registry/RawWriterRegistry.cpp +++ b/alib2raw/src/registry/RawWriterRegistry.cpp @@ -14,6 +14,17 @@ ext::map < std::string, std::unique_ptr < RawWriterRegistry::Entry > > & RawWrit return writers; } +void RawWriterRegistry::unregisterRawWriter ( const std::string & param ) { + if ( getEntries ( ).erase ( param ) == 0u ) + throw std::invalid_argument ( "Entry " + param + " not registered." ); +} + +void RawWriterRegistry::registerRawWriter ( std::string param, std::unique_ptr < Entry > entry ) { + auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::move ( entry ) ) ); + if ( ! iter.second ) + throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); +} + std::shared_ptr < abstraction::OperationAbstraction > RawWriterRegistry::getAbstraction ( const std::string & param ) { auto type = getEntries ( ).find ( param ); if ( type == getEntries ( ).end ( ) ) diff --git a/alib2raw/src/registry/RawWriterRegistry.hpp b/alib2raw/src/registry/RawWriterRegistry.hpp index b782acc23f9a2e52b8d6c2c4056f08dd560014a5..2f8f71a90618a94dc4bddb76fd8db40a38d7e0ad 100644 --- a/alib2raw/src/registry/RawWriterRegistry.hpp +++ b/alib2raw/src/registry/RawWriterRegistry.hpp @@ -39,10 +39,7 @@ private: static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ); public: - static void unregisterRawWriter ( const std::string & param ) { - if ( getEntries ( ).erase ( param ) == 0u ) - throw std::invalid_argument ( "Entry " + param + " not registered." ); - } + static void unregisterRawWriter ( const std::string & param ); template < class ParamType > static void unregisterRawWriter ( ) { @@ -50,11 +47,11 @@ public: unregisterRawWriter ( param ); } + static void registerRawWriter ( std::string param, std::unique_ptr < Entry > entry ); + template < class ParamType > static void registerRawWriter ( std::string param ) { - auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); + registerRawWriter ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ); } template < class ParamType > diff --git a/alib2str/src/registry/StringReaderRegistry.cpp b/alib2str/src/registry/StringReaderRegistry.cpp index 4acfc5f4cbdc9ea4d823558c6d072f1a615c1630..e4ddef122df8d07b09d929ca7c336cf5274142ec 100644 --- a/alib2str/src/registry/StringReaderRegistry.cpp +++ b/alib2str/src/registry/StringReaderRegistry.cpp @@ -14,6 +14,21 @@ ext::map < std::string, ext::list < std::pair < std::function < bool ( std::istr return readers; } +void StringReaderRegistry::unregisterStringReader ( const std::string & group, ext::list < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < StringReaderRegistry::Entry > > >::const_iterator iter ) { + auto & entry = getEntries ( ) [ group ]; + if ( ! ext::range_contains_iterator ( entry.begin ( ), entry.end ( ), iter ) ) + throw std::invalid_argument ( "Entry not found in " + group + "." ); + + entry.erase ( iter ); + if ( entry.empty ( ) ) + getEntries ( ).erase ( group ); +} + +ext::list < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < StringReaderRegistry::Entry > > >::const_iterator StringReaderRegistry::registerStringReader ( std::string group, std::function < bool ( std::istream & ) > first, std::unique_ptr < Entry > entry ) { + auto & collection = getEntries ( ) [ std::move ( group ) ]; + return collection.insert ( collection.end ( ), std::make_pair ( std::move ( first ), std::move ( entry ) ) ); +} + std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::getAbstraction ( const std::string & group, const std::string & str ) { std::stringstream ss ( str ); while ( ext::isspace ( ss.peek ( ) ) ) diff --git a/alib2str/src/registry/StringReaderRegistry.hpp b/alib2str/src/registry/StringReaderRegistry.hpp index 47df792176c9e956f3a9c6e9d1a4dfa91e57b289..4bef65f81cc188d2c6f51029890409214864505e 100644 --- a/alib2str/src/registry/StringReaderRegistry.hpp +++ b/alib2str/src/registry/StringReaderRegistry.hpp @@ -40,25 +40,19 @@ private: static ext::map < std::string, ext::list < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > > > & getEntries ( ); public: + static void unregisterStringReader ( const std::string & group, ext::list < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > >::const_iterator iter ); + template < class Group > static void unregisterStringReader ( ext::list < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > >::const_iterator iter ) { std::string group = ext::to_string < Group > ( ); - - auto & entry = getEntries ( ) [ group ]; - if ( ! ext::range_contains_iterator ( entry.begin ( ), entry.end ( ), iter ) ) - throw std::invalid_argument ( "Entry not found in " + group + "." ); - - entry.erase ( iter ); - if ( entry.empty ( ) ) - getEntries ( ).erase ( group ); + unregisterStringReader ( group, iter ); } + static ext::list < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > >::const_iterator registerStringReader ( std::string group, std::function < bool ( std::istream & ) > first, std::unique_ptr < Entry > entry ); + template < class Group, class ReturnType > static ext::list < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > >::const_iterator registerStringReader ( ) { - std::string group = ext::to_string < Group > ( ); - - auto & entry = getEntries ( ) [ std::move ( group ) ]; - return entry.insert ( entry.end ( ), std::make_pair ( core::stringApi < ReturnType >::first, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ); + return registerStringReader ( ext::to_string < Group > ( ), core::stringApi < ReturnType >::first, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ); } static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & group, const std::string & str ); diff --git a/alib2str/src/registry/StringWriterRegistry.cpp b/alib2str/src/registry/StringWriterRegistry.cpp index 99ef936ad9d62ccbb1794d43f022e256252c360b..97cbd01b76ce8e0c8619e66ec6a7fcdf0d833799 100644 --- a/alib2str/src/registry/StringWriterRegistry.cpp +++ b/alib2str/src/registry/StringWriterRegistry.cpp @@ -14,6 +14,17 @@ ext::map < std::string, std::unique_ptr < StringWriterRegistry::Entry > > & Stri return writers; } +void StringWriterRegistry::unregisterStringWriter ( const std::string & param ) { + if ( getEntries ( ).erase ( param ) == 0u ) + throw std::invalid_argument ( "Entry " + param + " not registered." ); +} + +void StringWriterRegistry::registerStringWriter ( std::string param, std::unique_ptr < Entry > entry ) { + auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::move ( entry ) ) ); + if ( ! iter.second ) + throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); +} + std::shared_ptr < abstraction::OperationAbstraction > StringWriterRegistry::getAbstraction ( const std::string & param ) { auto type = getEntries ( ).find ( param ); if ( type == getEntries ( ).end ( ) ) diff --git a/alib2str/src/registry/StringWriterRegistry.hpp b/alib2str/src/registry/StringWriterRegistry.hpp index 3df5dffdeff8b008fd56bb42033ed0830e6b2c6a..376b3a0d51f7b0d80d3a658e21834e3289761a2c 100644 --- a/alib2str/src/registry/StringWriterRegistry.hpp +++ b/alib2str/src/registry/StringWriterRegistry.hpp @@ -40,10 +40,7 @@ private: static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ); public: - static void unregisterStringWriter ( const std::string & param ) { - if ( getEntries ( ).erase ( param ) == 0u ) - throw std::invalid_argument ( "Entry " + param + " not registered." ); - } + static void unregisterStringWriter ( const std::string & param ); template < class ParamType > static void unregisterStringWriter ( ) { @@ -51,11 +48,11 @@ public: unregisterStringWriter ( param ); } + static void registerStringWriter ( std::string param, std::unique_ptr < Entry > entry ); + template < class ParamType > static void registerStringWriter ( std::string param ) { - auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); + registerStringWriter ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ); } template < class ParamType > diff --git a/alib2xml/src/registry/XmlComposerRegistry.cpp b/alib2xml/src/registry/XmlComposerRegistry.cpp index ad298fc61eb9d254143a44200e466b138cbf790d..66db02f4813c27b055b5c1eb1283526bd0f34168 100644 --- a/alib2xml/src/registry/XmlComposerRegistry.cpp +++ b/alib2xml/src/registry/XmlComposerRegistry.cpp @@ -14,6 +14,17 @@ ext::map < std::string, std::unique_ptr < XmlComposerRegistry::Entry > > & XmlCo return fileWriters; } +void XmlComposerRegistry::unregisterXmlComposer ( const std::string & param ) { + if ( getEntries ( ).erase ( param ) == 0u ) + throw std::invalid_argument ( "Entry " + param + " not registered." ); +} + +void XmlComposerRegistry::registerXmlComposer ( std::string param, std::unique_ptr < Entry > entry ) { + auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::move ( entry ) ) ); + if ( ! iter.second ) + throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); +} + std::shared_ptr < abstraction::OperationAbstraction > XmlComposerRegistry::getAbstraction ( const std::string & param ) { auto res = getEntries ( ).find ( param ); if ( res == getEntries ( ).end ( ) ) diff --git a/alib2xml/src/registry/XmlComposerRegistry.hpp b/alib2xml/src/registry/XmlComposerRegistry.hpp index 892d7b283c66788f49e46ecd32b6c4e65c8daa8f..2ae999bf9dc6fc4816c84ac2c3cd400fcfe01870 100644 --- a/alib2xml/src/registry/XmlComposerRegistry.hpp +++ b/alib2xml/src/registry/XmlComposerRegistry.hpp @@ -40,10 +40,7 @@ private: static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ); public: - static void unregisterXmlComposer ( const std::string & param ) { - if ( getEntries ( ).erase ( param ) == 0u ) - throw std::invalid_argument ( "Entry " + param + " not registered." ); - } + static void unregisterXmlComposer ( const std::string & param ); template < class ParamType > static void unregisterXmlComposer ( ) { @@ -51,11 +48,11 @@ public: unregisterXmlComposer ( param ); } + static void registerXmlComposer ( std::string param, std::unique_ptr < Entry > entry ); + template < class ParamType > static void registerXmlComposer ( std::string param ) { - auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); + registerXmlComposer ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ); } template < class ParamType > diff --git a/alib2xml/src/registry/XmlContainerParserRegistry.cpp b/alib2xml/src/registry/XmlContainerParserRegistry.cpp index 661c46d7a106382f1c6d827c11928438eb7022a3..a0eacda1bffbdb70a1ad0e702058426c5e4e7445 100644 --- a/alib2xml/src/registry/XmlContainerParserRegistry.cpp +++ b/alib2xml/src/registry/XmlContainerParserRegistry.cpp @@ -15,6 +15,32 @@ ext::map < std::string, ext::list < ext::pair < std::string, std::unique_ptr < X return containerGroups; } +void XmlContainerParserRegistry::unregisterSet ( const std::string & param ) { + std::string container = "Set"; + + auto & group = getEntries ( ) [ container ]; + auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry ) { + return entry.first == param; + } ); + if ( iter == group.end ( ) ) + throw exception::CommonException ( "Callback for " + param + " in container " + container + " not registered." ); + + group.erase ( iter ); +} + +void XmlContainerParserRegistry::registerSet ( std::string param, std::unique_ptr < Entry > entry ) { + std::string container = "Set"; + + auto & group = getEntries ( ) [ container ]; + auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const ext::pair < std::string, std::unique_ptr < Entry > > & item ) { + return item.first == param; + } ); + if ( iter != group.end ( ) ) + throw exception::CommonException ( "Callback for " + param + " in container " + container + " already registered." ); + + group.insert ( group.end ( ), ext::make_pair ( std::move ( param ), std::move ( entry ) ) ); +} + bool XmlContainerParserRegistry::hasAbstraction ( const std::string & container ) { return getEntries ( ).contains ( container ); } diff --git a/alib2xml/src/registry/XmlContainerParserRegistry.hpp b/alib2xml/src/registry/XmlContainerParserRegistry.hpp index 0d08602c0480c232823fa966edb35ae99ff2cb10..9872a54b147b387d0cd79ef71ba2c4ec5a0f1bb3 100644 --- a/alib2xml/src/registry/XmlContainerParserRegistry.hpp +++ b/alib2xml/src/registry/XmlContainerParserRegistry.hpp @@ -40,18 +40,7 @@ private: static ext::map < std::string, ext::list < ext::pair < std::string, std::unique_ptr < Entry > > > > & getEntries ( ); public: - static void unregisterSet ( const std::string & param ) { - std::string container = "Set"; - - auto & group = getEntries ( ) [ container ]; - auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry ) { - return entry.first == param; - } ); - if ( iter == group.end ( ) ) - throw exception::CommonException ( "Callback for " + param + " in container " + container + " not registered." ); - - group.erase ( iter ); - } + static void unregisterSet ( const std::string & param ); template < class ParamTypes > static void unregisterSet ( ) { @@ -59,16 +48,11 @@ public: unregisterSet ( param ); } + static void registerSet ( std::string param, std::unique_ptr < Entry > entry ); + template < class ParamTypes > static void registerSet ( std::string param ) { - std::string container = "Set"; - - auto & group = getEntries ( ) [ container ]; - for ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry : group ) - if ( entry.first == param ) - throw exception::CommonException ( "Callback for " + param + " in container " + container + " already registered." ); - - group.insert ( group.end ( ), ext::make_pair ( std::move ( param ), std::make_unique < SetEntryImpl < ParamTypes > > ( ) ) ); + registerSet ( std::move ( param ), std::make_unique < SetEntryImpl < ParamTypes > > ( ) ); } template < class ParamTypes > diff --git a/alib2xml/src/registry/XmlParserRegistry.cpp b/alib2xml/src/registry/XmlParserRegistry.cpp index 5ecc00d1de9523addab8591196c93fb869d9655d..9e0034562ff9b8e4c83b0b303a5bb70cfee7946c 100644 --- a/alib2xml/src/registry/XmlParserRegistry.cpp +++ b/alib2xml/src/registry/XmlParserRegistry.cpp @@ -14,6 +14,17 @@ ext::map < std::string, std::unique_ptr < XmlParserRegistry::Entry > > & XmlPars return parsers; } +void XmlParserRegistry::unregisterXmlParser ( const std::string & result ) { + if ( getEntries ( ).erase ( result ) == 0u ) + throw std::invalid_argument ( "Entry " + result + " not registered." ); +} + +void XmlParserRegistry::registerXmlParser ( std::string result, std::unique_ptr < Entry > entry ) { + auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( result ), std::move ( entry ) ) ); + if ( ! iter.second ) + throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); +} + std::shared_ptr < abstraction::OperationAbstraction > XmlParserRegistry::getAbstraction ( const std::string & typeName ) { auto type = getEntries ( ).find ( typeName ); if ( type == getEntries ( ).end ( ) ) diff --git a/alib2xml/src/registry/XmlParserRegistry.hpp b/alib2xml/src/registry/XmlParserRegistry.hpp index d1c1277658d73c754dba39eb78e3869e646a6d6a..63bd72326bc1eb948fea399368ced3a88d599b14 100644 --- a/alib2xml/src/registry/XmlParserRegistry.hpp +++ b/alib2xml/src/registry/XmlParserRegistry.hpp @@ -39,10 +39,7 @@ private: static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ); public: - static void unregisterXmlParser ( const std::string & result ) { - if ( getEntries ( ).erase ( result ) == 0u ) - throw std::invalid_argument ( "Entry " + result + " not registered." ); - } + static void unregisterXmlParser ( const std::string & result ); template < class ReturnType > static void unregisterXmlParser ( ) { @@ -50,11 +47,11 @@ public: unregisterXmlParser ( ret ); } + static void registerXmlParser ( std::string result, std::unique_ptr < Entry > entry ); + template < class ReturnType > static void registerXmlParser ( std::string result ) { - auto iter = getEntries ( ).insert ( std::make_pair ( std::move ( result ), std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ); - if ( ! iter.second ) - throw std::invalid_argument ( "Entry " + iter.first->first + " already registered." ); + registerXmlParser ( std::move ( result ), std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ; } template < class ReturnType >