diff --git a/alib2raw/src/registry/RawReaderRegistry.hpp b/alib2raw/src/registry/RawReaderRegistry.hpp index 66cffe99eb1dab9f350fd460be800d72937b820f..156c58498578e9c2384b3e6cf1524b6753c72d15 100644 --- a/alib2raw/src/registry/RawReaderRegistry.hpp +++ b/alib2raw/src/registry/RawReaderRegistry.hpp @@ -44,7 +44,8 @@ class RawReaderRegistry { public: template < class ReturnType > static void registerRawReader ( std::string type ) { - getEntries ( ).insert ( std::make_pair ( std::move ( type ), std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ); + if ( ! getEntries ( ).insert ( std::make_pair ( std::move ( type ), std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ).second ) + throw std::invalid_argument ( "Entry " + type + " already registered." ); } template < class ReturnType > diff --git a/alib2raw/src/registry/RawWriterRegistry.hpp b/alib2raw/src/registry/RawWriterRegistry.hpp index b8210981a6482ed0bbe1710bbfd8b10e51f87200..886ee8553b12530a69c3db24ad93a4be845ad7b4 100644 --- a/alib2raw/src/registry/RawWriterRegistry.hpp +++ b/alib2raw/src/registry/RawWriterRegistry.hpp @@ -47,7 +47,8 @@ class RawWriterRegistry { public: template < class ParamType > static void registerRawWriter ( std::string param ) { - getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ); + if ( ! getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ).second ) + throw std::invalid_argument ( "Entry " + param + " already registered." ); } template < class ParamType > diff --git a/alib2str/src/registry/StringReaderRegistry.cpp b/alib2str/src/registry/StringReaderRegistry.cpp index 79018fccb90d2996a7683183d56eeca5599c5451..e69c58d26d837da9d65265d3effba351d72846a3 100644 --- a/alib2str/src/registry/StringReaderRegistry.cpp +++ b/alib2str/src/registry/StringReaderRegistry.cpp @@ -14,8 +14,8 @@ std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::getA while ( isspace ( ss.peek ( ) ) ) ss.get ( ); - auto lambda = [ & ] ( const std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > & entry ) { - return entry.first ( ss ); + auto lambda = [ & ] ( const std::pair < const std::string, std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > > & entry ) { + return entry.second.first ( ss ); }; const auto & entryIterator = getEntries ( ).find ( group ); @@ -26,14 +26,14 @@ std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::getA int pos = ss.tellg(); - typename ext::deque < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > >::const_iterator callback = find_if ( entries.begin ( ), entries.end ( ), lambda ); + typename ext::map < std::string, std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > >::const_iterator callback = find_if ( entries.begin ( ), entries.end ( ), lambda ); if ( callback == entries.end ( ) ) throw exception::CommonException ( "No callback handling input found." ); if ( pos != ss.tellg ( ) ) throw exception::CommonException ( "First function of registered callback moved the stream." ); - return callback->second->getAbstraction ( ); + return callback->second.second->getAbstraction ( ); } } /* namespace abstraction */ diff --git a/alib2str/src/registry/StringReaderRegistry.hpp b/alib2str/src/registry/StringReaderRegistry.hpp index f987514c2b8b431ca8e1a766936699aace28b6df..5f33c77682d365e4fe266872a0271568ee9f758e 100644 --- a/alib2str/src/registry/StringReaderRegistry.hpp +++ b/alib2str/src/registry/StringReaderRegistry.hpp @@ -39,15 +39,19 @@ class StringReaderRegistry { virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override; }; - static ext::map < std::string, ext::deque < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > > > & getEntries ( ) { - static ext::map < std::string, ext::deque < std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > > > readers; + static ext::map < std::string, ext::map < std::string, std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > > > & getEntries ( ) { + static ext::map < std::string, ext::map < std::string, std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < Entry > > > > readers; return readers; } public: template < class Group, class ReturnType > static void registerStringReader ( ) { - getEntries ( ) [ ext::to_string < Group > ( ) ].push_back ( std::make_pair ( core::stringApi < ReturnType >::first, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ); + std::string group = ext::to_string < Group > ( ); + std::string returnType = ext::to_string < ReturnType > ( ); + + if ( ! getEntries ( ) [ group ].insert ( std::make_pair ( std::move ( returnType ), std::make_pair ( core::stringApi < ReturnType >::first, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ) ).second ) + throw std::invalid_argument ( "Entry " + returnType + " already registered in " + group + "." ); } static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & group, const std::string & data ); diff --git a/alib2str/src/registry/StringWriterRegistry.hpp b/alib2str/src/registry/StringWriterRegistry.hpp index 68ab65ed6c166ebd40d37096a8f1c01df40e3bb3..5aca32764fe63d59032b1448e594186e471c46be 100644 --- a/alib2str/src/registry/StringWriterRegistry.hpp +++ b/alib2str/src/registry/StringWriterRegistry.hpp @@ -48,7 +48,8 @@ class StringWriterRegistry { public: template < class ParamType > static void registerStringWriter ( std::string param ) { - getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ); + if ( ! getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ).second ) + throw std::invalid_argument ( "Entry " + param + " already registered." ); } template < class ParamType > diff --git a/alib2xml/src/registry/XmlComposerRegistry.hpp b/alib2xml/src/registry/XmlComposerRegistry.hpp index 1a310058a83069a346d34fe8c260b5887bc21923..b2161fc0906447d924cfeec84f4b005f889ef799 100644 --- a/alib2xml/src/registry/XmlComposerRegistry.hpp +++ b/alib2xml/src/registry/XmlComposerRegistry.hpp @@ -48,7 +48,8 @@ class XmlComposerRegistry { public: template < class ParamType > static void registerXmlComposer ( std::string param ) { - getEntries ( ).insert ( std::make_pair ( param, std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ); + if ( ! getEntries ( ).insert ( std::make_pair ( param, std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ).second ) + throw std::invalid_argument ( "Entry " + param + " already registered." ); } template < class ParamType > diff --git a/alib2xml/src/registry/XmlParserRegistry.hpp b/alib2xml/src/registry/XmlParserRegistry.hpp index b252c33c391f005f1f3427c4be303ca8c13d0eea..e2ea08c121a0f30a091316e372d62c87ce91f4b6 100644 --- a/alib2xml/src/registry/XmlParserRegistry.hpp +++ b/alib2xml/src/registry/XmlParserRegistry.hpp @@ -47,7 +47,8 @@ class XmlParserRegistry { public: template < class ReturnType > static void registerXmlParser ( std::string result ) { - getEntries ( ).insert ( std::make_pair ( result, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ); + if ( ! getEntries ( ).insert ( std::make_pair ( result, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ).second ) + throw std::invalid_argument ( "Entry " + result + " already registered." ); } template < class ReturnType >