From 6795a8edbe47377cf37cbce374171d368fb55162 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 11 Jul 2017 16:17:09 +0200 Subject: [PATCH] modify registrations --- .../src/registration/AlgoRegistration.hpp | 43 +++++++++++++++++++ .../src/registration/CastRegistration.hpp | 3 ++ .../src/registration/TypeRegistration.hpp | 11 +++++ 3 files changed, 57 insertions(+) diff --git a/alib2common/src/registration/AlgoRegistration.hpp b/alib2common/src/registration/AlgoRegistration.hpp index 096394ce44..1a2d5e27fd 100644 --- a/alib2common/src/registration/AlgoRegistration.hpp +++ b/alib2common/src/registration/AlgoRegistration.hpp @@ -4,6 +4,10 @@ #include <introspection/Algorithms.hpp> #include <core/multipleDispatch.hpp> +#include <abstraction/AlgorithmRegistry.hpp> +#include <abstraction/NormalizeRegistry.hpp> +#include <abstraction/DowncastRegistry.hpp> + namespace registration { template < class Algorithm, class RealReturnType, class ... RealParameterTypeBases > @@ -18,6 +22,45 @@ public: } }; +template < class Type, typename enable = void > +struct RequireNormalization : std::false_type { +}; + +template < class Type > +struct RequireNormalization < Type, typename std::enable_if < std::has_normalize < Type >::value && ! std::is_same < Type, typename Type::normalized_type >::value >::type > : public std::true_type { +}; + +template < class Type, typename enable = void > +struct RequireDowncast : std::false_type { +}; + +template < class Type > +struct RequireDowncast < Type *, typename std::enable_if < ! std::is_final < Type >::value >::type > : public std::true_type { +}; + +template < class Algorithm, class ReturnType, class ... ParameterTypes > +class AbstractRegister { + + template < class Type, typename std::enable_if < RequireNormalization < Type >::value >::type * = nullptr > + void registerNormalize ( ) { + abstraction::NormalizeRegistry::registerNormalize < ReturnType > ( ); + } + + template < class Type, typename std::enable_if < ! RequireNormalization < Type >::value >::type * = nullptr > + void registerNormalize ( ) { + } + +public: + AbstractRegister ( ReturnType ( * callback ) ( ParameterTypes ... ) ) { + bool normalize = RequireNormalization < ReturnType >::value; + bool downcast = RequireDowncast < ReturnType >::value; + + abstraction::AlgorithmRegistry::registerAlgorithm < Algorithm, ReturnType, ParameterTypes ... > ( callback, downcast, normalize ); + + registerNormalize < ReturnType > ( ); + } +}; + } /* namespace registration */ #endif // _ALGO_REGISTRATION_HPP_ diff --git a/alib2common/src/registration/CastRegistration.hpp b/alib2common/src/registration/CastRegistration.hpp index 8d42e2e997..2dc1e7fa66 100644 --- a/alib2common/src/registration/CastRegistration.hpp +++ b/alib2common/src/registration/CastRegistration.hpp @@ -3,6 +3,7 @@ #include <core/castApi.hpp> #include <introspection/Casts.hpp> +#include <abstraction/CastRegistry.hpp> namespace registration { @@ -13,6 +14,8 @@ public: alib::castApi::getCastPool < To > ( ).template add < From > ( ); introspection::Casts::registerCast < From, To > ( ); + + abstraction::CastRegistry::registerCast < To, From > ( ); } CastRegister ( To ( * castFunction ) ( const From & ) ) { diff --git a/alib2common/src/registration/TypeRegistration.hpp b/alib2common/src/registration/TypeRegistration.hpp index 00042d31f1..db6742f52a 100644 --- a/alib2common/src/registration/TypeRegistration.hpp +++ b/alib2common/src/registration/TypeRegistration.hpp @@ -4,6 +4,11 @@ #include <core/xmlApi.hpp> #include <introspection/DataTypes.hpp> +#include <abstraction/XmlFileWriterRegistry.hpp> +#include <abstraction/XmlParserRegistry.hpp> +#include <abstraction/ValuePrinterRegistry.hpp> +#include <abstraction/DowncastRegistry.hpp> + namespace registration { template < class Group, class Type > @@ -13,6 +18,12 @@ public: alib::xmlApi < Group >::template registerType < Type > ( ); introspection::DataTypes::registerTypeInGroup < Type, Group > ( ); introspection::DataTypes::registerGroup < Group > ( ); + + abstraction::XmlFileWriterRegistry::registerXmlFileWriter < Type > ( ); + abstraction::XmlParserRegistry::registerXmlParser < Type > ( ); + abstraction::ValuePrinterRegistry::registerValuePrinter < Type > ( ); + + abstraction::DowncastRegistry::registerDowncast < Type, typename std::decay < decltype ( std::declval < Group > ( ).getData ( ) ) >::type > ( ); } }; -- GitLab