From 631d2d1fa96dbb917c41e63a3d58276d0e00e324 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 21 Aug 2017 20:14:36 +0200 Subject: [PATCH] move nontemplate code to cpp files in abstraction --- alib2common/src/abstraction/CastRegistry.cpp | 93 +++++++++++++++++++ alib2common/src/abstraction/CastRegistry.hpp | 81 ++-------------- .../src/abstraction/DowncastRegistry.cpp | 20 ++++ .../src/abstraction/DowncastRegistry.hpp | 8 +- .../src/abstraction/ImmediateRegistry.cpp | 20 ++++ .../src/abstraction/ImmediateRegistry.hpp | 8 +- .../src/abstraction/NormalizeRegistry.cpp | 20 ++++ .../src/abstraction/NormalizeRegistry.hpp | 8 +- .../src/abstraction/ValuePrinterRegistry.cpp | 8 ++ .../src/abstraction/ValuePrinterRegistry.hpp | 8 +- .../src/abstraction/XmlFileWriterRegistry.cpp | 33 +++++++ .../src/abstraction/XmlFileWriterRegistry.hpp | 21 +---- .../src/abstraction/XmlParserRegistry.cpp | 20 ++++ .../src/abstraction/XmlParserRegistry.hpp | 8 +- 14 files changed, 228 insertions(+), 128 deletions(-) create mode 100644 alib2common/src/abstraction/CastRegistry.cpp create mode 100644 alib2common/src/abstraction/DowncastRegistry.cpp create mode 100644 alib2common/src/abstraction/ImmediateRegistry.cpp create mode 100644 alib2common/src/abstraction/NormalizeRegistry.cpp create mode 100644 alib2common/src/abstraction/XmlFileWriterRegistry.cpp create mode 100644 alib2common/src/abstraction/XmlParserRegistry.cpp diff --git a/alib2common/src/abstraction/CastRegistry.cpp b/alib2common/src/abstraction/CastRegistry.cpp new file mode 100644 index 0000000000..9338ebdc74 --- /dev/null +++ b/alib2common/src/abstraction/CastRegistry.cpp @@ -0,0 +1,93 @@ +/* + * CastRegistry.cpp + * + * Created on: 21. 7. 2017 + * Author: Jan Travnicek + */ + +#include <abstraction/CastRegistry.hpp> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > CastRegistry::getAbstraction ( const std::string & target, const std::string & param, bool & normalize ) { + std::set < std::string > targetTypes; + if ( alib::namingApi::hasTypes ( target ) ) + targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( target ), [ ] ( const ext::type_index & type ) { return ext::to_string ( type ); } ); + else + targetTypes.insert ( target ); + + for ( const std::string & toType : targetTypes ) { + auto cast = getEntries ( ).find ( std::make_pair ( toType, param ) ); + if ( cast != getEntries ( ).end ( ) ) { + normalize = cast->second->getNormalize ( ); + return cast->second->getAbstraction ( ); + } + } + + throw exception::CommonException ( "Entry from " + param + " to " + target + " not available." ); +} + +bool CastRegistry::isNoOp ( const std::string & target, const std::string & param ) { + std::set < std::string > targetTypes; + if ( alib::namingApi::hasTypes ( target ) ) + targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( target ), [ ] ( const ext::type_index & type ) { return ext::to_string ( type ); } ); + else + targetTypes.insert ( target ); + + for ( const std::string & toType : targetTypes ) + if ( param == toType ) + return true; + + return false; +} + +bool CastRegistry::castAvailable ( const std::string & target, const std::string & param ) { + std::set < std::string > targetTypes; + if ( alib::namingApi::hasTypes ( target ) ) + targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( target ), [ ] ( const ext::type_index & type ) { return ext::to_string ( type ); } ); + else + targetTypes.insert ( target ); + + for ( const std::string & toType : targetTypes ) { + auto cast = getEntries ( ).find ( std::make_pair ( toType, param ) ); + if ( cast != getEntries ( ).end ( ) ) + return true; + } + + return false; +} + +std::shared_ptr < abstraction::OperationAbstraction > CastRegistry::getAbstraction ( const std::string & target, const std::string & param ) { + bool normalize; + return getAbstraction ( target, param, normalize ); +} + +void CastRegistry::listFrom ( const std::string & type ) { + std::set < std::string > sourceTypes; + if ( alib::namingApi::hasTypes ( type ) ) + sourceTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( type ), [ ] ( const ext::type_index & raw_type ) { return ext::to_string ( raw_type ); } ); + else + sourceTypes.insert ( type ); + + for ( const std::pair < const std::pair < std::string, std::string >, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { + if ( sourceTypes.count ( entry.first.first ) ) { + std::cout << entry.first.second << std::endl; + } + } +} + +void CastRegistry::listTo ( const std::string & type ) { + std::set < std::string > targetTypes; + if ( alib::namingApi::hasTypes ( type ) ) + targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( type ), [ ] ( const ext::type_index & raw_type ) { return ext::to_string ( raw_type ); } ); + else + targetTypes.insert ( type ); + + for ( const std::pair < const std::pair < std::string, std::string >, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { + if ( targetTypes.count ( entry.first.second ) ) { + std::cout << entry.first.first << std::endl; + } + } +} + +} /* namespace abstraction */ diff --git a/alib2common/src/abstraction/CastRegistry.hpp b/alib2common/src/abstraction/CastRegistry.hpp index 5b6d34135e..06532d93d5 100644 --- a/alib2common/src/abstraction/CastRegistry.hpp +++ b/alib2common/src/abstraction/CastRegistry.hpp @@ -101,86 +101,17 @@ public: registerCastAlgorithm < TargetType, ParamType > ( target, param, callback, normalize ); } - static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & target, const std::string & param, bool & normalize ) { - std::set < std::string > targetTypes; - if ( alib::namingApi::hasTypes ( target ) ) - targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( target ), [ ] ( const ext::type_index & type ) { return ext::to_string ( type ); } ); - else - targetTypes.insert ( target ); - - for ( const std::string & toType : targetTypes ) { - auto cast = getEntries ( ).find ( std::make_pair ( toType, param ) ); - if ( cast != getEntries ( ).end ( ) ) { - normalize = cast->second->getNormalize ( ); - return cast->second->getAbstraction ( ); - } - } - - throw exception::CommonException ( "Entry from " + param + " to " + target + " not available." ); - } - - static bool isNoOp ( const std::string & target, const std::string & param ) { - std::set < std::string > targetTypes; - if ( alib::namingApi::hasTypes ( target ) ) - targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( target ), [ ] ( const ext::type_index & type ) { return ext::to_string ( type ); } ); - else - targetTypes.insert ( target ); - - for ( const std::string & toType : targetTypes ) - if ( param == toType ) - return true; - - return false; - } + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & target, const std::string & param, bool & normalize ); - static bool castAvailable ( const std::string & target, const std::string & param ) { - std::set < std::string > targetTypes; - if ( alib::namingApi::hasTypes ( target ) ) - targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( target ), [ ] ( const ext::type_index & type ) { return ext::to_string ( type ); } ); - else - targetTypes.insert ( target ); - - for ( const std::string & toType : targetTypes ) { - auto cast = getEntries ( ).find ( std::make_pair ( toType, param ) ); - if ( cast != getEntries ( ).end ( ) ) - return true; - } + static bool isNoOp ( const std::string & target, const std::string & param ); - return false; - } + static bool castAvailable ( const std::string & target, const std::string & param ); - static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & target, const std::string & param ) { - bool normalize; - return getAbstraction ( target, param, normalize ); - } + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & target, const std::string & param ); - static void listFrom ( const std::string & type ) { - std::set < std::string > sourceTypes; - if ( alib::namingApi::hasTypes ( type ) ) - sourceTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( type ), [ ] ( const ext::type_index & raw_type ) { return ext::to_string ( raw_type ); } ); - else - sourceTypes.insert ( type ); - - for ( const std::pair < const std::pair < std::string, std::string >, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { - if ( sourceTypes.count ( entry.first.first ) ) { - std::cout << entry.first.second << std::endl; - } - } - } + static void listFrom ( const std::string & type ); - static void listTo ( const std::string & type ) { - std::set < std::string > targetTypes; - if ( alib::namingApi::hasTypes ( type ) ) - targetTypes = ext::transform < std::string > ( alib::namingApi::getTypes ( type ), [ ] ( const ext::type_index & raw_type ) { return ext::to_string ( raw_type ); } ); - else - targetTypes.insert ( type ); - - for ( const std::pair < const std::pair < std::string, std::string >, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { - if ( targetTypes.count ( entry.first.second ) ) { - std::cout << entry.first.first << std::endl; - } - } - } + static void listTo ( const std::string & type ); }; diff --git a/alib2common/src/abstraction/DowncastRegistry.cpp b/alib2common/src/abstraction/DowncastRegistry.cpp new file mode 100644 index 0000000000..6d1be65041 --- /dev/null +++ b/alib2common/src/abstraction/DowncastRegistry.cpp @@ -0,0 +1,20 @@ +/* + * DowncastRegistry.cpp + * + * Created on: 21. 8. 2017 + * Author: Jan Travnicek + */ + +#include <abstraction/DowncastRegistry.hpp> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > DowncastRegistry::getAbstraction ( const std::string & concrete, const std::string & base ) { + auto res = getEntries ( ).find ( std::make_pair ( concrete, base ) ); + if ( res == getEntries ( ).end ( ) ) + throw exception::CommonException ( "Entry " + concrete + ", " + base + " not available." ); + + return res->second->getAbstraction ( ); +} + +} /* namespace abstraction */ diff --git a/alib2common/src/abstraction/DowncastRegistry.hpp b/alib2common/src/abstraction/DowncastRegistry.hpp index 25e4621ecb..331f477e69 100644 --- a/alib2common/src/abstraction/DowncastRegistry.hpp +++ b/alib2common/src/abstraction/DowncastRegistry.hpp @@ -46,13 +46,7 @@ public: throw ::exception::CommonException ( "Downcasting for " + base + " to " + concrete + " already registered." ); } - static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & concrete, const std::string & base ) { - auto res = getEntries ( ).find ( std::make_pair ( concrete, base ) ); - if ( res == getEntries ( ).end ( ) ) - throw exception::CommonException ( "Entry " + concrete + ", " + base + " not available." ); - - return res->second->getAbstraction ( ); - } + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & concrete, const std::string & base ); }; } /* namespace abstraction */ diff --git a/alib2common/src/abstraction/ImmediateRegistry.cpp b/alib2common/src/abstraction/ImmediateRegistry.cpp new file mode 100644 index 0000000000..4dcd5cd19e --- /dev/null +++ b/alib2common/src/abstraction/ImmediateRegistry.cpp @@ -0,0 +1,20 @@ +/* + * ImmediateRegistry.cpp + * + * Created on: 21. 8. 2017 + * Author: Jan Travnicek + */ + +#include <abstraction/ImmediateRegistry.hpp> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > ImmediateRegistry::getAbstraction ( const std::string & result, std::string value ) { + auto res = getEntries ( ).find ( result ); + if ( res == getEntries ( ).end ( ) ) + throw exception::CommonException ( "Entry " + result + " not available." ); + + return res->second->getAbstraction ( std::move ( value ) ); +} + +} /* namespace abstraction */ diff --git a/alib2common/src/abstraction/ImmediateRegistry.hpp b/alib2common/src/abstraction/ImmediateRegistry.hpp index d7884d14db..369995e001 100644 --- a/alib2common/src/abstraction/ImmediateRegistry.hpp +++ b/alib2common/src/abstraction/ImmediateRegistry.hpp @@ -52,13 +52,7 @@ public: registerImmediate < ResultType > ( std::move ( result ) ); } - static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & result, std::string value ) { - auto res = getEntries ( ).find ( result ); - if ( res == getEntries ( ).end ( ) ) - throw exception::CommonException ( "Entry " + result + " not available." ); - - return res->second->getAbstraction ( std::move ( value ) ); - } + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & result, std::string value ); }; } /* namespace abstraction */ diff --git a/alib2common/src/abstraction/NormalizeRegistry.cpp b/alib2common/src/abstraction/NormalizeRegistry.cpp new file mode 100644 index 0000000000..0c47a9153e --- /dev/null +++ b/alib2common/src/abstraction/NormalizeRegistry.cpp @@ -0,0 +1,20 @@ +/* + * NormalizeRegistry.cpp + * + * Created on: 21. 8. 2017 + * Author: Jan Travnicek + */ + +#include <abstraction/NormalizeRegistry.hpp> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > NormalizeRegistry::getAbstraction ( const std::string & param ) { + auto res = getEntries ( ).find ( param ); + if ( res == getEntries ( ).end ( ) ) + throw exception::CommonException ( "Entry " + param + " not available." ); + + return res->second->getAbstraction ( ); +} + +} /* namespace abstraction */ diff --git a/alib2common/src/abstraction/NormalizeRegistry.hpp b/alib2common/src/abstraction/NormalizeRegistry.hpp index a777bc7190..a5791d6d00 100644 --- a/alib2common/src/abstraction/NormalizeRegistry.hpp +++ b/alib2common/src/abstraction/NormalizeRegistry.hpp @@ -49,13 +49,7 @@ public: registerNormalize < ParamType > ( std::move ( param ) ); } - static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & param ) { - auto res = getEntries ( ).find ( param ); - if ( res == getEntries ( ).end ( ) ) - throw exception::CommonException ( "Entry " + param + " not available." ); - - return res->second->getAbstraction ( ); - } + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & param ); }; } /* namespace abstraction */ diff --git a/alib2common/src/abstraction/ValuePrinterRegistry.cpp b/alib2common/src/abstraction/ValuePrinterRegistry.cpp index 39e39fc579..89c5198a72 100644 --- a/alib2common/src/abstraction/ValuePrinterRegistry.cpp +++ b/alib2common/src/abstraction/ValuePrinterRegistry.cpp @@ -9,6 +9,14 @@ namespace abstraction { +std::shared_ptr < abstraction::OperationAbstraction > ValuePrinterRegistry::getAbstraction ( const std::string & param ) { + auto res = getEntries ( ).find ( param ); + if ( res == getEntries ( ).end ( ) ) + throw exception::CommonException ( "Entry " + param + " not available." ); + + return res->second->getAbstraction ( ); +} + template < > std::shared_ptr < abstraction::OperationAbstraction > ValuePrinterRegistry::EntryImpl < void >::getAbstraction ( ) const { return std::make_shared < abstraction::ValuePrinterAbstraction < void > > ( ); diff --git a/alib2common/src/abstraction/ValuePrinterRegistry.hpp b/alib2common/src/abstraction/ValuePrinterRegistry.hpp index 92b4f370ad..ccf6d3694a 100644 --- a/alib2common/src/abstraction/ValuePrinterRegistry.hpp +++ b/alib2common/src/abstraction/ValuePrinterRegistry.hpp @@ -49,13 +49,7 @@ public: registerValuePrinter < ParamType > ( std::move ( param ) ); } - static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & param ) { - auto res = getEntries ( ).find ( param ); - if ( res == getEntries ( ).end ( ) ) - throw exception::CommonException ( "Entry " + param + " not available." ); - - return res->second->getAbstraction ( ); - } + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & param ); }; } /* namespace abstraction */ diff --git a/alib2common/src/abstraction/XmlFileWriterRegistry.cpp b/alib2common/src/abstraction/XmlFileWriterRegistry.cpp new file mode 100644 index 0000000000..ad32093568 --- /dev/null +++ b/alib2common/src/abstraction/XmlFileWriterRegistry.cpp @@ -0,0 +1,33 @@ +/* + * XmlFileWriterRegistry.cpp + * + * Created on: 21. 8. 2017 + * Author: Jan Travnicek + */ + +#include <abstraction/XmlFileWriterRegistry.hpp> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > XmlFileWriterRegistry::getAbstraction ( const std::string & param, std::string filename ) { + auto res = getEntries ( ).find ( param ); + if ( res == getEntries ( ).end ( ) ) + throw exception::CommonException ( "Entry " + param + " not available." ); + + return res->second->getAbstraction ( std::move ( filename ) ); +} + +void XmlFileWriterRegistry::listGroup ( const std::string & group ) { + for ( const std::pair < const std::string, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { + if ( entry.first.find ( group ) == 0 ) //found at the begining + std::cout << entry.first << std::endl; + } +} + +void XmlFileWriterRegistry::list ( ) { + for ( const std::pair < const std::string, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { + std::cout << entry.first << std::endl; + } +} + +} /* namespace abstraction */ diff --git a/alib2common/src/abstraction/XmlFileWriterRegistry.hpp b/alib2common/src/abstraction/XmlFileWriterRegistry.hpp index 937360501c..2f1ae77784 100644 --- a/alib2common/src/abstraction/XmlFileWriterRegistry.hpp +++ b/alib2common/src/abstraction/XmlFileWriterRegistry.hpp @@ -49,26 +49,11 @@ public: registerXmlFileWriter < ParamType > ( std::move ( param ) ); } - static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & param, std::string filename ) { - auto res = getEntries ( ).find ( param ); - if ( res == getEntries ( ).end ( ) ) - throw exception::CommonException ( "Entry " + param + " not available." ); + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & param, std::string filename ); - return res->second->getAbstraction ( std::move ( filename ) ); - } - - static void listGroup ( const std::string & group ) { - for ( const std::pair < const std::string, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { - if ( entry.first.find ( group ) == 0 ) //found at the begining - std::cout << entry.first << std::endl; - } - } + static void listGroup ( const std::string & group ); - static void list ( ) { - for ( const std::pair < const std::string, std::unique_ptr < Entry > > & entry : getEntries ( ) ) { - std::cout << entry.first << std::endl; - } - } + static void list ( ); }; } /* namespace abstraction */ diff --git a/alib2common/src/abstraction/XmlParserRegistry.cpp b/alib2common/src/abstraction/XmlParserRegistry.cpp new file mode 100644 index 0000000000..0c5a2f12c5 --- /dev/null +++ b/alib2common/src/abstraction/XmlParserRegistry.cpp @@ -0,0 +1,20 @@ +/* + * XmlParserRegistry.cpp + * + * Created on: 21. 8. 2017 + * Author: Jan Travnicek + */ + +#include <abstraction/XmlParserRegistry.hpp> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > XmlParserRegistry::getAbstraction ( const std::string & typeName, ext::deque < sax::Token > tokens ) { + auto type = getEntries ( ).find ( typeName ); + if ( type == getEntries ( ).end ( ) ) + throw exception::CommonException ( "Entry " + typeName + " not available." ); + + return type->second->getAbstraction ( std::move ( tokens ) ); +} + +} /* namespace abstraction */ diff --git a/alib2common/src/abstraction/XmlParserRegistry.hpp b/alib2common/src/abstraction/XmlParserRegistry.hpp index 40664eff9f..7adf27a9d0 100644 --- a/alib2common/src/abstraction/XmlParserRegistry.hpp +++ b/alib2common/src/abstraction/XmlParserRegistry.hpp @@ -45,13 +45,7 @@ public: getEntries ( ).insert ( std::make_pair ( ret, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) ) ); } - static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & typeName, ext::deque < sax::Token > tokens ) { - auto type = getEntries ( ).find ( typeName ); - if ( type == getEntries ( ).end ( ) ) - throw exception::CommonException ( "Entry " + typeName + " not available." ); - - return type->second->getAbstraction ( std::move ( tokens ) ); - } + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & typeName, ext::deque < sax::Token > tokens ); }; } /* namespace abstraction */ -- GitLab