From cc41d66de590ab3e9910e3db2b4ea25dc3ea79de Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Wed, 16 Aug 2017 22:06:43 +0200
Subject: [PATCH] register cast algorithms in abstraction

---
 alib2common/src/abstraction/CastRegistry.hpp      | 14 ++++++++++++++
 alib2common/src/registration/CastRegistration.hpp |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/alib2common/src/abstraction/CastRegistry.hpp b/alib2common/src/abstraction/CastRegistry.hpp
index 2c5f58b371..c038829132 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 9d9ff52e82..817c8e002d 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 );
 	}
 };
 
-- 
GitLab