From 7a96c2dce7c26b8532059373380730648dbe3666 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 21 Nov 2017 17:28:26 +0100 Subject: [PATCH] get operation on components as method abstraction --- alib2common/src/core/components.hpp | 24 +++++++++++++++++++ .../src/core/components/setComponents.hpp | 7 ++++++ .../registration/ComponentRegistration.hpp | 17 +++++++++++++ alib2data/src/automaton/FSM/CompactNFA.cpp | 3 +++ 4 files changed, 51 insertions(+) create mode 100644 alib2common/src/registration/ComponentRegistration.hpp diff --git a/alib2common/src/core/components.hpp b/alib2common/src/core/components.hpp index e2b2956fb6..69c846ebae 100644 --- a/alib2common/src/core/components.hpp +++ b/alib2common/src/core/components.hpp @@ -10,6 +10,7 @@ #include <typeinfo> #include <exception/CommonException.h> +#include <abstraction/AlgorithmRegistry.hpp> namespace component { @@ -145,6 +146,12 @@ public: return * this; } + static void registerComponent ( ) { + std::array < std::string, 0 > names; + ComponentType & ( Derived::* method ) ( ) = & Component < Derived, ComponentType, component::Value, ComponentName >::get; + abstraction::AlgorithmRegistry::registerMethod < ComponentName > ( method, "get", names ); + } + }; /** @@ -158,6 +165,9 @@ public: */ template < class T, typename std::enable_if < ! std::is_same < T, T >::value >::type * = nullptr > void accessComponent ( ); + + static void registerComponent ( ) { + } }; /** @@ -186,6 +196,11 @@ public: * Make access method from Components base class part of methods set of this Components class */ using Components < Derived, Next ... >::accessComponent; + + static void registerComponent ( ) { + Component < Derived, ComponentType, ComponentCategory, ComponentName >::registerComponent ( ); + Components < Derived, Next ... >::registerComponent ( ); + } }; /** @@ -214,6 +229,11 @@ public: * Make access method from Components base class part of methods set of this Components class */ using Components < Derived, ComponentType, ComponentCategory, std::tuple < ComponentNames ... >, Next ... >::accessComponent; + + static void registerComponent ( ) { + Component < Derived, ComponentType, ComponentCategory, ComponentName >::registerComponent ( ); + Components < Derived, ComponentType, ComponentCategory, std::tuple < ComponentNames ... >, Next ... >::registerComponent ( ); + } }; /** @@ -236,6 +256,10 @@ public: * Make access method from Components base class part of methods set of this Components class */ using Components < Derived, Next ... >::accessComponent; + + static void registerComponent ( ) { + Components < Derived, Next ... >::registerComponent ( ); + } }; } /* namespace alib */ diff --git a/alib2common/src/core/components/setComponents.hpp b/alib2common/src/core/components/setComponents.hpp index 1746248c0c..f24dd9cb28 100644 --- a/alib2common/src/core/components/setComponents.hpp +++ b/alib2common/src/core/components/setComponents.hpp @@ -11,6 +11,7 @@ #include <algorithm> #include <typeinfo> #include <exception/CommonException.h> +#include <abstraction/AlgorithmRegistry.hpp> namespace component { @@ -229,6 +230,12 @@ public: Component ( ) { } + + static void registerComponent ( ) { + std::array < std::string, 0 > names; + ComponentType & ( Derived::* method ) ( ) = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::get; + abstraction::AlgorithmRegistry::registerMethod < ComponentName > ( method, "get", names ); + } }; } /* namespace alib */ diff --git a/alib2common/src/registration/ComponentRegistration.hpp b/alib2common/src/registration/ComponentRegistration.hpp new file mode 100644 index 0000000000..0482c7f716 --- /dev/null +++ b/alib2common/src/registration/ComponentRegistration.hpp @@ -0,0 +1,17 @@ +#ifndef _COMPONENT_REGISTRATION_HPP_ +#define _COMPONENT_REGISTRATION_HPP_ + +namespace registration { + +template < class ObjectType > +class ComponentRegister { +public: + ComponentRegister ( ) { + ObjectType::registerComponent ( ); + } + +}; + +} /* namespace registration */ + +#endif /* _COMPONENT_REGISTRATION_HPP_ */ diff --git a/alib2data/src/automaton/FSM/CompactNFA.cpp b/alib2data/src/automaton/FSM/CompactNFA.cpp index 714e6cee9f..b619700abd 100644 --- a/alib2data/src/automaton/FSM/CompactNFA.cpp +++ b/alib2data/src/automaton/FSM/CompactNFA.cpp @@ -12,9 +12,12 @@ #include <registration/ValuePrinterRegistration.hpp> #include <registration/XmlRegistration.hpp> #include <registration/CastRegistration.hpp> +#include <registration/ComponentRegistration.hpp> namespace { +static auto components = registration::ComponentRegister < automaton::CompactNFA < > > ( ); + static auto valuePrinter = registration::ValuePrinterRegister < automaton::CompactNFA < > > ( ); static auto xmlWrite = registration::XmlWriterRegister < automaton::Automaton, automaton::CompactNFA < > > ( ); -- GitLab