diff --git a/alib2common/src/abstraction/CastRegistry.hpp b/alib2common/src/abstraction/CastRegistry.hpp index 2c5f58b3719ee845fd1f93c07612348313371c6f..c038829132f71ebe7d2c6ed9816c795b150a5079 100644 --- a/alib2common/src/abstraction/CastRegistry.hpp +++ b/alib2common/src/abstraction/CastRegistry.hpp @@ -73,6 +73,20 @@ public: registerCast < TargetType, ParamType > ( target, param, normalize ); } + template < class TargetType, class ParamType > + static void registerCastAlgorithm ( std::string target, std::string param, TargetType ( * callback ) ( const ParamType & ), bool normalize ) { + if ( ! getEntries ( ).insert ( std::make_pair ( std::make_pair ( target, param ), std::unique_ptr < Entry > ( new AlgorithmEntryImpl < TargetType, const ParamType & > ( callback, normalize ) ) ) ).second ) + throw ::exception::CommonException ( "Entry from " + param + " to " + target + " already registered." ); + } + + template < class TargetType, class ParamType > + static void registerCastAlgorithm ( TargetType ( * callback ) ( const ParamType & ), bool normalize ) { + std::string target = ext::to_string < TargetType > ( ); + std::string param = ext::to_string < ParamType > ( ); + + registerCastAlgorithm < TargetType, ParamType > ( target, param, callback, normalize ); + } + template < class TargetType, class ParamType > static void registerCastAlgorithm ( std::string target, std::string param, TargetType ( * callback ) ( ParamType ), bool normalize ) { if ( ! getEntries ( ).insert ( std::make_pair ( std::make_pair ( target, param ), std::unique_ptr < Entry > ( new AlgorithmEntryImpl < TargetType, ParamType > ( callback, normalize ) ) ) ).second ) diff --git a/alib2common/src/registration/CastRegistration.hpp b/alib2common/src/registration/CastRegistration.hpp index 9d9ff52e82cd97716540b712c355a9b07bc407a1..817c8e002d07eb2e62da4e257db5c5b8ffd818d4 100644 --- a/alib2common/src/registration/CastRegistration.hpp +++ b/alib2common/src/registration/CastRegistration.hpp @@ -25,6 +25,9 @@ public: alib::castApi::getCastPool < To > ( ).template add < From > ( castFunction ); introspection::Casts::registerCast < From, To > ( ); + + bool normalize = registration::NormalizationRegister < To > ( ).requireNormalization ( ); + abstraction::CastRegistry::registerCastAlgorithm < To, From > ( castFunction, normalize ); } };