diff --git a/alib2common/src/abstraction/NormalizeAbstraction.hpp b/alib2common/src/abstraction/NormalizeAbstraction.hpp index 50db25dac60dd892d381a6a6ed4610da75f89da1..5997c1938b0045d612f2e2790d7da6094a6ba09b 100644 --- a/alib2common/src/abstraction/NormalizeAbstraction.hpp +++ b/alib2common/src/abstraction/NormalizeAbstraction.hpp @@ -11,6 +11,8 @@ #include <abstraction/UnaryOperationAbstraction.hpp> #include <tuple> +#include <core/normalize.hpp> + namespace abstraction { template < class ReturnType, class ParamType > @@ -23,7 +25,7 @@ public: if ( this->cached ( ) ) return true; - this->m_data = ReturnType ( * std::unique_ptr < ReturnType > ( static_cast < ReturnType * > ( std::move ( std::get < 0 > ( this->m_params )->getValue ( std::get < 0 > ( this->m_moves ) ) ).normalize ( ) ) ) ); + this->m_data = alib::normalize < ParamType >::eval ( std::get < 0 > ( this->m_params )->getValue ( std::get < 0 > ( this->m_moves ) ) ); return true; } diff --git a/alib2common/src/base/CommonBase.hpp b/alib2common/src/base/CommonBase.hpp index a5d7e21fd5cdda33e48f19af39c937a2ec27b2e9..d7e878e7415856d044e84c35cff15e8c97c2089d 100644 --- a/alib2common/src/base/CommonBase.hpp +++ b/alib2common/src/base/CommonBase.hpp @@ -146,14 +146,6 @@ public: */ template< typename T > class CommonBase : public CommonBaseMiddle < T > { -public: - - /** - * Helper for normalisation of templated datatypes in algorithms library toolkit to the same types but with default template parameters. - * - * \returns new instance of the grammar with default template parameters or unmodified instance if the template parameters were already default ones - */ - virtual T * normalize ( ) && = 0; }; } /* namespace alib */ diff --git a/alib2common/src/base/WrapperBase.hpp b/alib2common/src/base/WrapperBase.hpp index fbca24ffc960e24074ef556ccf274ba5029a61c4..c056cc2db12ce1227b667df97b858ff435b1463d 100644 --- a/alib2common/src/base/WrapperBase.hpp +++ b/alib2common/src/base/WrapperBase.hpp @@ -229,16 +229,6 @@ template < typename T > class WrapperBase : public WrapperBaseMiddle < T > { public: using WrapperBaseMiddle < T >::WrapperBaseMiddle; - - /** - * Helper for normalisation of wrapped templated datatypes in algorithms library toolkit to the same types but with default template parameters. - * - * This method actually changes the stored object to the normalized one. - */ - void normalize ( ) { - this->setData ( std::move ( this->getData ( ) ).normalize ( ) ); - } - }; } /* namespace alib */ diff --git a/alib2common/src/container/ObjectsDeque.h b/alib2common/src/container/ObjectsDeque.h index e25e0ba8fa236fa5d615304195bac941525c558b..f3931f7d4eb108abd5f7198873732730f0383552 100644 --- a/alib2common/src/container/ObjectsDeque.h +++ b/alib2common/src/container/ObjectsDeque.h @@ -16,9 +16,11 @@ #include "ContainerFeatures.h" #include <core/xmlApi.hpp> -#include "../object/UniqueObject.h" +#include <object/UniqueObject.h> #include <object/AnyObject.h> +#include <core/normalize.hpp> + namespace container { /** @@ -61,19 +63,7 @@ public: virtual alib::ObjectBase * inc ( ) &&; - static ext::deque < alib::Object > normalizeRaw ( ext::deque < ElementType > && source ) { - ext::deque < alib::Object > res; - for ( ElementType & element : source ) { - res.push_back ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( element ) ) ) ); - } - return res; - } - typedef ObjectsDeque < > normalized_type; - - virtual ContainerBase * normalize ( ) && { - return new ObjectsDeque < alib::Object > ( normalizeRaw ( std::move ( * this ) ) ); - } }; template < class ElementType > @@ -183,6 +173,32 @@ void xmlApi < ext::deque < T > >::compose ( ext::deque < sax::Token > & output, return container::ObjectsDeque < T >::compose ( output, input ); } +template < > +struct normalize < ext::deque < alib::Object > > { + static ext::deque < alib::Object > && eval ( ext::deque < alib::Object > && source ) { + return std::move ( source ); + } +}; + +template < class ElementType > +struct normalize < ext::deque < ElementType > > { + static ext::deque < alib::Object > eval ( ext::deque < ElementType > && source ) { + ext::deque < alib::Object > res; + + for ( ElementType & element : source ) + res.push_back ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( element ) ) ) ); + + return res; + } +}; + +template < class ElementType > +struct normalize < container::ObjectsDeque < ElementType >, typename std::enable_if < ! std::is_same < container::ObjectsDeque < ElementType >, container::ObjectsDeque < > >::value >::type > { + static container::ObjectsDeque < > eval ( container::ObjectsDeque < ElementType > && value ) { + return container::ObjectsDeque < > ( normalize < ext::deque < ElementType > >::eval ( std::move ( value ) ) ); + } +}; + } /* namespace alib */ #endif /* OBJECTS_DEQUE_H_ */ diff --git a/alib2common/src/container/ObjectsList.h b/alib2common/src/container/ObjectsList.h index 9cbf7e4d0c02d3f64de6f16902d210646576ca0a..2d7808ec1300144a7bd000ee1e303c10fe1304dd 100644 --- a/alib2common/src/container/ObjectsList.h +++ b/alib2common/src/container/ObjectsList.h @@ -16,9 +16,11 @@ #include "ContainerFeatures.h" #include <core/xmlApi.hpp> -#include "../object/UniqueObject.h" +#include <object/UniqueObject.h> #include <object/AnyObject.h> +#include <core/normalize.hpp> + namespace container { /** @@ -61,19 +63,7 @@ public: virtual alib::ObjectBase * inc ( ) &&; - static ext::list < alib::Object > normalizeRaw ( ext::list < ElementType > && source ) { - ext::list < alib::Object > res; - for ( ElementType & element : source ) { - res.push_back ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( element ) ) ) ); - } - return res; - } - typedef ObjectsList < > normalized_type; - - virtual ContainerBase * normalize ( ) && { - return new ObjectsList < alib::Object > ( normalizeRaw ( std::move ( * this ) ) ); - } }; template < class ElementType > @@ -183,6 +173,32 @@ void xmlApi < ext::list < T > >::compose ( ext::deque < sax::Token > & output, c return container::ObjectsList < T >::compose ( output, input ); } +template < > +struct normalize < ext::list < alib::Object > > { + static ext::list < alib::Object > && eval ( ext::list < alib::Object > && source ) { + return std::move ( source ); + } +}; + +template < class ElementType > +struct normalize < ext::list < ElementType > > { + static ext::list < alib::Object > eval ( ext::list < ElementType > && source ) { + ext::list < alib::Object > res; + + for ( ElementType & element : source ) + res.push_back ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( element ) ) ) ); + + return res; + } +}; + +template < class ElementType > +struct normalize < container::ObjectsList < ElementType >, typename std::enable_if < ! std::is_same < container::ObjectsList < ElementType >, container::ObjectsList < > >::value >::type > { + static container::ObjectsList < > eval ( container::ObjectsList < ElementType > && value ) { + return container::ObjectsList < > ( normalize < ext::list < ElementType > >::eval ( std::move ( value ) ) ); + } +}; + } /* namespace alib */ #endif /* OBJECTS_LIST_H_ */ diff --git a/alib2common/src/container/ObjectsMap.h b/alib2common/src/container/ObjectsMap.h index 8e0f38bcdfb6b9cdd4a95a901c5b57e4387b1322..205d3ff644e49db45825620b629fd0af1e081480 100644 --- a/alib2common/src/container/ObjectsMap.h +++ b/alib2common/src/container/ObjectsMap.h @@ -16,11 +16,13 @@ #include "ContainerFeatures.h" #include <core/xmlApi.hpp> -#include "../object/UniqueObject.h" +#include <object/UniqueObject.h> #include <object/AnyObject.h> #include "ObjectsPair.h" +#include <core/normalize.hpp> + namespace container { /** @@ -63,19 +65,7 @@ public: virtual alib::ObjectBase * inc ( ) &&; - static ext::map < alib::Object, alib::Object > normalizeRaw ( ext::map < KeyType, ValueType > && source ) { - ext::map < alib::Object, alib::Object > res; - for ( std::pair < KeyType, ValueType > && element : ext::make_moveable_map ( source ) ) { - res.insert ( ObjectsPair < KeyType, ValueType >::normalizeRaw ( std::move ( element ) ) ); - } - return res; - } - typedef ObjectsMap < > normalized_type; - - virtual ContainerBase * normalize ( ) && { - return new ObjectsMap < alib::Object, alib::Object > ( normalizeRaw ( std::move ( * this ) ) ); - } }; template < class KeyType, class ValueType > @@ -186,6 +176,32 @@ void xmlApi < ext::map < T, R > >::compose ( ext::deque < sax::Token > & output, return container::ObjectsMap < T, R >::compose ( output, input ); } +template < > +struct normalize < ext::map < alib::Object, alib::Object > > { + static ext::map < alib::Object, alib::Object > && eval ( ext::map < alib::Object, alib::Object > && source ) { + return std::move ( source ); + } +}; + +template < class KeyType, class ValueType > +struct normalize < ext::map < KeyType, ValueType > > { + static ext::map < alib::Object, alib::Object > eval ( ext::map < KeyType, ValueType > && source ) { + ext::map < alib::Object, alib::Object > res; + + for ( std::pair < KeyType, ValueType > && element : ext::make_moveable_map ( source ) ) + res.insert ( normalize < std::pair < KeyType, ValueType > >::eval ( std::move ( element ) ) ); + + return res; + } +}; + +template < class KeyType, class ValueType > +struct normalize < container::ObjectsMap < KeyType, ValueType >, typename std::enable_if < ! std::is_same < container::ObjectsMap < KeyType, ValueType >, container::ObjectsMap < > >::value >::type > { + static container::ObjectsMap < > eval ( container::ObjectsMap < KeyType, ValueType > && value ) { + return container::ObjectsMap < > ( normalize < ext::map < KeyType, ValueType > >::eval ( std::move ( value ) ) ); + } +}; + } /* namespace alib */ #endif /* OBJECTS_MAP_H_ */ diff --git a/alib2common/src/container/ObjectsPair.h b/alib2common/src/container/ObjectsPair.h index 6b237194f52a6752605d733ab1332ee6b9c8e413..27ebcdbcdcf3cd5682897cc54b028f76a23fff62 100644 --- a/alib2common/src/container/ObjectsPair.h +++ b/alib2common/src/container/ObjectsPair.h @@ -16,9 +16,11 @@ #include "ContainerFeatures.h" #include <core/xmlApi.hpp> -#include "../object/UniqueObject.h" +#include <object/UniqueObject.h> #include <object/AnyObject.h> +#include <core/normalize.hpp> + namespace container { /** @@ -62,19 +64,7 @@ public: virtual alib::ObjectBase * inc ( ) &&; - static ext::pair < alib::Object, alib::Object > normalizeRaw ( ext::pair < FirstType, SecondType > && source ) { - return ext::make_pair ( alib::Object ( alib::AnyObject < FirstType > ( std::move ( source.first ) ) ), alib::Object ( alib::AnyObject < SecondType > ( std::move ( source.second ) ) ) ); - } - - static std::pair < alib::Object, alib::Object > normalizeRaw ( std::pair < FirstType, SecondType > && source ) { - return std::make_pair ( alib::Object ( alib::AnyObject < FirstType > ( std::move ( source.first ) ) ), alib::Object ( alib::AnyObject < SecondType > ( std::move ( source.second ) ) ) ); - } - typedef ObjectsPair < > normalized_type; - - virtual ContainerBase * normalize ( ) && { - return new ObjectsPair < alib::Object, alib::Object > ( normalizeRaw ( std::move ( * this ) ) ); - } }; template < class FirstType, class SecondType > @@ -195,6 +185,41 @@ void xmlApi < ext::pair < T, R > >::compose ( ext::deque < sax::Token > & output return container::ObjectsPair < T, R >::compose ( output, input ); } +template < > +struct normalize < std::pair < alib::Object, alib::Object > > { + static std::pair < alib::Object, alib::Object > && eval ( std::pair < alib::Object, alib::Object > && source ) { + return std::move ( source ); + } +}; + +template < class FirstType, class SecondType > +struct normalize < std::pair < FirstType, SecondType > > { + static std::pair < alib::Object, alib::Object > eval ( std::pair < FirstType, SecondType > && source ) { + return std::make_pair ( alib::Object ( alib::AnyObject < FirstType > ( std::move ( source.first ) ) ), alib::Object ( alib::AnyObject < SecondType > ( std::move ( source.second ) ) ) ); + } +}; + +template < > +struct normalize < ext::pair < alib::Object, alib::Object > > { + static ext::pair < alib::Object, alib::Object > && eval ( ext::pair < alib::Object, alib::Object > && source ) { + return std::move ( source ); + } +}; + +template < class FirstType, class SecondType > +struct normalize < ext::pair < FirstType, SecondType > > { + static ext::pair < alib::Object, alib::Object > eval ( ext::pair < FirstType, SecondType > && source ) { + return ext::make_pair ( alib::Object ( alib::AnyObject < FirstType > ( std::move ( source.first ) ) ), alib::Object ( alib::AnyObject < SecondType > ( std::move ( source.second ) ) ) ); + } +}; + +template < class FirstType, class SecondType > +struct normalize < container::ObjectsPair < FirstType, SecondType >, typename std::enable_if < ! std::is_same < container::ObjectsPair < FirstType, SecondType >, container::ObjectsPair < > >::value >::type > { + static container::ObjectsPair < > eval ( container::ObjectsPair < FirstType, SecondType > && value ) { + return container::ObjectsPair < > ( normalize < ext::pair < FirstType, SecondType > >::eval ( std::move ( value ) ) ); + } +}; + } /* namespace alib */ #endif /* OBJECTS_PAIR_H_ */ diff --git a/alib2common/src/container/ObjectsSet.h b/alib2common/src/container/ObjectsSet.h index e20bb49d4bb32fc032667f8c0a54088fdca5017f..4eb6d5b910b0078daef45fd5f17076c4af6997a8 100644 --- a/alib2common/src/container/ObjectsSet.h +++ b/alib2common/src/container/ObjectsSet.h @@ -16,9 +16,11 @@ #include "ContainerFeatures.h" #include <core/xmlApi.hpp> -#include "../object/UniqueObject.h" +#include <object/UniqueObject.h> #include <object/AnyObject.h> +#include <core/normalize.hpp> + namespace container { /** @@ -61,19 +63,7 @@ public: virtual alib::ObjectBase * inc ( ) &&; - static ext::set < alib::Object > normalizeRaw ( ext::set < ElementType > && source ) { - ext::set < alib::Object > res; - for ( ElementType && element : ext::make_moveable_set ( source ) ) { - res.insert ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( element ) ) ) ); - } - return res; - } - typedef ObjectsSet < > normalized_type; - - virtual ContainerBase * normalize ( ) && { - return new ObjectsSet < alib::Object > ( normalizeRaw ( std::move ( * this ) ) ); - } }; template < class ElementType > @@ -184,6 +174,32 @@ void xmlApi < ext::set < T > >::compose ( ext::deque < sax::Token > & output, co return container::ObjectsSet < T >::compose ( output, input ); } +template < > +struct normalize < ext::set < alib::Object > > { + static ext::set < alib::Object > && eval ( ext::set < alib::Object > && source ) { + return std::move ( source ); + } +}; + +template < class ElementType > +struct normalize < ext::set < ElementType > > { + static ext::set < alib::Object > eval ( ext::set < ElementType > && source ) { + ext::set < alib::Object > res; + + for ( ElementType && element : ext::make_moveable_set ( source ) ) + res.insert ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( element ) ) ) ); + + return res; + } +}; + +template < class ElementType > +struct normalize < container::ObjectsSet < ElementType >, typename std::enable_if < ! std::is_same < container::ObjectsSet < ElementType >, container::ObjectsSet < > >::value >::type > { + static container::ObjectsSet < > eval ( container::ObjectsSet < ElementType > && value ) { + return container::ObjectsSet < > ( normalize < ext::set < ElementType > >::eval ( std::move ( value ) ) ); + } +}; + } /* namespace alib */ #endif /* OBJECTS_SET_H_ */ diff --git a/alib2common/src/container/ObjectsTree.h b/alib2common/src/container/ObjectsTree.h index 4a742defa975707221d8df62fd9ccc9bf508c285..fb3fefdab27c7ad87cf1cc77c1842171971d0ee0 100644 --- a/alib2common/src/container/ObjectsTree.h +++ b/alib2common/src/container/ObjectsTree.h @@ -16,9 +16,11 @@ #include "ContainerFeatures.h" #include <core/xmlApi.hpp> -#include "../object/UniqueObject.h" +#include <object/UniqueObject.h> #include <object/AnyObject.h> +#include <core/normalize.hpp> + namespace container { /** @@ -60,21 +62,7 @@ public: virtual alib::ObjectBase * inc ( ) &&; - ext::tree < alib::Object > normalizeRaw ( ext::tree < ElementType > && node ) { - ext::vector < ext::tree < alib::Object > > children; - - for ( ext::tree < ElementType > & child : node.getChildren ( ) ) { - children.push_back ( normalizeRaw ( std::move ( child ) ) ); - } - - return ext::tree < alib::Object > ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( node.getData ( ) ) ) ), std::move ( children ) ); - } - typedef ObjectsTree < > normalized_type; - - virtual ContainerBase * normalize ( ) && { - return new ObjectsTree < alib::Object > ( normalizeRaw ( std::move ( * this ) ) ); - } }; template < class ElementType > @@ -219,6 +207,33 @@ void xmlApi < ext::tree < T > >::compose ( ext::deque < sax::Token > & output, c return container::ObjectsTree < T >::compose ( output, input ); } +template < > +struct normalize < ext::tree < alib::Object > > { + static ext::tree < alib::Object > && eval ( ext::tree < alib::Object > && source ) { + return std::move ( source ); + } +}; + +template < class ElementType > +struct normalize < ext::tree < ElementType > > { + static ext::tree < alib::Object > eval ( ext::tree < ElementType > && source ) { + ext::vector < ext::tree < alib::Object > > children; + + for ( ext::tree < ElementType > & child : source.getChildren ( ) ) { + children.push_back ( normalize < ext::tree < ElementType > >::eval ( std::move ( child ) ) ); + } + + return ext::tree < alib::Object > ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( source.getData ( ) ) ) ), std::move ( children ) ); + } +}; + +template < class ElementType > +struct normalize < container::ObjectsTree < ElementType >, typename std::enable_if < ! std::is_same < container::ObjectsTree < ElementType >, container::ObjectsTree < > >::value >::type > { + static container::ObjectsTree < > eval ( container::ObjectsTree < ElementType > && value ) { + return container::ObjectsTree < > ( normalize < ext::tree < ElementType > >::eval ( std::move ( value ) ) ); + } +}; + } /* namespace alib */ #endif /* OBJECTS_TREE_H_ */ diff --git a/alib2common/src/container/ObjectsTrie.h b/alib2common/src/container/ObjectsTrie.h index 89bb303338f896ba5d1e4a1f15bef8f1594b32ec..07bf98015cf29b58cff6becbd63c3caae3b74086 100644 --- a/alib2common/src/container/ObjectsTrie.h +++ b/alib2common/src/container/ObjectsTrie.h @@ -16,9 +16,11 @@ #include "ContainerFeatures.h" #include <core/xmlApi.hpp> -#include "../object/UniqueObject.h" +#include <object/UniqueObject.h> #include <object/AnyObject.h> +#include <core/normalize.hpp> + namespace container { /** @@ -62,21 +64,7 @@ public: virtual alib::ObjectBase * inc ( ) &&; - ext::trie < alib::Object, alib::Object > normalizeRaw ( ext::trie < KeyType, ValueType > && node ) { - ext::map < alib::Object, ext::trie < alib::Object, alib::Object > > children; - - for ( std::pair < KeyType, ext::trie < KeyType, ValueType > > && child : ext::make_moveable_map ( node.getChildren ( ) ) ) { - children.insert ( std::make_pair ( alib::Object ( alib::AnyObject < KeyType > ( std::move ( child.first ) ) ), normalizeRaw ( std::move ( child.second ) ) ) ); - } - - return ext::trie < alib::Object, alib::Object > ( alib::Object ( alib::AnyObject < ValueType > ( std::move ( node.getData ( ) ) ) ), std::move ( children ) ); - } - typedef ObjectsTrie < > normalized_type; - - virtual ContainerBase * normalize ( ) && { - return new ObjectsTrie < alib::Object > ( normalizeRaw ( std::move ( * this ) ) ); - } }; template < class KeyType, class ValueType > @@ -211,6 +199,33 @@ void xmlApi < ext::trie < T, R > >::compose ( ext::deque < sax::Token > & output return container::ObjectsTrie < T, R >::compose ( output, input ); } +template < > +struct normalize < ext::trie < alib::Object, alib::Object > > { + static ext::trie < alib::Object, alib::Object > && eval ( ext::trie < alib::Object, alib::Object > && source ) { + return std::move ( source ); + } +}; + +template < class KeyType, class ValueType > +struct normalize < ext::trie < KeyType, ValueType > > { + static ext::trie < alib::Object, alib::Object > eval ( ext::trie < KeyType, ValueType > && source ) { + ext::map < alib::Object, ext::trie < alib::Object, alib::Object > > children; + + for ( std::pair < KeyType, ext::trie < KeyType, ValueType > > && child : ext::make_moveable_map ( source.getChildren ( ) ) ) { + children.insert ( std::make_pair ( alib::Object ( alib::AnyObject < KeyType > ( std::move ( child.first ) ) ), normalizeRaw ( std::move ( child.second ) ) ) ); + } + + return ext::trie < alib::Object, alib::Object > ( alib::Object ( alib::AnyObject < ValueType > ( std::move ( source.getData ( ) ) ) ), std::move ( children ) ); + } +}; + +template < class KeyType, class ValueType > +struct normalize < container::ObjectsTrie < KeyType, ValueType >, typename std::enable_if < ! std::is_same < container::ObjectsTrie < KeyType, ValueType >, container::ObjectsTrie < > >::value >::type > { + static container::ObjectsTrie < > eval ( container::ObjectsTrie < KeyType, ValueType > && value ) { + return container::ObjectsTrie < > ( normalize < ext::trie < KeyType, ValueType > >::eval ( std::move ( value ) ) ); + } +}; + } /* namespace alib */ #endif /* OBJECTS_TRIE_H_ */ diff --git a/alib2common/src/container/ObjectsVector.h b/alib2common/src/container/ObjectsVector.h index c7b3a214b7504f745785288a07beddc91c457b3f..e92ec41f57afa61a7c8fac2dd144d9699d7f762a 100644 --- a/alib2common/src/container/ObjectsVector.h +++ b/alib2common/src/container/ObjectsVector.h @@ -16,9 +16,11 @@ #include "ContainerFeatures.h" #include <core/xmlApi.hpp> -#include "../object/UniqueObject.h" +#include <object/UniqueObject.h> #include <object/AnyObject.h> +#include <core/normalize.hpp> + namespace container { /** @@ -61,19 +63,7 @@ public: virtual alib::ObjectBase * inc ( ) &&; - static ext::vector < alib::Object > normalizeRaw ( ext::vector < ElementType > && source ) { - ext::vector < alib::Object > res; - for ( ElementType & element : source ) { - res.push_back ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( element ) ) ) ); - } - return res; - } - typedef ObjectsVector < > normalized_type; - - virtual ContainerBase * normalize ( ) && { - return new ObjectsVector < alib::Object > ( normalizeRaw ( std::move ( * this ) ) ); - } }; template < class ElementType > @@ -183,6 +173,32 @@ void xmlApi < ext::vector < T > >::compose ( ext::deque < sax::Token > & output, return container::ObjectsVector < T >::compose ( output, input ); } +template < > +struct normalize < ext::vector < alib::Object > > { + static ext::vector < alib::Object > && eval ( ext::vector < alib::Object > && source ) { + return std::move ( source ); + } +}; + +template < class ElementType > +struct normalize < ext::vector < ElementType > > { + static ext::vector < alib::Object > eval ( ext::vector < ElementType > && source ) { + ext::vector < alib::Object > res; + + for ( ElementType & element : source ) + res.push_back ( alib::Object ( alib::AnyObject < ElementType > ( std::move ( element ) ) ) ); + + return res; + } +}; + +template < class ElementType > +struct normalize < container::ObjectsVector < ElementType >, typename std::enable_if < ! std::is_same < container::ObjectsVector < ElementType >, container::ObjectsVector < > >::value >::type > { + static container::ObjectsVector < > eval ( container::ObjectsVector < ElementType > && value ) { + return container::ObjectsVector < > ( normalize < ext::vector < ElementType > >::eval ( std::move ( value ) ) ); + } +}; + } /* namespace alib */ #endif /* OBJECTS_VECTOR_H_ */ diff --git a/alib2common/src/core/normalize.hpp b/alib2common/src/core/normalize.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4dc6aaa5764c0e55bd0cafd3724bc6afcfc275b4 --- /dev/null +++ b/alib2common/src/core/normalize.hpp @@ -0,0 +1,25 @@ +/* + * normalize.hpp + * + * Created on: Apr 1, 2013 + * Author: Jan Travnicek + */ + +#ifndef NORMALIZE_HPP_ +#define NORMALIZE_HPP_ + +namespace alib { + +template < typename T, typename Enable = void > +struct normalize { }; + +template < typename Type > +struct normalize < Type, typename std::enable_if < std::is_same < Type, typename Type::normalized_type >::value >::type > { + static Type && eval ( Type && value ) { + return std::move ( value ); + } +}; + +} /* namespace alib */ + +#endif /* NORMALIZE_HPP_ */ diff --git a/alib2common/src/exception/CommonException.h b/alib2common/src/exception/CommonException.h index 7434c628c629fe118992230880bd7a7f8f1e6e02..a487a6583f630698c0b36f82bd3719a956c5dac3 100644 --- a/alib2common/src/exception/CommonException.h +++ b/alib2common/src/exception/CommonException.h @@ -81,12 +81,6 @@ public: void compose ( ext::deque < sax::Token > & out ) const; virtual alib::ObjectBase * inc ( ) &&; - - typedef CommonException normalized_type; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace exception */ diff --git a/alib2common/src/object/AnyObject.h b/alib2common/src/object/AnyObject.h index 9b2bbb4d12f1fce7afbf5a2c5fe5e6463cff9307..9f27496822b2d9179598657e21d46ca50087ac3c 100644 --- a/alib2common/src/object/AnyObject.h +++ b/alib2common/src/object/AnyObject.h @@ -53,10 +53,6 @@ public: void compose ( ext::deque < sax::Token > & out ) const; virtual ObjectBase * inc ( ) &&; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; template < class T > diff --git a/alib2common/src/object/ObjectBase.h b/alib2common/src/object/ObjectBase.h index 7fe9fe744ff9719dc5ac81709ec866fff4d408d7..462aba8217cff03742550c15ceac6f2b35a843b9 100644 --- a/alib2common/src/object/ObjectBase.h +++ b/alib2common/src/object/ObjectBase.h @@ -38,11 +38,6 @@ public: * \details Effectively may discard or preserve the instance based on the way how the incrementation can be done. */ virtual ObjectBase * inc() && = 0; - - /** - * @copydoc alib::CommonBase<ObjectBase>::normalize() - */ - virtual ObjectBase * normalize() && override = 0; }; } /* namespace alib */ diff --git a/alib2common/src/object/UniqueObject.h b/alib2common/src/object/UniqueObject.h index 262831382389f9229534f216eeadfa9305384e24..8e98e75a2e0767ecaf99e1cfcd96c9a5f548efec 100644 --- a/alib2common/src/object/UniqueObject.h +++ b/alib2common/src/object/UniqueObject.h @@ -64,10 +64,6 @@ public: void compose ( ext::deque < sax::Token > & out ) const; virtual ObjectBase * inc ( ) &&; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace alib */ diff --git a/alib2common/src/object/Void.h b/alib2common/src/object/Void.h index 317aba435d3ee8bdfe4001297c76b125b7c7663d..9fcc433ae27c5bbcb500c78c8af43b2a17b4dcac 100644 --- a/alib2common/src/object/Void.h +++ b/alib2common/src/object/Void.h @@ -54,10 +54,6 @@ public: void compose ( ext::deque < sax::Token > & out ) const; virtual ObjectBase * inc ( ) &&; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace alib */ diff --git a/alib2common/src/primitive/Bool.h b/alib2common/src/primitive/Bool.h index 7e91b70344df590d5d4dd5f963797fec56b95c86..dba091c389e74ece9296918b788cb4717416d26c 100644 --- a/alib2common/src/primitive/Bool.h +++ b/alib2common/src/primitive/Bool.h @@ -68,12 +68,6 @@ public: static void compose ( ext::deque < sax::Token > & out, bool primitive ); virtual PrimitiveBase * inc ( ) &&; - - typedef Bool normalized_type; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace primitive */ diff --git a/alib2common/src/primitive/Character.h b/alib2common/src/primitive/Character.h index 62814d844e3127a3c2e8e5189c8e54227ea1e380..5975b59bab9b0763aec4db66c26016eaac378457 100644 --- a/alib2common/src/primitive/Character.h +++ b/alib2common/src/primitive/Character.h @@ -68,12 +68,6 @@ public: static void compose ( ext::deque < sax::Token > & out, char primitive ); virtual PrimitiveBase * inc ( ) &&; - - typedef Character normalized_type; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace primitive */ diff --git a/alib2common/src/primitive/Double.h b/alib2common/src/primitive/Double.h index f3c3a2280b3b626c61ce8027b74cf3b85db552f4..deed2e03bc4e63aa5e4977e7d67d3eb5971c73b5 100644 --- a/alib2common/src/primitive/Double.h +++ b/alib2common/src/primitive/Double.h @@ -68,12 +68,6 @@ public: static void compose ( ext::deque < sax::Token > & out, double primitive ); virtual PrimitiveBase * inc ( ) &&; - - typedef Double normalized_type; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace primitive */ diff --git a/alib2common/src/primitive/Integer.h b/alib2common/src/primitive/Integer.h index da6cd69b075ab2339e06205b63aeca087540c5cf..cabceba32fbe2f8c22e05a64a664d7c5b9ab0f5d 100644 --- a/alib2common/src/primitive/Integer.h +++ b/alib2common/src/primitive/Integer.h @@ -68,12 +68,6 @@ public: static void compose ( ext::deque < sax::Token > & out, int primitive ); virtual PrimitiveBase * inc ( ) &&; - - typedef Integer normalized_type; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace primitive */ diff --git a/alib2common/src/primitive/String.h b/alib2common/src/primitive/String.h index 87f7a52d5bf48cc19de5f62083aaaf4aa9f922f3..f95230a8c53932fcd1d7cf56d3515829e4777482 100644 --- a/alib2common/src/primitive/String.h +++ b/alib2common/src/primitive/String.h @@ -69,12 +69,6 @@ public: static void compose ( ext::deque < sax::Token > & out, const std::string & primitive ); virtual PrimitiveBase * inc ( ) &&; - - typedef String normalized_type; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace primitive */ diff --git a/alib2common/src/primitive/Unsigned.h b/alib2common/src/primitive/Unsigned.h index 97ed5d602e71c77540401c8dc660a58a84633cd6..f8e012d8f630bbe922871d24806132178ee913ea 100644 --- a/alib2common/src/primitive/Unsigned.h +++ b/alib2common/src/primitive/Unsigned.h @@ -70,12 +70,6 @@ public: static void compose ( ext::deque < sax::Token > & out, unsigned primitive ); virtual PrimitiveBase * inc ( ) &&; - - typedef Unsigned normalized_type; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace primitive */ diff --git a/alib2common/src/primitive/UnsignedLong.h b/alib2common/src/primitive/UnsignedLong.h index bd4cfbf0829e67bd80011d838d47dda7b759340a..a16181abdcbdf54c6251360a16ad445dcda07373 100644 --- a/alib2common/src/primitive/UnsignedLong.h +++ b/alib2common/src/primitive/UnsignedLong.h @@ -68,12 +68,6 @@ public: static void compose ( ext::deque < sax::Token > & out, unsigned long primitive ); virtual PrimitiveBase * inc ( ) &&; - - typedef UnsignedLong normalized_type; - - virtual ObjectBase * normalize ( ) && { - return this; - } }; } /* namespace primitive */ diff --git a/alib2common/src/registration/NormalizationRegistration.hpp b/alib2common/src/registration/NormalizationRegistration.hpp index 4ea083aa214548f8f6e2cc58323d304c3d3f3c2e..6c5058d41611a12216471a34ba4c7672bcf00c40 100644 --- a/alib2common/src/registration/NormalizationRegistration.hpp +++ b/alib2common/src/registration/NormalizationRegistration.hpp @@ -17,7 +17,7 @@ public: }; template < class ReturnType > -class NormalizationRegister < ReturnType, typename std::enable_if < ext::has_normalize < ReturnType >::value && ! std::is_same < ReturnType, typename ReturnType::normalized_type >::value >::type > { +class NormalizationRegister < ReturnType, typename std::enable_if < ! std::is_same < ReturnType, typename ReturnType::normalized_type >::value >::type > { public: NormalizationRegister ( ) { abstraction::NormalizeRegistry::registerNormalize < ReturnType > ( ); diff --git a/alib2common/test-src/container/ContainerTest.cpp b/alib2common/test-src/container/ContainerTest.cpp index 0de594e5204f7981ede260c40bda2ffd5918a199..faf174c1af4e9f9800418db842e52038cc65a19f 100644 --- a/alib2common/test-src/container/ContainerTest.cpp +++ b/alib2common/test-src/container/ContainerTest.cpp @@ -6,6 +6,7 @@ #include "object/Object.h" #include "container/ObjectsSet.h" +#include "container/ObjectsDeque.h" #include "container/ObjectsVariant.h" #include "container/ObjectsTree.h" #include "container/ObjectsTrie.h" @@ -140,3 +141,13 @@ void ContainerTest::testTrieParsing ( ) { void ContainerTest::testProperties ( ) { CPPUNIT_ASSERT ( std::is_nothrow_move_constructible < container::ObjectsSet < alib::Object > >::value ); } + +void ContainerTest::testNormalize ( ) { + ext::deque < int > dint; + ext::deque < alib::Object > dnor = alib::normalize < ext::deque < int > >::eval ( std::move ( dint ) ); + ext::deque < alib::Object > dnor2 = alib::normalize < ext::deque < alib::Object > >::eval ( std::move ( dnor ) ); + + container::ObjectsDeque < int > Dint; + container::ObjectsDeque < alib::Object > Dnor = alib::normalize < container::ObjectsDeque < int > >::eval ( std::move ( Dint ) ); + container::ObjectsDeque < alib::Object > Dnor2 = alib::normalize < container::ObjectsDeque < alib::Object > >::eval ( std::move ( Dnor ) ); +} diff --git a/alib2common/test-src/container/ContainerTest.h b/alib2common/test-src/container/ContainerTest.h index 1e2a756cca8b3870c1348b27aa6e76a6314e4b59..543a1df8c7cc54e53ef5e9cd3e61d43ee9c19f0e 100644 --- a/alib2common/test-src/container/ContainerTest.h +++ b/alib2common/test-src/container/ContainerTest.h @@ -10,6 +10,7 @@ class ContainerTest : public CppUnit::TestFixture { CPPUNIT_TEST ( testTreeParsing ); CPPUNIT_TEST ( testTrieParsing ); CPPUNIT_TEST ( testProperties ); + CPPUNIT_TEST ( testNormalize ); CPPUNIT_TEST_SUITE_END ( ); public: @@ -21,6 +22,7 @@ public: void testTreeParsing ( ); void testTrieParsing ( ); void testProperties ( ); + void testNormalize ( ); }; #endif // CONTAINER_TEST_H_ diff --git a/alib2data/src/alphabet/BarSymbol.h b/alib2data/src/alphabet/BarSymbol.h index 1ed96e6f4f607cbf1a2da4e1b9d54a7dac10c239..c54191785bae3b52149a8117edde9e1168b0ec96 100644 --- a/alib2data/src/alphabet/BarSymbol.h +++ b/alib2data/src/alphabet/BarSymbol.h @@ -58,10 +58,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef BarSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/alphabet/BlankSymbol.h b/alib2data/src/alphabet/BlankSymbol.h index c6de00c362991ebb977b92df66ed4fe5c2ebe79d..0fc4d35948a0ca8da302039bb9a6dd3d413c6cb1 100644 --- a/alib2data/src/alphabet/BlankSymbol.h +++ b/alib2data/src/alphabet/BlankSymbol.h @@ -58,10 +58,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef BlankSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/alphabet/BottomOfTheStackSymbol.h b/alib2data/src/alphabet/BottomOfTheStackSymbol.h index c6180b293ebc34b8a83feb6d9af70a82e6d21ce8..6d5374fe75eb0c889cff91ef1caaa630d051b41d 100644 --- a/alib2data/src/alphabet/BottomOfTheStackSymbol.h +++ b/alib2data/src/alphabet/BottomOfTheStackSymbol.h @@ -58,10 +58,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef BottomOfTheStackSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/alphabet/EndSymbol.h b/alib2data/src/alphabet/EndSymbol.h index d3c4fca72ca7a80419c0c4434d8b3d350ef741a6..1057fed09fdad814b70441ded2870e6daf844515 100644 --- a/alib2data/src/alphabet/EndSymbol.h +++ b/alib2data/src/alphabet/EndSymbol.h @@ -58,10 +58,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef EndSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/alphabet/InitialSymbol.h b/alib2data/src/alphabet/InitialSymbol.h index 523db64b1d7fd334225e51cfa634de0e595cc34f..02d17812d8ff90583f967487ce34af492fccd5a0 100644 --- a/alib2data/src/alphabet/InitialSymbol.h +++ b/alib2data/src/alphabet/InitialSymbol.h @@ -59,10 +59,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef InitialSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/alphabet/LabeledSymbol.h b/alib2data/src/alphabet/LabeledSymbol.h index 83202e6182c05cd3ed36f5f4b9ef9e42076cb0f4..7c662a6216f6592a61f18cad9a5eb724868ee503 100644 --- a/alib2data/src/alphabet/LabeledSymbol.h +++ b/alib2data/src/alphabet/LabeledSymbol.h @@ -66,10 +66,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef LabeledSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; } /* namespace alphabet */ diff --git a/alib2data/src/alphabet/NonlinearVariableSymbol.h b/alib2data/src/alphabet/NonlinearVariableSymbol.h index 486618095af4d7141998c3f5db97066ff14b8eca..0c792cc0022c1396e3882e8aefa6cb017972a277 100644 --- a/alib2data/src/alphabet/NonlinearVariableSymbol.h +++ b/alib2data/src/alphabet/NonlinearVariableSymbol.h @@ -16,6 +16,8 @@ #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace alphabet { /** @@ -75,13 +77,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef NonlinearVariableSymbol < > normalized_type; - - virtual SymbolBase * normalize ( ) && { - if ( typeid ( NonlinearVariableSymbol < > ) == typeid ( NonlinearVariableSymbol < SymbolType > ) ) - return this; - - return new NonlinearVariableSymbol < > ( SymbolNormalize::normalizeSymbol ( std::move ( this->getSymbol ( ) ) ) ); - } }; template < class SymbolType > @@ -160,4 +155,15 @@ SymbolBase * NonlinearVariableSymbol < SymbolType >::inc ( ) && { } /* namespace alphabet */ +namespace alib { + +template < class SymbolType > +struct normalize < alphabet::NonlinearVariableSymbol < SymbolType >, typename std::enable_if < ! std::is_same < alphabet::NonlinearVariableSymbol < SymbolType >, alphabet::NonlinearVariableSymbol < > >::value >::type > { + static alphabet::NonlinearVariableSymbol < > eval ( alphabet::NonlinearVariableSymbol < SymbolType > && value ) { + return alphabet::NonlinearVariableSymbol < > ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getSymbol ( ) ) ); + } +}; + +} /* namespace alib */ + #endif /* NONLINEAR_VARIABLE_SYMBOL_H_ */ diff --git a/alib2data/src/alphabet/RankedSymbol.h b/alib2data/src/alphabet/RankedSymbol.h index 5b80bcda56e6fde3e764172104c0e92f7fb43748..f6c62f39e8869d39ab254987b517fd9c82f582ed 100644 --- a/alib2data/src/alphabet/RankedSymbol.h +++ b/alib2data/src/alphabet/RankedSymbol.h @@ -17,6 +17,8 @@ #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace alphabet { /** @@ -66,18 +68,7 @@ public: virtual SymbolBase * inc ( ) &&; - common::ranked_symbol < DefaultSymbolType, DefaultRankType > normalizeRaw ( common::ranked_symbol < SymbolType, RankType > && source ) { - return common::ranked_symbol < DefaultSymbolType, DefaultRankType > ( SymbolNormalize::normalizeSymbol ( std::move ( source.getSymbol ( ) ) ), DefaultRankType ( std::move ( source.getRank ( ) ) ) ); - } - typedef RankedSymbol < > normalized_type; - - virtual SymbolBase * normalize ( ) && { - if ( typeid ( RankedSymbol < > ) == typeid ( RankedSymbol < SymbolType, RankType > ) ) - return this; - - return new RankedSymbol < > ( normalizeRaw ( std::move ( *this ) ) ); - } }; template < class SymbolType, class RankType > @@ -170,6 +161,27 @@ void xmlApi < common::ranked_symbol < T, R > >::compose ( ext::deque < sax::Toke return alphabet::RankedSymbol < T, R >::compose( output, input ); } +template < class SymbolType, class RankType > +struct normalize < common::ranked_symbol < SymbolType, RankType >, typename std::enable_if < std::is_same < common::ranked_symbol < SymbolType, RankType >, common::ranked_symbol < > >::value >::type > { + static common::ranked_symbol < > && eval ( common::ranked_symbol < SymbolType, RankType > && value ) { + return std::move ( value ); + } +}; + +template < class SymbolType, class RankType > +struct normalize < common::ranked_symbol < SymbolType, RankType >, typename std::enable_if < ! std::is_same < common::ranked_symbol < SymbolType, RankType >, common::ranked_symbol < > >::value >::type > { + static common::ranked_symbol < > eval ( common::ranked_symbol < SymbolType, RankType > && value ) { + return alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( value ) ); + } +}; + +template < class SymbolType, class RankType > +struct normalize < alphabet::RankedSymbol < SymbolType, RankType >, typename std::enable_if < ! std::is_same < alphabet::RankedSymbol < SymbolType, RankType >, alphabet::RankedSymbol < > >::value >::type > { + static alphabet::RankedSymbol < > eval ( alphabet::RankedSymbol < SymbolType, RankType > && value ) { + return alphabet::RankedSymbol < > ( normalize < common::ranked_symbol < SymbolType, RankType > >::eval ( std::move ( value ) ) ); + } +}; + } /* namespace alib */ #endif /* RANKED_SYMBOL_H_ */ diff --git a/alib2data/src/alphabet/StartSymbol.h b/alib2data/src/alphabet/StartSymbol.h index eaaa9a9c94a02b561e068db07cef1147e16a198b..fc5e5e3e89092a5cad326cd93486fa200e5046a8 100644 --- a/alib2data/src/alphabet/StartSymbol.h +++ b/alib2data/src/alphabet/StartSymbol.h @@ -58,10 +58,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef StartSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/alphabet/SubtreeWildcardSymbol.h b/alib2data/src/alphabet/SubtreeWildcardSymbol.h index f76fa44fab73db1d503b59d7f3fb56b50cc879de..f03139f48d695a19ee1a0d2cb95ab8e8c8e470c9 100644 --- a/alib2data/src/alphabet/SubtreeWildcardSymbol.h +++ b/alib2data/src/alphabet/SubtreeWildcardSymbol.h @@ -59,10 +59,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef SubtreeWildcardSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/alphabet/SymbolBase.h b/alib2data/src/alphabet/SymbolBase.h index ee2959782f441e6f5a8c98e0e47d09b052821f48..031a52ac77c148d130903f3bf69cdd55a93120d6 100644 --- a/alib2data/src/alphabet/SymbolBase.h +++ b/alib2data/src/alphabet/SymbolBase.h @@ -21,8 +21,6 @@ public: virtual SymbolBase* plunder() && = 0; virtual SymbolBase* inc() && = 0; - - virtual SymbolBase* normalize ( ) && = 0; }; } /* namespace alphabet */ diff --git a/alib2data/src/alphabet/UniqueSymbol.h b/alib2data/src/alphabet/UniqueSymbol.h index 78f6b50fcea07c807a045e601fac1466f2648d83..4e19aab36c8e440588b42101242ff9b855f72bdc 100644 --- a/alib2data/src/alphabet/UniqueSymbol.h +++ b/alib2data/src/alphabet/UniqueSymbol.h @@ -68,10 +68,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef UniqueSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; } /* namespace alphabet */ diff --git a/alib2data/src/alphabet/VariablesBarSymbol.h b/alib2data/src/alphabet/VariablesBarSymbol.h index 0608d7181ec0ca312cb3927c2e7b741718c944f3..b5d0420f14239cd8bd71ff84b73b93f10f95547a 100644 --- a/alib2data/src/alphabet/VariablesBarSymbol.h +++ b/alib2data/src/alphabet/VariablesBarSymbol.h @@ -59,10 +59,6 @@ public: virtual SymbolBase * inc ( ) &&; typedef VariablesBarSymbol normalized_type; - - virtual SymbolBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/automaton/AutomatonBase.h b/alib2data/src/automaton/AutomatonBase.h index 946e49378828f0b5da4359cbc5db695f12533373..ed17dc3f051bb0ca0854f15f56d578725bb97c1c 100644 --- a/alib2data/src/automaton/AutomatonBase.h +++ b/alib2data/src/automaton/AutomatonBase.h @@ -19,8 +19,6 @@ class AutomatonBase : public alib::ObjectBase { public: virtual AutomatonBase* clone() const = 0; virtual AutomatonBase* plunder() && = 0; - - virtual AutomatonBase* normalize ( ) && = 0; }; } /* namespace automaton */ diff --git a/alib2data/src/automaton/FSM/CompactNFA.h b/alib2data/src/automaton/FSM/CompactNFA.h index 4ac6348d0db614cc9896b3126ac286cf3a6d6d76..563aca9bc119e37ed1fffdd9be87cf5324fb6270 100644 --- a/alib2data/src/automaton/FSM/CompactNFA.h +++ b/alib2data/src/automaton/FSM/CompactNFA.h @@ -44,6 +44,8 @@ #include "../../label/InitialStateLabel.h" +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -471,33 +473,6 @@ public: * Type of normalized automaton. */ typedef CompactNFA < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. - * - * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones - */ - virtual AutomatonBase * normalize ( ) && override { - if ( typeid ( CompactNFA < > ) == typeid ( CompactNFA < SymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - CompactNFA < > * res = new CompactNFA < > ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, ext::vector < SymbolType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( transitions ) ) { - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - ext::vector < DefaultSymbolType > input = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( transition.first.second ) ); - ext::set < DefaultStateType > targets = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - res->addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); - } - - return res; - } }; } /* namespace automaton */ @@ -927,6 +902,33 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class SymbolType, class StateType > +struct normalize < automaton::CompactNFA < SymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::CompactNFA < SymbolType, StateType >, automaton::CompactNFA < > >::value >::type > { + static automaton::CompactNFA < > eval ( automaton::CompactNFA < SymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::CompactNFA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, ext::vector < SymbolType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + ext::vector < DefaultSymbolType > input = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( transition.first.second ) ); + ext::set < DefaultStateType > targets = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* COMPACT_DFA_H_ */ diff --git a/alib2data/src/automaton/FSM/DFA.h b/alib2data/src/automaton/FSM/DFA.h index 6052f22bba0f53a4250e151cda38732db59c26be..78ee0f8922da049d141a9459bff59b93c6ec68a4 100644 --- a/alib2data/src/automaton/FSM/DFA.h +++ b/alib2data/src/automaton/FSM/DFA.h @@ -41,6 +41,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -437,33 +439,6 @@ public: * Type of normalized automaton. */ typedef DFA < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. - * - * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones - */ - virtual AutomatonBase * normalize ( ) && override { - if ( typeid ( DFA < > ) == typeid ( DFA < SymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - DFA < > * res = new DFA < > ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, SymbolType >, StateType > && transition : ext::make_moveable_map ( transitions ) ) { - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); - - res->addTransition ( std::move ( from ), std::move ( input ), std::move ( to ) ); - } - - return res; - } }; template<class SymbolType, class StateType > @@ -864,6 +839,33 @@ public: }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class SymbolType, class StateType > +struct normalize < automaton::DFA < SymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::DFA < SymbolType, StateType >, automaton::DFA < > >::value >::type > { + static automaton::DFA < > eval ( automaton::DFA < SymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::DFA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, SymbolType >, StateType > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); + + res.addTransition ( std::move ( from ), std::move ( input ), std::move ( to ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* DFA_H_ */ diff --git a/alib2data/src/automaton/FSM/EpsilonNFA.h b/alib2data/src/automaton/FSM/EpsilonNFA.h index 87958d35d908aba0ea999d84de94f8a13a7d7da8..92c43c146ea131e79a0ba74431f01ecd1c7fce0a 100644 --- a/alib2data/src/automaton/FSM/EpsilonNFA.h +++ b/alib2data/src/automaton/FSM/EpsilonNFA.h @@ -44,6 +44,8 @@ #include "../../label/InitialStateLabel.h" +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -607,33 +609,6 @@ public: * Type of normalized automaton. */ typedef EpsilonNFA < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. - * - * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones - */ - virtual AutomatonBase * normalize ( ) && override { - if ( typeid ( EpsilonNFA < > ) == typeid ( EpsilonNFA < SymbolType, EpsilonType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - EpsilonNFA < > * res = new EpsilonNFA < > ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, SymbolType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( transitions ) ) { - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); - ext::set < DefaultStateType > targets = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - res->addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); - } - - return res; - } }; } /* namespace automaton */ @@ -1186,6 +1161,33 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template<class SymbolType, class EpsilonType, class StateType > +struct normalize < automaton::EpsilonNFA < SymbolType, EpsilonType, StateType >, typename std::enable_if < ! std::is_same < automaton::EpsilonNFA < SymbolType, EpsilonType, StateType >, automaton::EpsilonNFA < > >::value >::type > { + static automaton::EpsilonNFA < > eval ( automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::EpsilonNFA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, SymbolType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); + ext::set < DefaultStateType > targets = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* EPSILON_NFA_H_ */ diff --git a/alib2data/src/automaton/FSM/ExtendedNFA.h b/alib2data/src/automaton/FSM/ExtendedNFA.h index 9d6901d09d5c40db4371723c24054826b3589656..8ae76b2fa4f7c1096e9eb726e4535669a87b5540 100644 --- a/alib2data/src/automaton/FSM/ExtendedNFA.h +++ b/alib2data/src/automaton/FSM/ExtendedNFA.h @@ -47,6 +47,8 @@ #include "../../regexp/unbounded/UnboundedRegExpConcatenation.h" #include "../../regexp/unbounded/UnboundedRegExpSymbol.h" +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -481,33 +483,6 @@ public: * Type of normalized automaton. */ typedef ExtendedNFA < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. - * - * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones - */ - virtual AutomatonBase * normalize ( ) && override { - if ( typeid ( ExtendedNFA < > ) == typeid ( ExtendedNFA < SymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - ExtendedNFA < > * res = new ExtendedNFA < > ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( transitions ) ) { - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - regexp::UnboundedRegExpStructure < DefaultSymbolType > input = AutomatonNormalize::normalizeRegExp ( std::move ( transition.first.second ) ); - ext::set < DefaultStateType > targets = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - res->addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); - } - - return res; - } }; } /* namespace automaton */ @@ -951,6 +926,33 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class SymbolType, class StateType > +struct normalize < automaton::ExtendedNFA < SymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::ExtendedNFA < SymbolType, StateType >, automaton::ExtendedNFA < > >::value >::type > { + static automaton::ExtendedNFA < > eval ( automaton::ExtendedNFA < SymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::ExtendedNFA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, regexp::UnboundedRegExpStructure < SymbolType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + regexp::UnboundedRegExpStructure < DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeRegExp ( std::move ( transition.first.second ) ); + ext::set < DefaultStateType > targets = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* EXTENDED_NFA_H_ */ diff --git a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h index 23987f3de3574e63c4ff25420d16d1044a422f3b..909ccae23b9508ee5955177c91edc9b6fc8d396a 100644 --- a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h +++ b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h @@ -40,6 +40,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -499,33 +501,6 @@ public: * Type of normalized automaton. */ typedef MultiInitialStateNFA < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. - * - * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones - */ - virtual AutomatonBase * normalize ( ) && override { - if ( typeid ( MultiInitialStateNFA < > ) == typeid ( MultiInitialStateNFA < SymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - ext::set < DefaultStateType > initialStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < InitialStates > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - MultiInitialStateNFA < > * res = new MultiInitialStateNFA < > ( std::move ( states ), std::move ( alphabet ), std::move ( initialStates ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, SymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( transitions ) ) { - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - ext::set < DefaultStateType > targets = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - res->addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); - } - - return res; - } }; } /* namespace automaton */ @@ -953,6 +928,33 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class SymbolType, class StateType > +struct normalize < automaton::MultiInitialStateNFA < SymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::MultiInitialStateNFA < SymbolType, StateType >, automaton::MultiInitialStateNFA < > >::value >::type > { + static automaton::MultiInitialStateNFA < > eval ( automaton::MultiInitialStateNFA < SymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + ext::set < DefaultStateType > initialStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getInitialStates ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::MultiInitialStateNFA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( initialStates ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, SymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + ext::set < DefaultStateType > targets = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* MULTI_INITIAL_STATE_NFA_H_ */ diff --git a/alib2data/src/automaton/FSM/NFA.h b/alib2data/src/automaton/FSM/NFA.h index 947249bd592dbe9f2d7a024af5c84204df153138..21aa17dbfa93734b839584f063e7ebfff5b5ccaf 100644 --- a/alib2data/src/automaton/FSM/NFA.h +++ b/alib2data/src/automaton/FSM/NFA.h @@ -38,6 +38,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -469,33 +471,6 @@ public: * Type of normalized automaton. */ typedef NFA < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. - * - * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones - */ - virtual AutomatonBase * normalize ( ) && override { - if ( typeid ( NFA < > ) == typeid ( NFA < SymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - NFA < > * res = new NFA < > ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, SymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( transitions ) ) { - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - ext::set < DefaultStateType > targets = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - res->addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); - } - - return res; - } }; } /* namespace automaton */ @@ -903,6 +878,33 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class SymbolType, class StateType > +struct normalize < automaton::NFA < SymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::NFA < SymbolType, StateType >, automaton::NFA < > >::value >::type > { + static automaton::NFA < > eval ( automaton::NFA < SymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::NFA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, SymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + ext::set < DefaultStateType > targets = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* NFA_H_ */ diff --git a/alib2data/src/automaton/PDA/DPDA.h b/alib2data/src/automaton/PDA/DPDA.h index 7850560e86e8a28748e2c063da06101ff3f3bde8..430276a43db390c5c0b1309b6cee6cb8dd0581dd 100644 --- a/alib2data/src/automaton/PDA/DPDA.h +++ b/alib2data/src/automaton/PDA/DPDA.h @@ -27,6 +27,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -238,33 +240,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef DPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( DPDA < > ) == typeid ( DPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - DPDA < > * res = new DPDA < > ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > && transition : ext::make_moveable_map ( transitions ) ) { - ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( transition.first ) ) ); - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); - - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) ); - ext::vector < DefaultSymbolType > push = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( transition.second.second ) ); - - res->addTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ), std::move ( push ) ); - } - - return res; - } }; template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > @@ -663,6 +638,38 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::DPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::DPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, automaton::DPDA < > >::value >::type > { + static automaton::DPDA < > eval ( automaton::DPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::DPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( transition.first ) ) ); + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); + + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) ); + ext::vector < DefaultSymbolType > push = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( transition.second.second ) ); + + res.addTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ), std::move ( push ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/InputDrivenDPDA.h b/alib2data/src/automaton/PDA/InputDrivenDPDA.h index 647f848374c05081f47fc9456e90ff6bbc8fe874..c08f30e61b9842999f9494bbdd664d05ce9b3465 100644 --- a/alib2data/src/automaton/PDA/InputDrivenDPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenDPDA.h @@ -26,6 +26,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -241,39 +243,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef InputDrivenDPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( InputDrivenDPDA < > ) == typeid ( InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - InputDrivenDPDA < > * res = new InputDrivenDPDA < > ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); - - for ( std::pair < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > && pushdownOperation : ext::make_moveable_map ( inputSymbolToPushdownStoreOperation ) ) { - DefaultSymbolType target = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( pushdownOperation.first ) ); - ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( pushdownOperation.second.first ) ); - ext::vector < DefaultSymbolType > push = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( pushdownOperation.second.second ) ); - - res->setPushdownStoreOperation ( std::move ( target ), std::move ( pop ), std::move ( push ) ); - } - - for ( std::pair < ext::pair < StateType, InputSymbolType >, StateType > && transition : ext::make_moveable_map ( transitions ) ) { - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); - - res->addTransition ( std::move ( from ), std::move ( input ), std::move ( to ) ); - } - - return res; - } }; template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > @@ -648,6 +617,44 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, automaton::InputDrivenDPDA < > >::value >::type > { + static automaton::InputDrivenDPDA < > eval ( automaton::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::InputDrivenDPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > && pushdownOperation : ext::make_moveable_map ( std::move ( value ).getPushdownStoreOperations ( ) ) ) { + DefaultSymbolType target = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( pushdownOperation.first ) ); + ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( pushdownOperation.second.first ) ); + ext::vector < DefaultSymbolType > push = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( pushdownOperation.second.second ) ); + + res.setPushdownStoreOperation ( std::move ( target ), std::move ( pop ), std::move ( push ) ); + } + + for ( std::pair < ext::pair < StateType, InputSymbolType >, StateType > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); + + res.addTransition ( std::move ( from ), std::move ( input ), std::move ( to ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* INPUT_DRIVEN_DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/InputDrivenNPDA.h b/alib2data/src/automaton/PDA/InputDrivenNPDA.h index 1217f9353bb33cce76acc77ee4e3c442a1fc364c..878faaf6d8759b74652a0fe9b235655cc637a1d5 100644 --- a/alib2data/src/automaton/PDA/InputDrivenNPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenNPDA.h @@ -26,6 +26,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -250,39 +252,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef InputDrivenNPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( InputDrivenNPDA < > ) == typeid ( InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - InputDrivenNPDA < > * res = new InputDrivenNPDA < > ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); - - for ( std::pair < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > && pushdownOperation : ext::make_moveable_map ( inputSymbolToPushdownStoreOperation ) ) { - DefaultSymbolType target = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( pushdownOperation.first ) ); - ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( pushdownOperation.second.first ) ); - ext::vector < DefaultSymbolType > push = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( pushdownOperation.second.second ) ); - - res->setPushdownStoreOperation ( std::move ( target ), std::move ( pop ), std::move ( push ) ); - } - - for ( std::pair < ext::pair < StateType, InputSymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( transitions ) ) { - ext::set < DefaultStateType > targets = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - - res->addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); - } - - return res; - } }; template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > @@ -673,6 +642,44 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, automaton::InputDrivenNPDA < > >::value >::type > { + static automaton::InputDrivenNPDA < > eval ( automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::InputDrivenNPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > && pushdownOperation : ext::make_moveable_map ( std::move ( value ).getPushdownStoreOperations ( ) ) ) { + DefaultSymbolType target = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( pushdownOperation.first ) ); + ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( pushdownOperation.second.first ) ); + ext::vector < DefaultSymbolType > push = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( pushdownOperation.second.second ) ); + + res.setPushdownStoreOperation ( std::move ( target ), std::move ( pop ), std::move ( push ) ); + } + + for ( std::pair < ext::pair < StateType, InputSymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + ext::set < DefaultStateType > targets = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* INPUT_DRIVEN_NPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/NPDA.h b/alib2data/src/automaton/PDA/NPDA.h index 1f5b6b68a3d03db0d09f0133bc0efe14d7eeab22..5255b460918cfe91df70551872126fab9aaea7b0 100644 --- a/alib2data/src/automaton/PDA/NPDA.h +++ b/alib2data/src/automaton/PDA/NPDA.h @@ -27,6 +27,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -236,34 +238,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef NPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( NPDA < > ) == typeid ( NPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - NPDA < > * res = new NPDA < > ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > > && transition : ext::make_moveable_map ( transitions ) ) { - ext::set < ext::pair < DefaultStateType, ext::vector < DefaultSymbolType > > > targets; - for ( std::pair < StateType, ext::vector < PushdownStoreSymbolType > > && target : ext::make_moveable_set ( transition.second ) ) - targets.insert ( ext::make_pair ( AutomatonNormalize::normalizeState ( std::move ( target.first ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target.second ) ) ) ); - - ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( transition.first ) ) ); - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - ext::variant < DefaultEpsilonType, DefaultStateType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); - - res->addTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); - } - - return res; - } }; template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > @@ -611,6 +585,39 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::NPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::NPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, automaton::NPDA < > >::value >::type > { + static automaton::NPDA < > eval ( automaton::NPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::NPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + ext::set < ext::pair < DefaultStateType, ext::vector < DefaultSymbolType > > > targets; + for ( std::pair < StateType, ext::vector < PushdownStoreSymbolType > > && target : ext::make_moveable_set ( transition.second ) ) + targets.insert ( ext::make_pair ( automaton::AutomatonNormalize::normalizeState ( std::move ( target.first ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target.second ) ) ) ); + + ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( transition.first ) ) ); + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + ext::variant < DefaultEpsilonType, DefaultStateType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* NPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/NPDTA.h b/alib2data/src/automaton/PDA/NPDTA.h index 2b1369d6f0e92a6963fa2f37a7d32613edf9012e..f0b034573fbafbcf656d00a75104402843465692 100644 --- a/alib2data/src/automaton/PDA/NPDTA.h +++ b/alib2data/src/automaton/PDA/NPDTA.h @@ -27,6 +27,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -260,35 +262,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef NPDTA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( NPDTA < > ) == typeid ( NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > outputAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < OutputAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - NPDTA < > * res = new NPDTA < > ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( outputAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > && transition : ext::make_moveable_map ( transitions ) ) { - ext::set < ext::tuple < DefaultStateType, ext::vector < DefaultSymbolType >, ext::vector < DefaultSymbolType > > > targets; - for ( ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > && target : ext::make_moveable_set ( transition.second ) ) - targets.insert ( ext::make_tuple ( AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( target ) ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 1 > ( target ) ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( target ) ) ) ) ); - - ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( transition.first ) ) ); - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); - - res->addTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); - } - - return res; - } }; template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > @@ -698,6 +671,41 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, automaton::NPDTA < > >::value >::type > { + static automaton::NPDTA < > eval ( automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > outputAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getOutputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::NPDTA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( outputAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + ext::set < ext::tuple < DefaultStateType, ext::vector < DefaultSymbolType >, ext::vector < DefaultSymbolType > > > targets; + for ( ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > && target : ext::make_moveable_set ( transition.second ) ) + targets.insert ( ext::make_tuple ( automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( target ) ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 1 > ( target ) ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( target ) ) ) ) ); + + ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( transition.first ) ) ); + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); + } + + return res; + } +}; + + } /* namespace alib */ #endif /* NPDTA_H_ */ diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h index ef513bd11a8bb6a1adca24948f287521ad38f8ee..a9b3e09a798b47f585f57c9dc42d14d8ede67760 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h @@ -26,6 +26,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -265,50 +267,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef RealTimeHeightDeterministicDPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( RealTimeHeightDeterministicDPDA < > ) == typeid ( RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType bottomSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < BottomOfTheStackSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - RealTimeHeightDeterministicDPDA < > * res = new RealTimeHeightDeterministicDPDA < > ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( bottomSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, InputSymbolType > >, ext::pair < StateType, PushdownStoreSymbolType > > && transition : ext::make_moveable_map ( callTransitions ) ) { - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) ); - DefaultSymbolType push = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.second.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); - - res->addCallTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( push ) ); - } - - for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, StateType > && transition : ext::make_moveable_map ( returnTransitions ) ) { - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); - DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); - - res->addReturnTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) ); - } - - for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, InputSymbolType > >, StateType > && transition : ext::make_moveable_map ( localTransitions ) ) { - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); - res->addLocalTransition ( std::move ( from ), std::move ( input ), std::move ( to ) ); - } - - return res; - } }; template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > @@ -900,6 +858,55 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, automaton::RealTimeHeightDeterministicDPDA < > >::value >::type > { + static automaton::RealTimeHeightDeterministicDPDA < > eval ( automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::RealTimeHeightDeterministicDPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, InputSymbolType > >, ext::pair < StateType, PushdownStoreSymbolType > > && transition : ext::make_moveable_map ( std::move ( value ).getCallTransitions ( ) ) ) { + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) ); + DefaultSymbolType push = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.second.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); + + res.addCallTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( push ) ); + } + + for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, StateType > && transition : ext::make_moveable_map ( std::move ( value ).getReturnTransitions ( ) ) ) { + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); + DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); + + res.addReturnTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) ); + } + + for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, InputSymbolType > >, StateType > && transition : ext::make_moveable_map ( std::move ( value ).getLocalTransitions ( ) ) ) { + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); + res.addLocalTransition ( std::move ( from ), std::move ( input ), std::move ( to ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* REAL_TIME_HEIGHT_DETERMINISTIC_DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h index 39377f3b90acd538bf890b393bbaef07842ae8f2..8ab10aadd6189e54379ada119eaff0ddece67048 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h @@ -26,6 +26,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -306,51 +308,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef RealTimeHeightDeterministicNPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( RealTimeHeightDeterministicNPDA < > ) == typeid ( RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType bottomSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < BottomOfTheStackSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - ext::set < DefaultStateType > initialStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < InitialStates > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - RealTimeHeightDeterministicNPDA < > * res = new RealTimeHeightDeterministicNPDA < > ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialStates ), std::move ( bottomSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, PushdownStoreSymbolType > > > && transition : ext::make_moveable_map ( callTransitions ) ) { - ext::set < ext::pair < DefaultStateType, DefaultSymbolType > > targets; - for ( std::pair < StateType, PushdownStoreSymbolType > && target : ext::make_moveable_set ( transition.second ) ) - targets.insert ( ext::make_pair ( AutomatonNormalize::normalizeState ( std::move ( target.first ) ), alphabet::SymbolNormalize::normalizeSymbol ( std::move ( target.second ) ) ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); - res->addCallTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); - } - - for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( returnTransitions ) ) { - ext::set < DefaultStateType > targets = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); - - res->addReturnTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); - } - - for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, InputSymbolType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( localTransitions ) ) { - ext::set < DefaultStateType > targets = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); - - res->addLocalTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); - } - - return res; - } }; template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > @@ -944,6 +901,56 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, automaton::RealTimeHeightDeterministicNPDA < > >::value >::type > { + static automaton::RealTimeHeightDeterministicNPDA < > eval ( automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + ext::set < DefaultStateType > initialStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getInitialStates ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::RealTimeHeightDeterministicNPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialStates ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, PushdownStoreSymbolType > > > && transition : ext::make_moveable_map ( std::move ( value ).getCallTransitions ( ) ) ) { + ext::set < ext::pair < DefaultStateType, DefaultSymbolType > > targets; + for ( std::pair < StateType, PushdownStoreSymbolType > && target : ext::make_moveable_set ( transition.second ) ) + targets.insert ( ext::make_pair ( automaton::AutomatonNormalize::normalizeState ( std::move ( target.first ) ), alphabet::SymbolNormalize::normalizeSymbol ( std::move ( target.second ) ) ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); + res.addCallTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); + } + + for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getReturnTransitions ( ) ) ) { + ext::set < DefaultStateType > targets = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); + + res.addReturnTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); + } + + for ( std::pair < ext::pair < StateType, ext::variant < EpsilonType, InputSymbolType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getLocalTransitions ( ) ) ) { + ext::set < DefaultStateType > targets = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( transition.first.second ) ); + + res.addLocalTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* REAL_TIME_HEIGHT_DETERMINISTIC_NPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/SinglePopDPDA.h b/alib2data/src/automaton/PDA/SinglePopDPDA.h index 90a525d9ba06824a047fce5f2d09314da7864ea1..0d32f6a8de364d36b9b7a5f2df37def1fd75c9a3 100644 --- a/alib2data/src/automaton/PDA/SinglePopDPDA.h +++ b/alib2data/src/automaton/PDA/SinglePopDPDA.h @@ -28,6 +28,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -226,33 +228,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef SinglePopDPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( SinglePopDPDA < > ) == typeid ( SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType bottomSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - SinglePopDPDA < > * res = new SinglePopDPDA < > ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( bottomSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > && transition : ext::make_moveable_map ( transitions ) ) { - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) ); - ext::vector < DefaultSymbolType > push = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( transition.second.second ) ); - - DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); - - res->addTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ), std::move ( push ) ); - } - - return res; - } }; template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > @@ -588,6 +563,38 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, automaton::SinglePopDPDA < > >::value >::type > { + static automaton::SinglePopDPDA < > eval ( automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::SinglePopDPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) ); + ext::vector < DefaultSymbolType > push = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( transition.second.second ) ); + + DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); + + res.addTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ), std::move ( push ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* SINGLE_POP_DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/SinglePopNPDA.h b/alib2data/src/automaton/PDA/SinglePopNPDA.h index 585b3e95a9bbd33ee09cc4864f8775fd854d813b..71df2b6463ed1a0ca8e1f14a808345af4b459fd4 100644 --- a/alib2data/src/automaton/PDA/SinglePopNPDA.h +++ b/alib2data/src/automaton/PDA/SinglePopNPDA.h @@ -27,6 +27,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -233,34 +235,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef SinglePopNPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( SinglePopNPDA < > ) == typeid ( SinglePopNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType bottomSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - SinglePopNPDA < > * res = new SinglePopNPDA < > ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( bottomSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, ext::set < ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > > && transition : ext::make_moveable_map ( transitions ) ) { - ext::set < ext::pair < DefaultStateType, ext::vector < DefaultSymbolType > > > targets; - for ( std::pair < StateType, ext::vector < PushdownStoreSymbolType > > && target : ext::make_moveable_set ( transition.second ) ) - targets.insert ( ext::make_pair ( AutomatonNormalize::normalizeState ( std::move ( target.first ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target.second ) ) ) ); - - DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); - - res->addTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); - } - - return res; - } }; template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > @@ -611,6 +585,39 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::SinglePopNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::SinglePopNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, automaton::SinglePopNPDA < > >::value >::type > { + static automaton::SinglePopNPDA < > eval ( automaton::SinglePopNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::SinglePopNPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, ext::set < ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + ext::set < ext::pair < DefaultStateType, ext::vector < DefaultSymbolType > > > targets; + for ( std::pair < StateType, ext::vector < PushdownStoreSymbolType > > && target : ext::make_moveable_set ( transition.second ) ) + targets.insert ( ext::make_pair ( automaton::AutomatonNormalize::normalizeState ( std::move ( target.first ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target.second ) ) ) ); + + DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* SINGLE_POP_NPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h b/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h index b9d6084e0963494a03ffee683d4baa3f283017dd..4027b3a35e966887c8e7b2b9deb3e85f413f105c 100644 --- a/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h +++ b/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h @@ -25,6 +25,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class CallAlphabet; @@ -306,53 +308,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef VisiblyPushdownDPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( VisiblyPushdownDPDA < > ) == typeid ( VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > call_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < CallAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > return_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < ReturnAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > local_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < LocalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType bottomSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < BottomOfTheStackSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - VisiblyPushdownDPDA < > * res = new VisiblyPushdownDPDA < > ( std::move ( states ), std::move ( call_alphabet ), std::move ( return_alphabet ), std::move ( local_alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( bottomSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, InputSymbolType >, ext::pair < StateType, PushdownStoreSymbolType > > && transition : ext::make_moveable_map ( callTransitions ) ) { - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) ); - DefaultSymbolType push = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.second.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - - res->addCallTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( push ) ); - } - - for ( std::pair < ext::tuple < StateType, InputSymbolType, PushdownStoreSymbolType >, StateType > && transition : ext::make_moveable_map ( returnTransitions ) ) { - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( transition.first ) ) ); - DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); - - res->addReturnTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) ); - } - - for ( std::pair < ext::pair < StateType, InputSymbolType >, StateType > && transition : ext::make_moveable_map ( localTransitions ) ) { - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - - res->addLocalTransition ( std::move ( from ), std::move ( input ), std::move ( to ) ); - } - - return res; - } }; template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > @@ -877,6 +832,58 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, automaton::VisiblyPushdownDPDA < > >::value >::type > { + static automaton::VisiblyPushdownDPDA < > eval ( automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > call_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getCallAlphabet ( ) ); + ext::set < DefaultSymbolType > return_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getReturnAlphabet ( ) ); + ext::set < DefaultSymbolType > local_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getLocalAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::VisiblyPushdownDPDA < > res ( std::move ( states ), std::move ( call_alphabet ), std::move ( return_alphabet ), std::move ( local_alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, InputSymbolType >, ext::pair < StateType, PushdownStoreSymbolType > > && transition : ext::make_moveable_map ( std::move ( value ).getCallTransitions ( ) ) ) { + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) ); + DefaultSymbolType push = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.second.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + + res.addCallTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( push ) ); + } + + for ( std::pair < ext::tuple < StateType, InputSymbolType, PushdownStoreSymbolType >, StateType > && transition : ext::make_moveable_map ( std::move ( value ).getReturnTransitions ( ) ) ) { + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( transition.first ) ) ); + DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); + + res.addReturnTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) ); + } + + for ( std::pair < ext::pair < StateType, InputSymbolType >, StateType > && transition : ext::make_moveable_map ( std::move ( value ).getLocalTransitions ( ) ) ) { + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + + res.addLocalTransition ( std::move ( from ), std::move ( input ), std::move ( to ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* VISIBLY_PUSHDOWN_DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h b/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h index 39fed02b94d823a9c715934cb47e7b2cb31cf092..0a4c9fee987d7c46f47be945f8d33c60e78df486 100644 --- a/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h +++ b/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h @@ -25,6 +25,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class CallAlphabet; @@ -341,54 +343,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef VisiblyPushdownNPDA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( VisiblyPushdownNPDA < > ) == typeid ( VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > call_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < CallAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > return_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < ReturnAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > local_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < LocalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ) ); - DefaultSymbolType bottomSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < BottomOfTheStackSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - ext::set < DefaultStateType > initialStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < InitialStates > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - VisiblyPushdownNPDA < > * res = new VisiblyPushdownNPDA < > ( std::move ( states ), std::move ( call_alphabet ), std::move ( return_alphabet ), std::move ( local_alphabet ), std::move ( pushdownAlphabet ), std::move ( initialStates ), std::move ( bottomSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < StateType, InputSymbolType >, ext::set < ext::pair < StateType, PushdownStoreSymbolType > > > && transition : ext::make_moveable_map ( callTransitions ) ) { - ext::set < ext::pair < DefaultStateType, DefaultSymbolType > > targets; - for ( std::pair < StateType, PushdownStoreSymbolType > && target : ext::make_moveable_set ( transition.second ) ) - targets.insert ( ext::make_pair ( AutomatonNormalize::normalizeState ( std::move ( target.first ) ), alphabet::SymbolNormalize::normalizeSymbol ( std::move ( target.second ) ) ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - - res->addCallTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); - } - - for ( std::pair < ext::tuple < StateType, InputSymbolType, PushdownStoreSymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( returnTransitions ) ) { - ext::set < DefaultStateType > to = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( transition.first ) ) ); - DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); - - res->addReturnTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) ); - } - - for ( std::pair < ext::pair < StateType, InputSymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( localTransitions ) ) { - ext::set < DefaultStateType > to = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - - res->addLocalTransitions ( std::move ( from ), std::move ( input ), std::move ( to ) ); - } - - return res; - } }; template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > @@ -924,6 +878,60 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, automaton::VisiblyPushdownNPDA < > >::value >::type > { + static automaton::VisiblyPushdownNPDA < > eval ( automaton::VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > call_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getCallAlphabet ( ) ); + ext::set < DefaultSymbolType > return_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getReturnAlphabet ( ) ); + ext::set < DefaultSymbolType > local_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getLocalAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + ext::set < DefaultStateType > initialStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getInitialStates ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::VisiblyPushdownNPDA < > res ( std::move ( states ), std::move ( call_alphabet ), std::move ( return_alphabet ), std::move ( local_alphabet ), std::move ( pushdownAlphabet ), std::move ( initialStates ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < StateType, InputSymbolType >, ext::set < ext::pair < StateType, PushdownStoreSymbolType > > > && transition : ext::make_moveable_map ( std::move ( value ).getCallTransitions ( ) ) ) { + ext::set < ext::pair < DefaultStateType, DefaultSymbolType > > targets; + for ( std::pair < StateType, PushdownStoreSymbolType > && target : ext::make_moveable_set ( transition.second ) ) + targets.insert ( ext::make_pair ( automaton::AutomatonNormalize::normalizeState ( std::move ( target.first ) ), alphabet::SymbolNormalize::normalizeSymbol ( std::move ( target.second ) ) ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + + res.addCallTransitions ( std::move ( from ), std::move ( input ), std::move ( targets ) ); + } + + for ( std::pair < ext::tuple < StateType, InputSymbolType, PushdownStoreSymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getReturnTransitions ( ) ) ) { + ext::set < DefaultStateType > to = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( transition.first ) ) ); + DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) ); + + res.addReturnTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) ); + } + + for ( std::pair < ext::pair < StateType, InputSymbolType >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getLocalTransitions ( ) ) ) { + ext::set < DefaultStateType > to = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + + res.addLocalTransitions ( std::move ( from ), std::move ( input ), std::move ( to ) ); + } + + return res; + } +}; + + } /* namespace alib */ #endif /* VISIBLY_PUSHDOWN_NPDA_H_ */ diff --git a/alib2data/src/automaton/TA/DFTA.h b/alib2data/src/automaton/TA/DFTA.h index c7d47ed2cb31e66c32490b8b603f3a948cf2e6b2..ec4466336c3838ecce1d54d8b37d5a71705c9b37 100644 --- a/alib2data/src/automaton/TA/DFTA.h +++ b/alib2data/src/automaton/TA/DFTA.h @@ -26,6 +26,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -169,27 +171,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef DFTA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( DFTA < > ) == typeid ( DFTA < SymbolType, RankType, StateType > ) ) - return this; - - ext::set < common::ranked_symbol < DefaultSymbolType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - DFTA < > * res = new DFTA < > ( std::move ( states ), std::move ( alphabet ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < common::ranked_symbol < SymbolType, RankType >, ext::vector < StateType > >, StateType > && transition : ext::make_moveable_map ( transitions ) ) { - common::ranked_symbol < DefaultSymbolType, DefaultRankType > input = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( transition.first.first ) ); - ext::vector < DefaultStateType > from = AutomatonNormalize::normalizeStates ( std::move ( transition.first.second ) ); - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); - - res->addTransition ( std::move ( input ), std::move ( from ), std::move ( to ) ); - } - - return res; - } }; } /* namespace automaton */ @@ -405,6 +386,32 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class SymbolType, class RankType, class StateType > +struct normalize < automaton::DFTA < SymbolType, RankType, StateType >, typename std::enable_if < ! std::is_same < automaton::DFTA < SymbolType, RankType, StateType >, automaton::DFTA < > >::value >::type > { + static automaton::DFTA < > eval ( automaton::DFTA < SymbolType, RankType, StateType > && value ) { + ext::set < common::ranked_symbol < > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::DFTA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < common::ranked_symbol < SymbolType, RankType >, ext::vector < StateType > >, StateType > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + common::ranked_symbol < DefaultSymbolType, DefaultRankType > input = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( transition.first.first ) ); + ext::vector < DefaultStateType > from = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.first.second ) ); + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) ); + + res.addTransition ( std::move ( input ), std::move ( from ), std::move ( to ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* DFTA_H_ */ diff --git a/alib2data/src/automaton/TA/NFTA.h b/alib2data/src/automaton/TA/NFTA.h index 87ec006ff5b3f9862276c4bf52179f5ecaf8d910..abe7db5d9527208dc8fa784c650d252cb81bc99c 100644 --- a/alib2data/src/automaton/TA/NFTA.h +++ b/alib2data/src/automaton/TA/NFTA.h @@ -25,6 +25,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class InputAlphabet; @@ -187,27 +189,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef NFTA < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( NFTA < > ) == typeid ( NFTA < SymbolType, RankType, StateType > ) ) - return this; - - ext::set < common::ranked_symbol < DefaultSymbolType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - NFTA < > * res = new NFTA < > ( std::move ( states ), std::move ( alphabet ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < common::ranked_symbol < SymbolType, RankType >, ext::vector < StateType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( transitions ) ) { - common::ranked_symbol < DefaultSymbolType, DefaultRankType > input = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( transition.first.first ) ); - ext::vector < DefaultStateType > from = AutomatonNormalize::normalizeStates ( std::move ( transition.first.second ) ); - ext::set < DefaultStateType > to = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); - - res->addTransitions ( std::move ( input ), std::move ( from ), std::move ( to ) ); - } - - return res; - } }; } /* namespace automaton */ @@ -457,6 +438,32 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class SymbolType, class RankType, class StateType > +struct normalize < automaton::NFTA < SymbolType, RankType, StateType >, typename std::enable_if < ! std::is_same < automaton::NFTA < SymbolType, RankType, StateType >, automaton::NFTA < > >::value >::type > { + static automaton::NFTA < > eval ( automaton::NFTA < SymbolType, RankType, StateType > && value ) { + ext::set < common::ranked_symbol < > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::NFTA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < common::ranked_symbol < SymbolType, RankType >, ext::vector < StateType > >, ext::set < StateType > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + common::ranked_symbol < DefaultSymbolType, DefaultRankType > input = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( transition.first.first ) ); + ext::vector < DefaultStateType > from = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.first.second ) ); + ext::set < DefaultStateType > to = automaton::AutomatonNormalize::normalizeStates ( std::move ( transition.second ) ); + + res.addTransitions ( std::move ( input ), std::move ( from ), std::move ( to ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* NFTA_H_ */ diff --git a/alib2data/src/automaton/TM/OneTapeDTM.h b/alib2data/src/automaton/TM/OneTapeDTM.h index 05ff53fd0e13f07d678ae842b9cfedc599ddf446..61df10787102e689035e25da20654b9324d7b89e 100644 --- a/alib2data/src/automaton/TM/OneTapeDTM.h +++ b/alib2data/src/automaton/TM/OneTapeDTM.h @@ -27,6 +27,8 @@ #include "../common/AutomatonNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace automaton { class TapeAlphabet; @@ -214,31 +216,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef OneTapeDTM < > normalized_type; - - virtual AutomatonBase * normalize ( ) && { - if ( typeid ( OneTapeDTM < > ) == typeid ( OneTapeDTM < SymbolType, StateType > ) ) - return this; - - ext::set < DefaultSymbolType > tapeAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TapeAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) ); - DefaultSymbolType blankSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < BlankSymbol > ( ).get ( ) ) ); - ext::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) ); - DefaultStateType initialState = AutomatonNormalize::normalizeState ( std::move ( this->template accessElement < InitialState > ( ).get ( ) ) ); - ext::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) ); - - OneTapeDTM < > * res = new OneTapeDTM < > ( std::move ( states ), std::move ( tapeAlphabet ), std::move ( blankSymbol ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); - - for ( std::pair < ext::pair < DefaultStateType, DefaultSymbolType >, ext::tuple < DefaultStateType, DefaultSymbolType, Shift > > && transition : ext::make_moveable_map ( transitions ) ) { - DefaultStateType from = AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); - DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); - DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.second ) ) ); - DefaultSymbolType output = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( transition.second ) ) ); - - res->addTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( output ), std::get < 2 > ( transition.second ) ); - } - - return res; - } }; template<class SymbolType, class StateType > @@ -534,6 +511,36 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template<class SymbolType, class StateType > +struct normalize < automaton::OneTapeDTM < SymbolType, StateType >, typename std::enable_if < ! std::is_same < automaton::OneTapeDTM < SymbolType, StateType >, automaton::OneTapeDTM < > >::value >::type > { + static automaton::OneTapeDTM < > eval ( automaton::OneTapeDTM < SymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > tapeAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTapeAlphabet ( ) ); + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + DefaultSymbolType blankSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getBlankSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::OneTapeDTM < > res ( std::move ( states ), std::move ( tapeAlphabet ), std::move ( blankSymbol ), std::move ( alphabet ), std::move ( initialState ), std::move ( finalStates ) ); + + for ( std::pair < ext::pair < DefaultStateType, DefaultSymbolType >, ext::tuple < DefaultStateType, DefaultSymbolType, automaton::Shift > > && transition : ext::make_moveable_map ( std::move ( value ).getTransitions ( ) ) ) { + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) ); + DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) ); + DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.second ) ) ); + DefaultSymbolType output = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( transition.second ) ) ); + + res.addTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( output ), std::get < 2 > ( transition.second ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* ONE_TAPE_DTM_H_ */ diff --git a/alib2data/src/grammar/ContextFree/CFG.h b/alib2data/src/grammar/ContextFree/CFG.h index 095f1afd7b683c767d7654d1e24e64dc5eab0c2b..603c35bcd60c67f2ba008486520c0135f8301f5a 100644 --- a/alib2data/src/grammar/ContextFree/CFG.h +++ b/alib2data/src/grammar/ContextFree/CFG.h @@ -25,6 +25,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { /** @@ -136,30 +138,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef CFG < > normalized_type; - - virtual GrammarBase * normalize ( ) && { - if ( typeid ( CFG < > ) == typeid ( CFG < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - CFG < > * res = new CFG < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < SymbolType, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::vector < DefaultSymbolType > > rhs; - for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); - - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - return res; - } }; } /* namespace grammar */ @@ -406,6 +384,30 @@ public: } }; +template < class SymbolType > +struct normalize < grammar::CFG < SymbolType >, typename std::enable_if < ! std::is_same < grammar::CFG < SymbolType >, grammar::CFG < > >::value >::type > { + static grammar::CFG < > eval ( grammar::CFG < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::CFG < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < SymbolType, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::vector < DefaultSymbolType > > rhs; + for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); + + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* CFG_H_ */ diff --git a/alib2data/src/grammar/ContextFree/CNF.h b/alib2data/src/grammar/ContextFree/CNF.h index c74f56334e351aa6e6a90453f66078bb3f0c12a1..9c17dd065c3aa2dc17e73c85a46d1e3770b61758 100644 --- a/alib2data/src/grammar/ContextFree/CNF.h +++ b/alib2data/src/grammar/ContextFree/CNF.h @@ -26,6 +26,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { /** @@ -143,32 +145,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef CNF < > normalized_type; - - virtual GrammarBase * normalize ( ) && { - if ( typeid ( CNF < > ) == typeid ( CNF < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - CNF < > * res = new CNF < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::variant < DefaultSymbolType, ext::pair < DefaultSymbolType, DefaultSymbolType > > > rhs; - for ( ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); - - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - res->setGeneratesEpsilon ( getGeneratesEpsilon ( ) ); - - return res; - } }; template < class SymbolType > @@ -502,6 +478,33 @@ public: } }; + +template < class SymbolType > +struct normalize < grammar::CNF < SymbolType >, typename std::enable_if < ! std::is_same < grammar::CNF < SymbolType >, grammar::CNF < > >::value >::type > { + static grammar::CNF < > eval ( grammar::CNF < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::CNF < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::variant < DefaultSymbolType, ext::pair < DefaultSymbolType, DefaultSymbolType > > > rhs; + for ( ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( grammar::GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); + + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + res.setGeneratesEpsilon ( value.getGeneratesEpsilon ( ) ); + + return res; + } +}; + } /* namespace alib */ #endif /* CNF_H_ */ diff --git a/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h b/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h index fabab64570a08400a012edf559346a19c5830212..9da5b8545b181a0c13de4a366511fd5cf0992547 100644 --- a/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h +++ b/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h @@ -25,6 +25,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { /** @@ -138,32 +140,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef EpsilonFreeCFG < > normalized_type; - - virtual GrammarBase * normalize ( ) && { - if ( typeid ( EpsilonFreeCFG < > ) == typeid ( EpsilonFreeCFG < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - EpsilonFreeCFG < > * res = new EpsilonFreeCFG < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < SymbolType, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::vector < DefaultSymbolType > > rhs; - for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); - - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - res->setGeneratesEpsilon ( getGeneratesEpsilon ( ) ); - - return res; - } }; template < class SymbolType > @@ -437,6 +413,32 @@ public: } }; +template < class SymbolType > +struct normalize < grammar::EpsilonFreeCFG < SymbolType >, typename std::enable_if < ! std::is_same < grammar::EpsilonFreeCFG < SymbolType >, grammar::EpsilonFreeCFG < > >::value >::type > { + static grammar::EpsilonFreeCFG < > eval ( grammar::EpsilonFreeCFG < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::EpsilonFreeCFG < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < SymbolType, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::vector < DefaultSymbolType > > rhs; + for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); + + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + res.setGeneratesEpsilon ( value.getGeneratesEpsilon ( ) ); + + return res; + } +}; + } /* namespace alib */ #endif /* EPSILON_FREE_CFG_H_ */ diff --git a/alib2data/src/grammar/ContextFree/GNF.h b/alib2data/src/grammar/ContextFree/GNF.h index 6d08d55e127489269ec73b738c1219f78f8b0f49..5bd214581d1408d5648cbfa04b5e5e796c210de8 100644 --- a/alib2data/src/grammar/ContextFree/GNF.h +++ b/alib2data/src/grammar/ContextFree/GNF.h @@ -25,6 +25,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { /** @@ -139,32 +141,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef GNF < > normalized_type; - - virtual GrammarBase * normalize ( ) && { - if ( typeid ( GNF < > ) == typeid ( GNF < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - GNF < > * res = new GNF < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < SymbolType, ext::set < ext::pair < SymbolType, ext::vector < SymbolType > > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::pair < DefaultSymbolType, ext::vector < DefaultSymbolType > > > rhs; - for ( ext::pair < SymbolType, ext::vector < SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); - - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - res->setGeneratesEpsilon ( getGeneratesEpsilon ( ) ); - - return res; - } }; template < class SymbolType > @@ -447,6 +423,32 @@ public: } }; +template < class SymbolType > +struct normalize < grammar::GNF < SymbolType >, typename std::enable_if < ! std::is_same < grammar::GNF < SymbolType >, grammar::GNF < > >::value >::type > { + static grammar::GNF < > eval ( grammar::GNF < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::GNF < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < SymbolType, ext::set < ext::pair < SymbolType, ext::vector < SymbolType > > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::pair < DefaultSymbolType, ext::vector < DefaultSymbolType > > > rhs; + for ( ext::pair < SymbolType, ext::vector < SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( grammar::GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); + + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + res.setGeneratesEpsilon ( value.getGeneratesEpsilon ( ) ); + + return res; + } +}; + } /* namespace alib */ #endif /* GNF_H_ */ diff --git a/alib2data/src/grammar/ContextFree/LG.h b/alib2data/src/grammar/ContextFree/LG.h index 9a1badbfffed3ae3e5aa3c92fd81631a8bc41cfc..9d8148d81b0a686612a1f65f6a46331b9d062416 100644 --- a/alib2data/src/grammar/ContextFree/LG.h +++ b/alib2data/src/grammar/ContextFree/LG.h @@ -27,6 +27,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { /** @@ -140,30 +142,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef LG < > normalized_type; - - virtual GrammarBase * normalize ( ) && { - if ( typeid ( LG < > ) == typeid ( LG < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - LG < > * res = new LG < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::tuple < ext::vector < SymbolType >, SymbolType, ext::vector < SymbolType > > > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::variant < ext::vector < DefaultSymbolType >, ext::tuple < ext::vector < DefaultSymbolType >, DefaultSymbolType, ext::vector < DefaultSymbolType > > > > rhs; - for ( ext::variant < ext::vector < SymbolType >, ext::tuple < ext::vector < SymbolType >, SymbolType, ext::vector < SymbolType > > > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); - - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - return res; - } }; template < class SymbolType > @@ -510,6 +488,30 @@ public: } }; +template < class SymbolType > +struct normalize < grammar::LG < SymbolType >, typename std::enable_if < ! std::is_same < grammar::LG < SymbolType >, grammar::LG < > >::value >::type > { + static grammar::LG < > eval ( grammar::LG < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::LG < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::tuple < ext::vector < SymbolType >, SymbolType, ext::vector < SymbolType > > > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::variant < ext::vector < DefaultSymbolType >, ext::tuple < ext::vector < DefaultSymbolType >, DefaultSymbolType, ext::vector < DefaultSymbolType > > > > rhs; + for ( ext::variant < ext::vector < SymbolType >, ext::tuple < ext::vector < SymbolType >, SymbolType, ext::vector < SymbolType > > > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( grammar::GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); + + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* LG_H_ */ diff --git a/alib2data/src/grammar/ContextSensitive/CSG.h b/alib2data/src/grammar/ContextSensitive/CSG.h index e8a3bf05297540354abaccb973a08c4b507e6118..c79a5546e51dc698a12816c1a9267b36c7642f58 100644 --- a/alib2data/src/grammar/ContextSensitive/CSG.h +++ b/alib2data/src/grammar/ContextSensitive/CSG.h @@ -25,6 +25,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { /** @@ -132,34 +134,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef CSG < > normalized_type; - - virtual GrammarBase * normalize ( ) && { - if ( typeid ( CSG < > ) == typeid ( CSG < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - CSG < > * res = new CSG < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < ext::tuple < ext::vector < SymbolType >, SymbolType, ext::vector < SymbolType > >, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::vector < DefaultSymbolType > > rhs; - for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); - - ext::vector < DefaultSymbolType > lContext = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 0 > ( rule.first ) ) ); - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( rule.first ) ) ); - ext::vector < DefaultSymbolType > rContext = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( rule.first ) ) ); - - res->addRules ( std::move ( lContext ), std::move ( lhs ), std::move ( rContext ), std::move ( rhs ) ); - } - - res->setGeneratesEpsilon ( getGeneratesEpsilon ( ) ); - - return res; - } }; template < class SymbolType > @@ -437,6 +411,34 @@ public: } }; +template < class SymbolType > +struct normalize < grammar::CSG < SymbolType >, typename std::enable_if < ! std::is_same < grammar::CSG < SymbolType >, grammar::CSG < > >::value >::type > { + static grammar::CSG < > eval ( grammar::CSG < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::CSG < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < ext::tuple < ext::vector < SymbolType >, SymbolType, ext::vector < SymbolType > >, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::vector < DefaultSymbolType > > rhs; + for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); + + ext::vector < DefaultSymbolType > lContext = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 0 > ( rule.first ) ) ); + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( rule.first ) ) ); + ext::vector < DefaultSymbolType > rContext = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( rule.first ) ) ); + + res.addRules ( std::move ( lContext ), std::move ( lhs ), std::move ( rContext ), std::move ( rhs ) ); + } + + res.setGeneratesEpsilon ( value.getGeneratesEpsilon ( ) ); + + return res; + } +}; + } /* namespace alib */ #endif /* CSG_H_ */ diff --git a/alib2data/src/grammar/ContextSensitive/NonContractingGrammar.h b/alib2data/src/grammar/ContextSensitive/NonContractingGrammar.h index c7cdea7d628dfb7e5a014a93b359818cae5925be..43bd50570bde170b8b7ca6b214f20d31ff238051 100644 --- a/alib2data/src/grammar/ContextSensitive/NonContractingGrammar.h +++ b/alib2data/src/grammar/ContextSensitive/NonContractingGrammar.h @@ -25,6 +25,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { /** @@ -132,32 +134,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef NonContractingGrammar < > normalized_type; - - virtual GrammarBase * normalize ( ) && { - if ( typeid ( NonContractingGrammar < > ) == typeid ( NonContractingGrammar < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - NonContractingGrammar < > * res = new NonContractingGrammar < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < ext::vector < SymbolType >, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::vector < DefaultSymbolType > > rhs; - for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); - - ext::vector < DefaultSymbolType > lhs = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - res->setGeneratesEpsilon ( getGeneratesEpsilon ( ) ); - - return res; - } }; template < class SymbolType > @@ -421,6 +397,32 @@ public: } }; +template < class SymbolType > +struct normalize < grammar::NonContractingGrammar < SymbolType >, typename std::enable_if < ! std::is_same < grammar::NonContractingGrammar < SymbolType >, grammar::NonContractingGrammar < > >::value >::type > { + static grammar::NonContractingGrammar < > eval ( grammar::NonContractingGrammar < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::NonContractingGrammar < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < ext::vector < SymbolType >, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::vector < DefaultSymbolType > > rhs; + for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); + + ext::vector < DefaultSymbolType > lhs = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + res.setGeneratesEpsilon ( value.getGeneratesEpsilon ( ) ); + + return res; + } +}; + } /* namespace alib */ #endif /* NON_CONTRACTING_GRAMMAR_H_ */ diff --git a/alib2data/src/grammar/GrammarBase.h b/alib2data/src/grammar/GrammarBase.h index bb22382ddea9b6b397b11c07fcbb8c7156320b20..e1a920950547a75c6bca6d57765ea1b98860adff 100644 --- a/alib2data/src/grammar/GrammarBase.h +++ b/alib2data/src/grammar/GrammarBase.h @@ -26,11 +26,6 @@ public: * @copydoc alib::ObjectBase::plunder() */ virtual GrammarBase* plunder() && override = 0; - - /** - * @copydoc alib::ObjectBase::normalize() - */ - virtual GrammarBase* normalize ( ) && override = 0; }; } /* namespace grammar */ diff --git a/alib2data/src/grammar/Regular/LeftLG.h b/alib2data/src/grammar/Regular/LeftLG.h index 8b5228608836b025835a54a280f83bed91e25c85..e9bd58bf4775012e742d08c29dd5795d3c09923c 100644 --- a/alib2data/src/grammar/Regular/LeftLG.h +++ b/alib2data/src/grammar/Regular/LeftLG.h @@ -42,6 +42,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { class TerminalAlphabet; @@ -396,36 +398,6 @@ public: * Type of normalized grammar. */ typedef LeftLG < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols. - * - * \returns new instance of the grammar with default template parameters or unmodified instance if the template parameters were already default ones - */ - virtual GrammarBase * normalize ( ) && override { - if ( typeid ( LeftLG < > ) == typeid ( LeftLG < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - LeftLG < > * res = new LeftLG < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::pair < SymbolType, ext::vector < SymbolType > > > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::variant < ext::vector < DefaultSymbolType >, ext::pair < DefaultSymbolType, ext::vector < DefaultSymbolType > > > > rhs; - for ( ext::variant < ext::vector < SymbolType >, ext::pair < SymbolType, ext::vector < SymbolType > > > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); - - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - return res; - } - }; template < class SymbolType > @@ -825,6 +797,35 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols. + * + * \returns new instance of the grammar with default template parameters or unmodified instance if the template parameters were already default ones + */ +template < class SymbolType > +struct normalize < grammar::LeftLG < SymbolType >, typename std::enable_if < ! std::is_same < grammar::LeftLG < SymbolType >, grammar::LeftLG < > >::value >::type > { + static grammar::LeftLG < > eval ( grammar::LeftLG < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::LeftLG < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::pair < SymbolType, ext::vector < SymbolType > > > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::variant < ext::vector < DefaultSymbolType >, ext::pair < DefaultSymbolType, ext::vector < DefaultSymbolType > > > > rhs; + for ( ext::variant < ext::vector < SymbolType >, ext::pair < SymbolType, ext::vector < SymbolType > > > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( grammar::GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); + + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* LEFT_LG_H_ */ diff --git a/alib2data/src/grammar/Regular/LeftRG.h b/alib2data/src/grammar/Regular/LeftRG.h index 095fffaa385676da16e69fd4c7d3e580e113eb1d..3a056514b7a1d9b0ff557d0096c12abd55aa995b 100644 --- a/alib2data/src/grammar/Regular/LeftRG.h +++ b/alib2data/src/grammar/Regular/LeftRG.h @@ -42,6 +42,8 @@ #include <grammar/common/GrammarNormalize.h> #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { class TerminalAlphabet; @@ -419,37 +421,6 @@ public: * Type of normalized grammar. */ typedef LeftRG < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols. - * - * \returns new instance of the grammar with default template parameters or unmodified instance if the template parameters were already default ones - */ - virtual GrammarBase * normalize ( ) && override { - if ( typeid ( LeftRG < > ) == typeid ( LeftRG < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - LeftRG < > * res = new LeftRG < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::variant < DefaultSymbolType, ext::pair < DefaultSymbolType, DefaultSymbolType > > > rhs; - for ( ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); - - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - res->setGeneratesEpsilon ( getGeneratesEpsilon ( ) ); - - return res; - } }; template < class SymbolType > @@ -859,6 +830,37 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols. + * + * \returns new instance of the grammar with default template parameters or unmodified instance if the template parameters were already default ones + */ +template < class SymbolType > +struct normalize < grammar::LeftRG < SymbolType >, typename std::enable_if < ! std::is_same < grammar::LeftRG < SymbolType >, grammar::LeftRG < > >::value >::type > { + static grammar::LeftRG < > eval ( grammar::LeftRG < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::LeftRG < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::variant < DefaultSymbolType, ext::pair < DefaultSymbolType, DefaultSymbolType > > > rhs; + for ( ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( grammar::GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); + + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + res.setGeneratesEpsilon ( value.getGeneratesEpsilon ( ) ); + + return res; + } +}; + } /* namespace alib */ #endif /* LEFT_RG_H_ */ diff --git a/alib2data/src/grammar/Regular/RightLG.h b/alib2data/src/grammar/Regular/RightLG.h index 748c453a694ba89e0bafb1b1ffc372d96d827bcd..a851b88dd8880f217a1e9eb81db4ba0346fa7a0e 100644 --- a/alib2data/src/grammar/Regular/RightLG.h +++ b/alib2data/src/grammar/Regular/RightLG.h @@ -42,6 +42,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { class TerminalAlphabet; @@ -396,35 +398,6 @@ public: * Type of normalized grammar. */ typedef RightLG < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols. - * - * \returns new instance of the grammar with default template parameters or unmodified instance if the template parameters were already default ones - */ - virtual GrammarBase * normalize ( ) && override { - if ( typeid ( RightLG < > ) == typeid ( RightLG < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - RightLG < > * res = new RightLG < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::pair < ext::vector < SymbolType >, SymbolType > > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::variant < ext::vector < DefaultSymbolType >, ext::pair < ext::vector < DefaultSymbolType >, DefaultSymbolType > > > rhs; - for ( ext::variant < ext::vector < SymbolType >, ext::pair < ext::vector < SymbolType >, SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); - - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - return res; - } }; template < class SymbolType > @@ -822,6 +795,35 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols. + * + * \returns new instance of the grammar with default template parameters or unmodified instance if the template parameters were already default ones + */ +template < class SymbolType > +struct normalize < grammar::RightLG < SymbolType >, typename std::enable_if < ! std::is_same < grammar::RightLG < SymbolType >, grammar::RightLG < > >::value >::type > { + static grammar::RightLG < > eval ( grammar::RightLG < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::RightLG < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::pair < ext::vector < SymbolType >, SymbolType > > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::variant < ext::vector < DefaultSymbolType >, ext::pair < ext::vector < DefaultSymbolType >, DefaultSymbolType > > > rhs; + for ( ext::variant < ext::vector < SymbolType >, ext::pair < ext::vector < SymbolType >, SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( grammar::GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); + + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* RIGHT_LG_H_ */ diff --git a/alib2data/src/grammar/Regular/RightRG.h b/alib2data/src/grammar/Regular/RightRG.h index 05dda236983d0ca033da4bc95f1a007e39013c70..ad65277fa675bdf42850c53cfc8bd48d8500baa7 100644 --- a/alib2data/src/grammar/Regular/RightRG.h +++ b/alib2data/src/grammar/Regular/RightRG.h @@ -42,6 +42,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { class TerminalAlphabet; @@ -419,37 +421,6 @@ public: * Type of normalized grammar. */ typedef RightRG < > normalized_type; - - /** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols. - * - * \returns new instance of the grammar with default template parameters or unmodified instance if the template parameters were already default ones - */ - virtual GrammarBase * normalize ( ) && override { - if ( typeid ( RightRG < > ) == typeid ( RightRG < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - RightRG < > * res = new RightRG < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::variant < DefaultSymbolType, ext::pair < DefaultSymbolType, DefaultSymbolType > > > rhs; - for ( ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); - - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - res->setGeneratesEpsilon ( getGeneratesEpsilon ( ) ); - - return res; - } }; template < class SymbolType > @@ -856,6 +827,37 @@ public: } }; +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols. + * + * \returns new instance of the grammar with default template parameters or unmodified instance if the template parameters were already default ones + */ +template < class SymbolType > +struct normalize < grammar::RightRG < SymbolType >, typename std::enable_if < ! std::is_same < grammar::RightRG < SymbolType >, grammar::RightRG < > >::value >::type > { + static grammar::RightRG < > eval ( grammar::RightRG < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::RightRG < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::variant < DefaultSymbolType, ext::pair < DefaultSymbolType, DefaultSymbolType > > > rhs; + for ( ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( grammar::GrammarNormalize::normalizeRHS ( std::move ( target ) ) ); + + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + res.setGeneratesEpsilon ( value.getGeneratesEpsilon ( ) ); + + return res; + } +}; + } /* namespace alib */ #endif /* RIGHT_RG_H_ */ diff --git a/alib2data/src/grammar/Unrestricted/ContextPreservingUnrestrictedGrammar.h b/alib2data/src/grammar/Unrestricted/ContextPreservingUnrestrictedGrammar.h index 2d12bc3b9381f2ed17f9dba2d2edd57bb12d759c..6948da76f6dcc08accffe1bbc277443a189f5f88 100644 --- a/alib2data/src/grammar/Unrestricted/ContextPreservingUnrestrictedGrammar.h +++ b/alib2data/src/grammar/Unrestricted/ContextPreservingUnrestrictedGrammar.h @@ -25,6 +25,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { /** @@ -128,32 +130,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef ContextPreservingUnrestrictedGrammar < > normalized_type; - - virtual GrammarBase * normalize ( ) && { - if ( typeid ( ContextPreservingUnrestrictedGrammar < > ) == typeid ( ContextPreservingUnrestrictedGrammar < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - ContextPreservingUnrestrictedGrammar < > * res = new ContextPreservingUnrestrictedGrammar < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < ext::tuple < ext::vector < SymbolType >, SymbolType, ext::vector < SymbolType > >, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::vector < DefaultSymbolType > > rhs; - for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); - - ext::vector < DefaultSymbolType > lContext = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 0 > ( rule.first ) ) ); - DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( rule.first ) ) ); - ext::vector < DefaultSymbolType > rContext = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( rule.first ) ) ); - - res->addRules ( std::move ( lContext ), std::move ( lhs ), std::move ( rContext ), std::move ( rhs ) ); - } - - return res; - } }; template < class SymbolType > @@ -407,6 +383,32 @@ public: } }; +template < class SymbolType > +struct normalize < grammar::ContextPreservingUnrestrictedGrammar < SymbolType >, typename std::enable_if < ! std::is_same < grammar::ContextPreservingUnrestrictedGrammar < SymbolType >, grammar::ContextPreservingUnrestrictedGrammar < > >::value >::type > { + static grammar::ContextPreservingUnrestrictedGrammar < > eval ( grammar::ContextPreservingUnrestrictedGrammar < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::ContextPreservingUnrestrictedGrammar < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < ext::tuple < ext::vector < SymbolType >, SymbolType, ext::vector < SymbolType > >, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::vector < DefaultSymbolType > > rhs; + for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); + + ext::vector < DefaultSymbolType > lContext = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 0 > ( rule.first ) ) ); + DefaultSymbolType lhs = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( rule.first ) ) ); + ext::vector < DefaultSymbolType > rContext = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( rule.first ) ) ); + + res.addRules ( std::move ( lContext ), std::move ( lhs ), std::move ( rContext ), std::move ( rhs ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* CONTEXT_PRESERVING_UNRESTRICTED_GRAMMAR_H_ */ diff --git a/alib2data/src/grammar/Unrestricted/UnrestrictedGrammar.h b/alib2data/src/grammar/Unrestricted/UnrestrictedGrammar.h index e0911b2e6b7d3211c2a7eaf9dd8ab65248608c5c..019009492e6553e3748ad276eabfcb3dff527aca 100644 --- a/alib2data/src/grammar/Unrestricted/UnrestrictedGrammar.h +++ b/alib2data/src/grammar/Unrestricted/UnrestrictedGrammar.h @@ -25,6 +25,8 @@ #include "../common/GrammarNormalize.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace grammar { /** @@ -128,30 +130,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef UnrestrictedGrammar < > normalized_type; - - virtual GrammarBase * normalize ( ) && { - if ( typeid ( UnrestrictedGrammar < > ) == typeid ( UnrestrictedGrammar < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonterminalAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < TerminalAlphabet > ( ).get ( ) ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < InitialSymbol > ( ).get ( ) ) ); - - UnrestrictedGrammar < > * res = new UnrestrictedGrammar < > ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); - - for ( std::pair < ext::vector < SymbolType >, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( rules ) ) { - - ext::set < ext::vector < DefaultSymbolType > > rhs; - for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) - rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); - - ext::vector < DefaultSymbolType > lhs = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( rule.first ) ); - - res->addRules ( std::move ( lhs ), std::move ( rhs ) ); - } - - return res; - } }; template < class SymbolType > @@ -384,6 +362,30 @@ public: } }; +template < class SymbolType > +struct normalize < grammar::UnrestrictedGrammar < SymbolType >, typename std::enable_if < ! std::is_same < grammar::UnrestrictedGrammar < SymbolType >, grammar::UnrestrictedGrammar < > >::value >::type > { + static grammar::UnrestrictedGrammar < > eval ( grammar::UnrestrictedGrammar < SymbolType > && value ) { + ext::set < DefaultSymbolType > nonterminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonterminalAlphabet ( ) ); + ext::set < DefaultSymbolType > terminals = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getTerminalAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + + grammar::UnrestrictedGrammar < > res ( std::move ( nonterminals ), std::move ( terminals ), std::move ( initialSymbol ) ); + + for ( std::pair < ext::vector < SymbolType >, ext::set < ext::vector < SymbolType > > > && rule : ext::make_moveable_map ( std::move ( value ).getRules ( ) ) ) { + + ext::set < ext::vector < DefaultSymbolType > > rhs; + for ( ext::vector < SymbolType > && target : ext::make_moveable_set ( rule.second ) ) + rhs.insert ( alphabet::SymbolNormalize::normalizeSymbols ( std::move ( target ) ) ); + + ext::vector < DefaultSymbolType > lhs = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( rule.first ) ); + + res.addRules ( std::move ( lhs ), std::move ( rhs ) ); + } + + return res; + } +}; + } /* namespace alib */ #endif /* UNRESTRICTED_GRAMMAR_H_ */ diff --git a/alib2data/src/indexes/arbology/CompressedBitParallelTreeIndex.h b/alib2data/src/indexes/arbology/CompressedBitParallelTreeIndex.h index 7ce253de37a0fad5114b90703d986e100ce553d4..1b5105c7bd7602a080d210d132205139f7b8c5e3 100644 --- a/alib2data/src/indexes/arbology/CompressedBitParallelTreeIndex.h +++ b/alib2data/src/indexes/arbology/CompressedBitParallelTreeIndex.h @@ -128,18 +128,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef CompressedBitParallelTreeIndex < > normalized_type; - - virtual ObjectBase * normalize ( ) && { - if ( typeid ( CompressedBitParallelTreeIndex < > ) == typeid ( CompressedBitParallelTreeIndex < SymbolType, RankType > ) ) - return this; - - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::map < common::ranked_symbol < DefaultSymbolType, DefaultRankType >, common::SparseBoolVector > vectors; - for ( std::pair < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > && vector : ext::make_moveable_map ( m_vectors ) ) - vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); - - return new CompressedBitParallelTreeIndex < > ( std::move ( alphabet ), std::move ( vectors ), std::move ( m_jumpTable ) ); - } }; } /* namespace arbology */ @@ -280,6 +268,19 @@ public: }; +template < class SymbolType, class RankType > +struct normalize < indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType >, typename std::enable_if < ! std::is_same < indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType >, indexes::arbology::CompressedBitParallelTreeIndex < > >::value >::type > { + static indexes::arbology::CompressedBitParallelTreeIndex < > eval ( indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > && value ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + + ext::map < common::ranked_symbol < DefaultSymbolType, DefaultRankType >, common::SparseBoolVector > vectors; + for ( std::pair < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > && vector : ext::make_moveable_map ( std::move ( value ).getData ( ) ) ) + vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); + + return indexes::arbology::CompressedBitParallelTreeIndex < > ( std::move ( alphabet ), std::move ( vectors ), std::move ( value ).getJumps ( ) ); + } +}; + } /* namespace alib */ #endif /* ARBOLOGY_COMPRESSED_BIT_PARALLEL_INDEX_H_ */ diff --git a/alib2data/src/indexes/arbology/FullAndLinearIndex.h b/alib2data/src/indexes/arbology/FullAndLinearIndex.h index f79b822ad48d72b96b59a847800772cf261e3476..fc99b52218c3bac54054f4038273914d0f97557f 100644 --- a/alib2data/src/indexes/arbology/FullAndLinearIndex.h +++ b/alib2data/src/indexes/arbology/FullAndLinearIndex.h @@ -124,15 +124,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef FullAndLinearIndex < > normalized_type; - - virtual ObjectBase * normalize ( ) && { - if ( typeid ( FullAndLinearIndex < > ) == typeid ( FullAndLinearIndex < SymbolType, RankType > ) ) - return this; - - indexes::stringology::PositionHeap < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > stringIndex = std::move ( m_StringIndex ).normalizeRankedRaw ( ); - - return new FullAndLinearIndex < > ( std::move ( stringIndex ), std::move ( m_JumpTable ) ); - } }; } /* namespace arbology */ @@ -243,4 +234,17 @@ alib::ObjectBase * FullAndLinearIndex < SymbolType, RankType >::inc ( ) && { } /* namespace indexes */ +namespace alib { + +template < class SymbolType, class RankType > +struct normalize < indexes::arbology::FullAndLinearIndex < SymbolType, RankType >, typename std::enable_if < ! std::is_same < indexes::arbology::FullAndLinearIndex < SymbolType, RankType >, indexes::arbology::FullAndLinearIndex < > >::value >::type > { + static indexes::arbology::FullAndLinearIndex < > eval ( indexes::arbology::FullAndLinearIndex < SymbolType, RankType > && value ) { + indexes::stringology::PositionHeap < common::ranked_symbol < > > stringIndex = alib::normalize < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::eval ( std::move ( value ).getStringIndex ( ) ); + + return indexes::arbology::FullAndLinearIndex < > ( std::move ( stringIndex ), std::move ( value ).getJumps ( ) ); + } +}; + +} /* namespace alib */ + #endif /* ARBOLOGY_FULL_AND_LINEAR_INDEX_H_ */ diff --git a/alib2data/src/indexes/arbology/NonlinearCompressedBitParallelTreeIndex.h b/alib2data/src/indexes/arbology/NonlinearCompressedBitParallelTreeIndex.h index 13aa65ef1ce3c3999d33905b258f079a5d9295af..cd8066dbbcf242774d918c42a323f6558f6f6d85 100644 --- a/alib2data/src/indexes/arbology/NonlinearCompressedBitParallelTreeIndex.h +++ b/alib2data/src/indexes/arbology/NonlinearCompressedBitParallelTreeIndex.h @@ -132,18 +132,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef NonlinearCompressedBitParallelTreeIndex < > normalized_type; - - virtual ObjectBase * normalize ( ) && { - if ( typeid ( NonlinearCompressedBitParallelTreeIndex < > ) == typeid ( NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > ) ) - return this; - - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::map < common::ranked_symbol < DefaultSymbolType, DefaultRankType >, common::SparseBoolVector > vectors; - for ( std::pair < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > && vector : ext::make_moveable_map ( m_vectors ) ) - vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); - - return new NonlinearCompressedBitParallelTreeIndex < > ( std::move ( alphabet ), std::move ( vectors ), std::move ( m_jumpTable ), std::move ( m_repeats ) ); - } }; } /* namespace arbology */ @@ -296,6 +284,19 @@ public: }; +template < class SymbolType, class RankType > +struct normalize < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType >, typename std::enable_if < ! std::is_same < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType >, indexes::arbology::NonlinearCompressedBitParallelTreeIndex < > >::value >::type > { + static indexes::arbology::NonlinearCompressedBitParallelTreeIndex < > eval ( indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > && value ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + + ext::map < common::ranked_symbol < DefaultSymbolType, DefaultRankType >, common::SparseBoolVector > vectors; + for ( std::pair < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > && vector : ext::make_moveable_map ( std::move ( value ).getData ( ) ) ) + vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); + + return indexes::arbology::NonlinearCompressedBitParallelTreeIndex < > ( std::move ( alphabet ), std::move ( vectors ), std::move ( value ).getJumps ( ), std::move ( value ).getRepeats ( ) ); + } +}; + } /* namespace alib */ #endif /* ARBOLOGY_NONLINEAR_COMPRESSED_BIT_PARALLEL_INDEX_H_ */ diff --git a/alib2data/src/indexes/arbology/NonlinearFullAndLinearIndex.h b/alib2data/src/indexes/arbology/NonlinearFullAndLinearIndex.h index c0722c6d42dfd2ceeb11a29645de0979e1bc271a..4e1396688eeb49f3fa48ef580a071b03a8f85c90 100644 --- a/alib2data/src/indexes/arbology/NonlinearFullAndLinearIndex.h +++ b/alib2data/src/indexes/arbology/NonlinearFullAndLinearIndex.h @@ -132,15 +132,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef NonlinearFullAndLinearIndex < > normalized_type; - - virtual ObjectBase * normalize ( ) && { - if ( typeid ( NonlinearFullAndLinearIndex < > ) == typeid ( NonlinearFullAndLinearIndex < SymbolType, RankType > ) ) - return this; - - indexes::stringology::PositionHeap < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > stringIndex = std::move ( m_StringIndex ).normalizeRankedRaw ( ); - - return new NonlinearFullAndLinearIndex < > ( std::move ( stringIndex ), std::move ( m_JumpTable ), std::move ( m_Repeats ) ); - } }; } /* namespace arbology */ @@ -263,4 +254,17 @@ alib::ObjectBase * NonlinearFullAndLinearIndex < SymbolType, RankType >::inc ( ) } /* namespace indexes */ +namespace alib { + +template < class SymbolType, class RankType > +struct normalize < indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType >, typename std::enable_if < ! std::is_same < indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType >, indexes::arbology::NonlinearFullAndLinearIndex < > >::value >::type > { + static indexes::arbology::NonlinearFullAndLinearIndex < > eval ( indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > && value ) { + indexes::stringology::PositionHeap < common::ranked_symbol < > > stringIndex = alib::normalize < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::eval ( std::move ( value ).getStringIndex ( ) ); + + return indexes::arbology::NonlinearFullAndLinearIndex < > ( std::move ( stringIndex ), std::move ( value ).getJumps ( ), std::move ( value ).getRepeats ( ) ); + } +}; + +} /* namespace alib */ + #endif /* ARBOLOGY_NONLINEAR_FULL_AND_LINEAR_INDEX_H_ */ diff --git a/alib2data/src/indexes/stringology/BNDMMatcher.h b/alib2data/src/indexes/stringology/BNDMMatcher.h index b2f48e45f3465b3e52fbc1ae767560faac4ec7f4..7ebe8f6dc8d482799cbdec9bfc564bb9dfa79c1e 100644 --- a/alib2data/src/indexes/stringology/BNDMMatcher.h +++ b/alib2data/src/indexes/stringology/BNDMMatcher.h @@ -124,21 +124,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef BNDMMatcher < > normalized_type; - - virtual ObjectBase * normalize ( ) && { - if ( typeid ( BNDMMatcher < > ) == typeid ( BNDMMatcher < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - - ext::map < DefaultSymbolType, ext::bitset < BitmaskBitCount > > vectors; - for ( std::pair < SymbolType, ext::bitset < BitmaskBitCount > > && vector : ext::make_moveable_map ( m_vectors ) ) - vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); - - ext::vector < DefaultSymbolType > string = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( m_string ) ); - - return new BNDMMatcher < > ( std::move ( alphabet ), std::move ( vectors ), std::move ( string ) ); - } }; } /* namespace stringology */ @@ -258,6 +243,28 @@ public: } }; +template < class SymbolType, size_t BitmaskBitCount > +struct normalize < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount >, typename std::enable_if < ! std::is_same < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount >, indexes::stringology::BNDMMatcher < > >::value && std::is_same < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount >, indexes::stringology::BNDMMatcher < DefaultSymbolType, BitmaskBitCount > >::value >::type > { + static indexes::stringology::BNDMMatcher < DefaultSymbolType, BitmaskBitCount > && eval ( indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > && value ) { + return std::move ( value ); + } +}; + +template < class SymbolType, size_t BitmaskBitCount > +struct normalize < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount >, typename std::enable_if < ! std::is_same < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount >, indexes::stringology::BNDMMatcher < DefaultSymbolType, BitmaskBitCount > >::value && ! std::is_same < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount >, indexes::stringology::BNDMMatcher < DefaultSymbolType, BitmaskBitCount > >::value >::type > { + static indexes::stringology::BNDMMatcher < DefaultSymbolType, BitmaskBitCount > eval ( indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + + ext::map < DefaultSymbolType, ext::bitset < BitmaskBitCount > > vectors; + for ( std::pair < SymbolType, ext::bitset < BitmaskBitCount > > && vector : ext::make_moveable_map ( std::move ( value ).getData ( ) ) ) + vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); + + ext::vector < DefaultSymbolType > string = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( value ).getString ( ) ); + + return indexes::stringology::BNDMMatcher < DefaultSymbolType, BitmaskBitCount > ( std::move ( alphabet ), std::move ( vectors ), std::move ( string ) ); + } +}; + } /* namespace alib */ #endif /* BNDM_MATCHER_H_ */ diff --git a/alib2data/src/indexes/stringology/BitParallelIndex.h b/alib2data/src/indexes/stringology/BitParallelIndex.h index 25b0d8c85c793aa5605f74a2540273b3d3833cc8..84e463928db2ba4491e3e5de89739f3e8d9b1b6f 100644 --- a/alib2data/src/indexes/stringology/BitParallelIndex.h +++ b/alib2data/src/indexes/stringology/BitParallelIndex.h @@ -119,18 +119,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef BitParallelIndex < > normalized_type; - - virtual ObjectBase * normalize ( ) && { - if ( typeid ( BitParallelIndex < > ) == typeid ( BitParallelIndex < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::map < DefaultSymbolType, ext::vector < bool > > vectors; - for ( std::pair < SymbolType, ext::vector < bool > > && vector : ext::make_moveable_map ( m_vectors ) ) - vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); - - return new BitParallelIndex < > ( std::move ( alphabet ), std::move ( vectors ) ); - } }; } /* namespace stringology */ @@ -255,6 +243,19 @@ public: } }; +template < class SymbolType > +struct normalize < indexes::stringology::BitParallelIndex < SymbolType >, typename std::enable_if < ! std::is_same < indexes::stringology::BitParallelIndex < SymbolType >, indexes::stringology::BitParallelIndex < > >::value >::type > { + static indexes::stringology::BitParallelIndex < > eval ( indexes::stringology::BitParallelIndex < SymbolType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + + ext::map < DefaultSymbolType, ext::vector < bool > > vectors; + for ( std::pair < SymbolType, ext::vector < bool > > && vector : ext::make_moveable_map ( std::move ( value ).getData ( ) ) ) + vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); + + return indexes::stringology::BitParallelIndex < > ( std::move ( alphabet ), std::move ( vectors ) ); + } +}; + } /* namespace alib */ #endif /* BIT_PARALLEL_INDEX_H_ */ diff --git a/alib2data/src/indexes/stringology/CompressedBitParallelIndex.h b/alib2data/src/indexes/stringology/CompressedBitParallelIndex.h index af705deb2b954de01bc1ad9eebe6e51734b48fa4..a05709045defc70d3ea978f0065c730053a490de 100644 --- a/alib2data/src/indexes/stringology/CompressedBitParallelIndex.h +++ b/alib2data/src/indexes/stringology/CompressedBitParallelIndex.h @@ -119,18 +119,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef CompressedBitParallelIndex < > normalized_type; - - virtual ObjectBase * normalize ( ) && { - if ( typeid ( CompressedBitParallelIndex < > ) == typeid ( CompressedBitParallelIndex < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::map < DefaultSymbolType, common::SparseBoolVector > vectors; - for ( std::pair < SymbolType, common::SparseBoolVector > && vector : ext::make_moveable_map ( m_vectors ) ) - vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); - - return new CompressedBitParallelIndex < > ( std::move ( alphabet ), std::move ( vectors ) ); - } }; } /* namespace stringology */ @@ -255,6 +243,19 @@ public: } }; +template < class SymbolType > +struct normalize < indexes::stringology::CompressedBitParallelIndex < SymbolType >, typename std::enable_if < ! std::is_same < indexes::stringology::CompressedBitParallelIndex < SymbolType >, indexes::stringology::CompressedBitParallelIndex < > >::value >::type > { + static indexes::stringology::CompressedBitParallelIndex < > eval ( indexes::stringology::CompressedBitParallelIndex < SymbolType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + + ext::map < DefaultSymbolType, common::SparseBoolVector > vectors; + for ( std::pair < SymbolType, common::SparseBoolVector > && vector : ext::make_moveable_map ( std::move ( value ).getData ( ) ) ) + vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) ); + + return indexes::stringology::CompressedBitParallelIndex < > ( std::move ( alphabet ), std::move ( vectors ) ); + } +}; + } /* namespace alib */ #endif /* COMPRESSED_BIT_PARALLEL_INDEX_H_ */ diff --git a/alib2data/src/indexes/stringology/PositionHeap.h b/alib2data/src/indexes/stringology/PositionHeap.h index 1d38cfcc74f11f3de09d9615d92248ddf1d30fa8..ef405dbb02d79f44075cae20fee697499d314a6b 100644 --- a/alib2data/src/indexes/stringology/PositionHeap.h +++ b/alib2data/src/indexes/stringology/PositionHeap.h @@ -131,29 +131,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef PositionHeap < > normalized_type; - - PositionHeap < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > normalizeRankedRaw ( ) && { - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::trie < common::ranked_symbol < DefaultSymbolType, DefaultRankType >, unsigned > trie = IndexesNormalize::normalizeRankedTrie ( std::move ( m_trie ) ); - ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > string = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( m_string ) ); - - return PositionHeap < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > ( std::move ( alphabet ), std::move ( trie ), std::move ( string ) ); - } - - PositionHeap < > normalizeRaw ( ) && { - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::trie < DefaultSymbolType, unsigned > trie = IndexesNormalize::normalizeTrie ( std::move ( m_trie ) ); - ext::vector < DefaultSymbolType > string = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( m_string ) ); - - return PositionHeap < > ( std::move ( alphabet ), std::move ( trie ), std::move ( string ) ); - } - - virtual alib::ObjectBase * normalize ( ) && { - if ( typeid ( PositionHeap < > ) == typeid ( PositionHeap < SymbolType > ) ) - return this; - - return std::move ( * this ).normalizeRaw ( ).plunder ( ); - } }; } /* namespace stringology */ @@ -298,6 +275,35 @@ public: } }; +template < > +struct normalize < indexes::stringology::PositionHeap < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > > { + static indexes::stringology::PositionHeap < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > && eval ( indexes::stringology::PositionHeap < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > && source ) { + return std::move ( source ); + } +}; + +template < class SymbolType, class RankType > +struct normalize < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > > { + static indexes::stringology::PositionHeap < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > eval ( indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > && source ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( source ).getAlphabet ( ) ); + ext::trie < common::ranked_symbol < DefaultSymbolType, DefaultRankType >, unsigned > trie = indexes::IndexesNormalize::normalizeRankedTrie ( std::move ( source ).getRoot ( ) ); + ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > string = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( source ).getString ( ) ); + + return indexes::stringology::PositionHeap < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > ( std::move ( alphabet ), std::move ( trie ), std::move ( string ) ); + } +}; + +template < class SymbolType > +struct normalize < indexes::stringology::PositionHeap < SymbolType >, typename std::enable_if < ! std::is_same < indexes::stringology::PositionHeap < SymbolType >, indexes::stringology::PositionHeap < > >::value >::type > { + static indexes::stringology::PositionHeap < > eval ( indexes::stringology::PositionHeap < SymbolType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::trie < DefaultSymbolType, unsigned > trie = indexes::IndexesNormalize::normalizeTrie ( std::move ( value ).getRoot ( ) ); + ext::vector < DefaultSymbolType > string = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( value ).getString ( ) ); + + return indexes::stringology::PositionHeap < > ( std::move ( alphabet ), std::move ( trie ), std::move ( string ) ); + } +}; + } /* namespace alib */ #endif /* POSITION_HEAP_H_ */ diff --git a/alib2data/src/indexes/stringology/SuffixArray.h b/alib2data/src/indexes/stringology/SuffixArray.h index 250f559defd54e968f1c8e2000f35a8485963e92..a14d9019f364bd14085197f372635bc72d55184e 100644 --- a/alib2data/src/indexes/stringology/SuffixArray.h +++ b/alib2data/src/indexes/stringology/SuffixArray.h @@ -125,16 +125,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef SuffixArray < > normalized_type; - - virtual ObjectBase * normalize ( ) && { - if ( typeid ( SuffixArray < > ) == typeid ( SuffixArray < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < DefaultSymbolType > string = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( m_string ) ); - - return new SuffixArray ( std::move ( alphabet ), std::move ( m_data ), std::move ( string ) ); - } }; } /* namespace stringology */ @@ -255,6 +245,16 @@ public: } }; +template < class SymbolType > +struct normalize < indexes::stringology::SuffixArray < SymbolType >, typename std::enable_if < ! std::is_same < indexes::stringology::SuffixArray < SymbolType >, indexes::stringology::SuffixArray < > >::value >::type > { + static indexes::stringology::SuffixArray < > eval ( indexes::stringology::SuffixArray < SymbolType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < DefaultSymbolType > string = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( value ).getString ( ) ); + + return indexes::stringology::SuffixArray < > ( std::move ( alphabet ), std::move ( value ).getData ( ), std::move ( string ) ); + } +}; + } /* namespace alib */ #endif /* SUFFIX_ARRAY_H_ */ diff --git a/alib2data/src/indexes/stringology/SuffixTrie.h b/alib2data/src/indexes/stringology/SuffixTrie.h index 3c9f8315000e5053e81b1d37cdbbac2f0bc2e510..b83b43164124d4e69f3e624cb27b2fcf48724930 100644 --- a/alib2data/src/indexes/stringology/SuffixTrie.h +++ b/alib2data/src/indexes/stringology/SuffixTrie.h @@ -129,16 +129,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef SuffixTrie < > normalized_type; - - virtual alib::ObjectBase * normalize ( ) && { - if ( typeid ( SuffixTrie < > ) == typeid ( SuffixTrie < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::trie < DefaultSymbolType, ext::variant < void, unsigned > > trie = IndexesNormalize::normalizeTrie ( std::move ( m_trie ) ); - - return new SuffixTrie < > ( std::move ( alphabet ), std::move ( trie ) ); - } }; } /* namespace stringology */ @@ -273,6 +263,16 @@ public: } }; +template < class SymbolType > +struct normalize < indexes::stringology::SuffixTrie < SymbolType >, typename std::enable_if < ! std::is_same < indexes::stringology::SuffixTrie < SymbolType >, indexes::stringology::SuffixTrie < > >::value >::type > { + static indexes::stringology::SuffixTrie < > eval ( indexes::stringology::SuffixTrie < SymbolType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlpahet ( ) ); + ext::trie < DefaultSymbolType, ext::variant < void, unsigned > > trie = indexes::IndexesNormalize::normalizeTrie ( std::move ( value ).getRoot ( ) ); + + return indexes::stringology::SuffixTrie < > ( std::move ( alphabet ), std::move ( trie ) ); + } +}; + } /* namespace alib */ #endif /* SUFFIX_TRIE_H_ */ diff --git a/alib2data/src/label/FailStateLabel.h b/alib2data/src/label/FailStateLabel.h index ce7ea68ba89e8af357ba2b517b818abe38ee1963..a0000fb16274bbb90b0a95d911e37a2153ba5c00 100644 --- a/alib2data/src/label/FailStateLabel.h +++ b/alib2data/src/label/FailStateLabel.h @@ -59,10 +59,6 @@ public: virtual LabelBase * inc ( ) &&; typedef FailStateLabel normalized_type; - - virtual LabelBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/label/FinalStateLabel.h b/alib2data/src/label/FinalStateLabel.h index 2094cf63bca24108e589de4c87c9744e3c8f9587..a13b4cbca613f72b81085c1203b69d7de8eb5d11 100644 --- a/alib2data/src/label/FinalStateLabel.h +++ b/alib2data/src/label/FinalStateLabel.h @@ -59,10 +59,6 @@ public: virtual LabelBase * inc ( ) &&; typedef FinalStateLabel normalized_type; - - virtual LabelBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/label/HexavigesimalLabel.h b/alib2data/src/label/HexavigesimalLabel.h index a179c69aed5174d773105379853dd87b1a8dd691..1e917e49e42f6dd0da60b2544255194acfba84ab 100644 --- a/alib2data/src/label/HexavigesimalLabel.h +++ b/alib2data/src/label/HexavigesimalLabel.h @@ -64,10 +64,6 @@ public: virtual LabelBase * inc ( ) &&; typedef HexavigesimalLabel normalized_type; - - virtual LabelBase * normalize ( ) && { - return this; - } }; } /* namespace label */ diff --git a/alib2data/src/label/InitialStateLabel.h b/alib2data/src/label/InitialStateLabel.h index 969850e8f75dd29d49e0df164e07baa496ed4fb1..9713f3c3781155e9584366db7acdd316cd5d6b72 100644 --- a/alib2data/src/label/InitialStateLabel.h +++ b/alib2data/src/label/InitialStateLabel.h @@ -59,10 +59,6 @@ public: virtual LabelBase * inc ( ) &&; typedef InitialStateLabel normalized_type; - - virtual LabelBase * normalize ( ) && { - return this; - } }; template < typename Base > diff --git a/alib2data/src/label/LabelBase.h b/alib2data/src/label/LabelBase.h index 3675c749c22ba3ed8d6ac41e22d0d6b921c438b3..9acd07d6b74f3504ee168360d0f1abe91511ee6a 100644 --- a/alib2data/src/label/LabelBase.h +++ b/alib2data/src/label/LabelBase.h @@ -21,8 +21,6 @@ public: virtual LabelBase* plunder() && = 0; virtual LabelBase* inc() && = 0; - - virtual LabelBase* normalize ( ) && = 0; }; } /* namespace label */ diff --git a/alib2data/src/label/ObjectLabel.h b/alib2data/src/label/ObjectLabel.h index 4b1f820731115f726f48f8239e404fc4565323a5..d676654d7645056a960ce0dd83ab7bcb103f8e75 100644 --- a/alib2data/src/label/ObjectLabel.h +++ b/alib2data/src/label/ObjectLabel.h @@ -62,10 +62,6 @@ public: virtual LabelBase * inc ( ) &&; typedef ObjectLabel normalized_type; - - virtual LabelBase * normalize ( ) && { - return this; - } }; } /* namespace label */ diff --git a/alib2data/src/label/PrimitiveLabel.h b/alib2data/src/label/PrimitiveLabel.h index ba1bf5fe769826163e5d0122b2dd13570eeaed37..504e591a2a2735c4279d942354dc685d28c02ed7 100644 --- a/alib2data/src/label/PrimitiveLabel.h +++ b/alib2data/src/label/PrimitiveLabel.h @@ -64,10 +64,6 @@ public: virtual LabelBase * inc ( ) &&; typedef PrimitiveLabel normalized_type; - - virtual LabelBase * normalize ( ) && { - return this; - } }; } /* namespace label */ diff --git a/alib2data/src/label/UniqueLabel.h b/alib2data/src/label/UniqueLabel.h index 1c9e476988550a79475abdeb11d8d044b6362d93..289fc7a4f69030bc7e8dc8cf1c314f5bbf81a246 100644 --- a/alib2data/src/label/UniqueLabel.h +++ b/alib2data/src/label/UniqueLabel.h @@ -66,10 +66,6 @@ public: virtual LabelBase * inc ( ) &&; typedef UniqueLabel normalized_type; - - virtual LabelBase * normalize ( ) && { - return this; - } }; } /* namespace label */ diff --git a/alib2data/src/regexp/RegExpBase.h b/alib2data/src/regexp/RegExpBase.h index 490046ec2b42061f3ecdd51226201a3c0feb70f2..3c23d3ce95824eb18e21d2a4af6e7f1accd5504c 100644 --- a/alib2data/src/regexp/RegExpBase.h +++ b/alib2data/src/regexp/RegExpBase.h @@ -19,8 +19,6 @@ class RegExpBase : public alib::ObjectBase { public: virtual RegExpBase* clone() const = 0; virtual RegExpBase* plunder() && = 0; - - virtual RegExpBase* normalize ( ) && = 0; }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/formal/FormalRegExp.h b/alib2data/src/regexp/formal/FormalRegExp.h index d3794515b2bfc81ed5adf0aa16b83c933856f91c..c2efcb610258e206c2176dcb0bb588640402047b 100644 --- a/alib2data/src/regexp/formal/FormalRegExp.h +++ b/alib2data/src/regexp/formal/FormalRegExp.h @@ -26,6 +26,8 @@ #include "FormalRegExpStructure.h" +#include <core/normalize.hpp> + namespace regexp { class GeneralAlphabet; @@ -110,13 +112,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef FormalRegExp < > normalized_type; - - virtual RegExpBase * normalize ( ) && { - if ( typeid ( FormalRegExp < > ) == typeid ( FormalRegExp < SymbolType > ) ) - return this; - - return new FormalRegExp < > ( std::move ( m_regExp ).normalize ( ) ); - } }; } /* namespace regexp */ @@ -239,6 +234,15 @@ public: } }; +template < class SymbolType > +struct normalize < regexp::FormalRegExp < SymbolType >, typename std::enable_if < ! std::is_same < regexp::FormalRegExp < SymbolType >, regexp::FormalRegExp < > >::value >::type > { + static regexp::FormalRegExp < > eval ( regexp::FormalRegExp < SymbolType > && value ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + + return regexp::FormalRegExp < > ( alphabet, std::move ( value ).getRegExp ( ).normalize ( ) ); + } +}; + } /* namespace alib */ #endif /* FORMAL_REG_EXP_H_ */ diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExp.h b/alib2data/src/regexp/unbounded/UnboundedRegExp.h index 84752bb59fd0fc503a6808f70da2d596775136ed..0259d8f413b4560e606d488865f107fb1b17023a 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExp.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExp.h @@ -26,6 +26,8 @@ #include "UnboundedRegExpStructure.h" +#include <core/normalize.hpp> + namespace regexp { class GeneralAlphabet; @@ -110,13 +112,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef UnboundedRegExp < > normalized_type; - - virtual RegExpBase * normalize ( ) && { - if ( typeid ( UnboundedRegExp < > ) == typeid ( UnboundedRegExp < SymbolType > ) ) - return this; - - return new UnboundedRegExp < > ( std::move ( m_regExp ).normalize ( ) ); - } }; } /* namespace regexp */ @@ -239,6 +234,15 @@ public: } }; +template < class SymbolType > +struct normalize < regexp::UnboundedRegExp < SymbolType >, typename std::enable_if < ! std::is_same < regexp::UnboundedRegExp < SymbolType >, regexp::UnboundedRegExp < > >::value >::type > { + static regexp::UnboundedRegExp < > eval ( regexp::UnboundedRegExp < SymbolType > && value ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + + return regexp::UnboundedRegExp < > ( alphabet, std::move ( value ).getRegExp ( ).normalize ( ) ); + } +}; + } /* namespace alib */ #endif /* UNBOUNDED_REG_EXP_H_ */ diff --git a/alib2data/src/rte/RTEBase.h b/alib2data/src/rte/RTEBase.h index 7c9c183ae70b8af9cba8e4dcfc72ee87124a4014..2ee291af36a11276f01bc594b1bf867e0b43e62d 100644 --- a/alib2data/src/rte/RTEBase.h +++ b/alib2data/src/rte/RTEBase.h @@ -18,8 +18,6 @@ class RTEBase : public alib::ObjectBase { public: virtual RTEBase * clone ( ) const = 0; virtual RTEBase * plunder ( ) && = 0; - - virtual RTEBase* normalize ( ) && = 0; }; } /* namespace rte */ diff --git a/alib2data/src/rte/formal/FormalRTE.h b/alib2data/src/rte/formal/FormalRTE.h index c5d80ea9dabb8e7ff5f28255b1e49e3c90150954..6131cc0d27a82a987ecdfa68d4b332bd0daf4c8d 100644 --- a/alib2data/src/rte/formal/FormalRTE.h +++ b/alib2data/src/rte/formal/FormalRTE.h @@ -26,6 +26,8 @@ #include "FormalRTEStructure.h" +#include <core/normalize.hpp> + namespace rte { class GeneralAlphabet; @@ -151,13 +153,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef FormalRTE < > normalized_type; - - virtual RTEBase * normalize ( ) && { - if ( typeid ( FormalRTE < > ) == typeid ( FormalRTE < SymbolType > ) ) - return this; - - return new FormalRTE < > ( std::move ( m_rte ).normalize ( ) ); - } }; template < class SymbolType, class RankType > @@ -291,6 +286,16 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < rte::FormalRTE < SymbolType, RankType >, typename std::enable_if < ! std::is_same < rte::FormalRTE < SymbolType, RankType >, rte::FormalRTE < > >::value >::type > { + static rte::FormalRTE < > eval ( rte::FormalRTE < SymbolType, RankType > && value ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > constants = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getSubstitutionAlphabet ( ) ); + + return rte::FormalRTE < > ( alphabet, constants, std::move ( value ).getRTE ( ).normalize ( ) ); + } +}; + } /* namespace alib */ #endif /* FORMAL_RTE_H_ */ diff --git a/alib2data/src/string/CyclicString.h b/alib2data/src/string/CyclicString.h index 4e18637c4992bf4664ac6d31465585b93d8b0cc8..089e3eb7a6b1921c6681c19a1c476da684c49a04 100644 --- a/alib2data/src/string/CyclicString.h +++ b/alib2data/src/string/CyclicString.h @@ -24,6 +24,8 @@ #include <exception/CommonException.h> #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace string { class GeneralAlphabet; @@ -98,15 +100,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef CyclicString < > normalized_type; - - virtual StringBase * normalize ( ) && { - if ( typeid ( CyclicString < > ) == typeid ( CyclicString < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < DefaultSymbolType > content = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( m_Data ) ); - return new CyclicString < > ( std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace string */ @@ -247,6 +240,15 @@ public: } }; +template < class SymbolType > +struct normalize < string::CyclicString < SymbolType >, typename std::enable_if < ! std::is_same < string::CyclicString < SymbolType >, string::CyclicString < > >::value >::type > { + static string::CyclicString < > eval ( string::CyclicString < SymbolType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < DefaultSymbolType > content = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( value ).getContent ( ) ); + return string::CyclicString < > ( std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* CYCLIC_STRING_H_ */ diff --git a/alib2data/src/string/Epsilon.h b/alib2data/src/string/Epsilon.h index eca106530efb0ea339c01078169f84d9d4d11678..694e953ed23180990fcfb40d9092f68baff9f8a1 100644 --- a/alib2data/src/string/Epsilon.h +++ b/alib2data/src/string/Epsilon.h @@ -21,6 +21,8 @@ #include "common/StringToXMLComposer.h" #include <alphabet/common/SymbolNormalize.h> +#include <core/normalize.hpp> + namespace string { class GeneralAlphabet; @@ -90,14 +92,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef Epsilon < > normalized_type; - - virtual StringBase * normalize ( ) && { - if ( typeid ( Epsilon < > ) == typeid ( Epsilon < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - return new Epsilon < > ( std::move ( alphabet ) ); - } }; template < class SymbolType > @@ -189,6 +183,14 @@ public: } }; +template < class SymbolType > +struct normalize < string::Epsilon < SymbolType >, typename std::enable_if < ! std::is_same < string::Epsilon < SymbolType >, string::Epsilon < > >::value >::type > { + static string::Epsilon < > eval ( string::Epsilon < SymbolType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + return string::Epsilon < > ( std::move ( alphabet ) ); + } +}; + } /* namespace alib */ #endif /* EPSILON_H_ */ diff --git a/alib2data/src/string/LinearString.cpp b/alib2data/src/string/LinearString.cpp index 1c972cbad3b1d5f95095a63441d18f4159782933..f83349a9814a6f3cb710472611330212d95b0875 100644 --- a/alib2data/src/string/LinearString.cpp +++ b/alib2data/src/string/LinearString.cpp @@ -23,19 +23,19 @@ auto linearStringType2 = registration::TypeRegister < alib::Object, string::Line auto LinearStringFromEpsilon = registration::CastRegister < string::LinearString < >, string::Epsilon < > > ( ); -auto LinearStringFromPostfixRankedTree = registration::CastRegister < string::LinearString < common::ranked_symbol < DefaultSymbolType, DefaultRankType > >, tree::PostfixRankedTree < > > ( ); +auto LinearStringFromPostfixRankedTree = registration::CastRegister < string::LinearString < common::ranked_symbol < > >, tree::PostfixRankedTree < > > ( ); auto LinearStringFromPrefixBarTree = registration::CastRegister < string::LinearString < >, tree::PrefixBarTree < > > ( ); -auto LinearStringFromPrefixRankedTree = registration::CastRegister < string::LinearString < common::ranked_symbol < DefaultSymbolType, DefaultRankType > >, tree::PrefixRankedTree < > > ( ); -auto LinearStringFromPrefixRankedPattern = registration::CastRegister < string::LinearString < common::ranked_symbol < DefaultSymbolType, DefaultRankType > >, tree::PrefixRankedPattern < > > ( ); -auto LinearStringFromPrefixRankedNonlinearPattern = registration::CastRegister < string::LinearString < common::ranked_symbol < DefaultSymbolType, DefaultRankType > >, tree::PrefixRankedNonlinearPattern < > > ( ); -auto LinearStringFromPrefixRankedBarTree = registration::CastRegister < string::LinearString < common::ranked_symbol < DefaultSymbolType, DefaultRankType > >, tree::PrefixRankedBarTree < > > ( ); -auto LinearStringFromPrefixRankedBarPattern = registration::CastRegister < string::LinearString < common::ranked_symbol < DefaultSymbolType, DefaultRankType > >, tree::PrefixRankedBarPattern < > > ( ); -auto LinearStringFromPrefixRankedBarNonlinearPattern = registration::CastRegister < string::LinearString < common::ranked_symbol < DefaultSymbolType, DefaultRankType > >, tree::PrefixRankedBarNonlinearPattern < > > ( ); +auto LinearStringFromPrefixRankedTree = registration::CastRegister < string::LinearString < common::ranked_symbol < > >, tree::PrefixRankedTree < > > ( ); +auto LinearStringFromPrefixRankedPattern = registration::CastRegister < string::LinearString < common::ranked_symbol < > >, tree::PrefixRankedPattern < > > ( ); +auto LinearStringFromPrefixRankedNonlinearPattern = registration::CastRegister < string::LinearString < common::ranked_symbol < > >, tree::PrefixRankedNonlinearPattern < > > ( ); +auto LinearStringFromPrefixRankedBarTree = registration::CastRegister < string::LinearString < common::ranked_symbol < > >, tree::PrefixRankedBarTree < > > ( ); +auto LinearStringFromPrefixRankedBarPattern = registration::CastRegister < string::LinearString < common::ranked_symbol < > >, tree::PrefixRankedBarPattern < > > ( ); +auto LinearStringFromPrefixRankedBarNonlinearPattern = registration::CastRegister < string::LinearString < common::ranked_symbol < > >, tree::PrefixRankedBarNonlinearPattern < > > ( ); auto LinearStringName = registration::NameRegister < string::LinearString < > > ( string::LinearString < >::getXmlTagName ( ) ); -auto LinearStringName2 = registration::NameRegister < string::LinearString < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > > ( string::LinearString < >::getXmlTagName ( ) ); +auto LinearStringName2 = registration::NameRegister < string::LinearString < common::ranked_symbol < > > > ( string::LinearString < >::getXmlTagName ( ) ); auto LinearStringSet = registration::SetRegister < string::LinearString < > > ( ); diff --git a/alib2data/src/string/LinearString.h b/alib2data/src/string/LinearString.h index 68d57f43e829162c33f102817d6c9c38664db9dc..5a64cce892cbd0bf5803d113a9a89120db0f5fdc 100644 --- a/alib2data/src/string/LinearString.h +++ b/alib2data/src/string/LinearString.h @@ -26,6 +26,8 @@ #include "../tree/TreeFeatures.h" +#include <core/normalize.hpp> + namespace string { class GeneralAlphabet; @@ -124,15 +126,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef LinearString < > normalized_type; - - virtual StringBase * normalize ( ) && { - if ( typeid ( LinearString < > ) == typeid ( LinearString < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < DefaultSymbolType > content = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( m_Data ) ); - return new LinearString < > ( std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace string */ @@ -337,6 +330,15 @@ public: } }; +template < class SymbolType > +struct normalize < string::LinearString < SymbolType >, typename std::enable_if < ! std::is_same < string::LinearString < SymbolType >, string::LinearString < > >::value >::type > { + static string::LinearString < > eval ( string::LinearString < SymbolType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < DefaultSymbolType > content = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( value ).getContent ( ) ); + return string::LinearString < > ( std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* LINEAR_STRING_H_ */ diff --git a/alib2data/src/string/StringBase.h b/alib2data/src/string/StringBase.h index ee227b810c4f27963cabfdd059ffd44c0301e781..fe7c47a54f84f9d7a90b3975253a9d608bbe24e6 100644 --- a/alib2data/src/string/StringBase.h +++ b/alib2data/src/string/StringBase.h @@ -21,8 +21,6 @@ class StringBase : public alib::ObjectBase { public: virtual StringBase * clone ( ) const = 0; virtual StringBase * plunder ( ) && = 0; - - virtual StringBase* normalize ( ) && = 0; }; } /* namespace string */ diff --git a/alib2data/src/tree/RankedTreeBase.h b/alib2data/src/tree/RankedTreeBase.h index dbd87d94bd940e0fcf3fac2f44cab528f9fe75eb..aff83a746d67ccab567ae118c28fe216d1561e52 100644 --- a/alib2data/src/tree/RankedTreeBase.h +++ b/alib2data/src/tree/RankedTreeBase.h @@ -20,8 +20,6 @@ class RankedTreeBase : public TreeBase { public: virtual RankedTreeBase * clone ( ) const = 0; virtual RankedTreeBase * plunder ( ) && = 0; - - virtual RankedTreeBase* normalize ( ) && = 0; }; } /* namespace tree */ diff --git a/alib2data/src/tree/TreeBase.h b/alib2data/src/tree/TreeBase.h index 65055eb8e11a28252a7db8eaaaf81dc7c3d62828..caa1a7624ea2a3f1d4edfb5da1d8978f74f11a52 100644 --- a/alib2data/src/tree/TreeBase.h +++ b/alib2data/src/tree/TreeBase.h @@ -19,8 +19,6 @@ class TreeBase : public alib::ObjectBase { public: virtual TreeBase* clone() const = 0; virtual TreeBase* plunder() && = 0; - - virtual TreeBase* normalize ( ) && = 0; }; } /* namespace tree */ diff --git a/alib2data/src/tree/UnrankedTreeBase.h b/alib2data/src/tree/UnrankedTreeBase.h index 68549e70f4c5adebe6c7ded19a0983e4763f51e8..f59ecf9bf4790de861a9bc73c3a1ed853458fd8d 100644 --- a/alib2data/src/tree/UnrankedTreeBase.h +++ b/alib2data/src/tree/UnrankedTreeBase.h @@ -20,8 +20,6 @@ class UnrankedTreeBase : public TreeBase { public: virtual UnrankedTreeBase * clone ( ) const = 0; virtual UnrankedTreeBase * plunder ( ) && = 0; - - virtual UnrankedTreeBase* normalize ( ) && = 0; }; } /* namespace tree */ diff --git a/alib2data/src/tree/ranked/PostfixRankedTree.h b/alib2data/src/tree/ranked/PostfixRankedTree.h index c0f2d37023bda98d14f632066d2323a101105d35..88fb0acd8cca1f71b56f57d2e510bc63ed1479f1 100644 --- a/alib2data/src/tree/ranked/PostfixRankedTree.h +++ b/alib2data/src/tree/ranked/PostfixRankedTree.h @@ -27,6 +27,8 @@ #include "../common/TreeToXMLComposer.h" #include <tree/common/TreeNormalize.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -102,17 +104,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef PostfixRankedTree < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( PostfixRankedTree < > ) == typeid ( PostfixRankedTree < SymbolType, RankType > ) ) - return this; - - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( m_Data ) ); - - return new PostfixRankedTree < > ( std::move ( alphabet ), std::move ( content ) ); - } - }; } /* namespace tree */ @@ -272,6 +263,16 @@ public: }; +template < class SymbolType, class RankType > +struct normalize < tree::PostfixRankedTree < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::PostfixRankedTree < SymbolType, RankType >, tree::PostfixRankedTree < > >::value >::type > { + static tree::PostfixRankedTree < > eval ( tree::PostfixRankedTree < SymbolType, RankType > && value ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( value ).getContent ( ) ); + + return tree::PostfixRankedTree < > ( std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* POSTFIX_RANKED_TREE_H_ */ diff --git a/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h b/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h index 41aca9a36ee22cd21c55d4da4a6b800a5054ca7d..4fa417608654dc207e98439b263cc85ab533870a 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h @@ -32,6 +32,8 @@ #include <alphabet/VariablesBarSymbol.h> #include <alphabet/SubtreeWildcardSymbol.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -151,20 +153,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef PrefixRankedBarNonlinearPattern < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( PrefixRankedBarNonlinearPattern < > ) == typeid ( PrefixRankedBarNonlinearPattern < SymbolType, RankType > ) ) - return this; - - common::ranked_symbol < DefaultSymbolType, DefaultRankType > variablesBars = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( this->template accessElement < VariablesBarSymbol > ( ).get ( ) ) ); - common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( this->template accessElement < SubtreeWildcard > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > nonlinearAlphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < NonlinearAlphabet > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > bars = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < BarSymbols > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( m_Data ) ); - - return new PrefixRankedBarNonlinearPattern < > ( std::move ( bars ), std::move ( variablesBars ), std::move ( wildcard ), std::move ( nonlinearAlphabet ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -453,6 +441,20 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < tree::PrefixRankedBarNonlinearPattern < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::PrefixRankedBarNonlinearPattern < SymbolType, RankType >, tree::PrefixRankedBarNonlinearPattern < > >::value >::type > { + static tree::PrefixRankedBarNonlinearPattern < > eval ( tree::PrefixRankedBarNonlinearPattern < SymbolType, RankType > && value ) { + common::ranked_symbol < DefaultSymbolType, DefaultRankType > variablesBars = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( value ).getVariablesBar ( ) ); + common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( value ).getSubtreeWildcard ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > nonlinearAlphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getNonlinearVariables ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > bars = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getBars ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( value ).getContent ( ) ); + + return tree::PrefixRankedBarNonlinearPattern < > ( std::move ( bars ), std::move ( variablesBars ), std::move ( wildcard ), std::move ( nonlinearAlphabet ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* PREFIX_RANKED_BAR_NONLINEAR_PATTERN_H_ */ diff --git a/alib2data/src/tree/ranked/PrefixRankedBarPattern.h b/alib2data/src/tree/ranked/PrefixRankedBarPattern.h index ff1883ce391972e2210f05f4899c2d9384603c20..fbe615c359d9a6614faf1448b38ed0eebea7e4b0 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedBarPattern.h @@ -32,6 +32,8 @@ #include <alphabet/VariablesBarSymbol.h> #include <alphabet/SubtreeWildcardSymbol.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -136,19 +138,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef PrefixRankedBarPattern < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( PrefixRankedBarPattern < > ) == typeid ( PrefixRankedBarPattern < SymbolType, RankType > ) ) - return this; - - common::ranked_symbol < DefaultSymbolType, DefaultRankType > variablesBars = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( this->template accessElement < VariablesBarSymbol > ( ).get ( ) ) ); - common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( this->template accessElement < SubtreeWildcard > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > bars = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < BarSymbols > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( m_Data ) ); - - return new PrefixRankedBarPattern < > ( std::move ( bars ), std::move ( variablesBars ), std::move ( wildcard ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -385,6 +374,19 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < tree::PrefixRankedBarPattern < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::PrefixRankedBarPattern < SymbolType, RankType >, tree::PrefixRankedBarPattern < > >::value >::type > { + static tree::PrefixRankedBarPattern < > eval ( tree::PrefixRankedBarPattern < SymbolType, RankType > && value ) { + common::ranked_symbol < DefaultSymbolType, DefaultRankType > variablesBars = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( value ).getVariablesBar ( ) ); + common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( value ).getSubtreeWildcard ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > bars = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getBars ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( value ).getContent ( ) ); + + return tree::PrefixRankedBarPattern < > ( std::move ( bars ), std::move ( variablesBars ), std::move ( wildcard ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* PREFIX_RANKED_BAR_PATTERN_H_ */ diff --git a/alib2data/src/tree/ranked/PrefixRankedBarTree.h b/alib2data/src/tree/ranked/PrefixRankedBarTree.h index b75d2b306f762fd2eda1af994c97423776a7042f..c6677941e58f150dd05bf63586befc03ecdbabc6 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarTree.h +++ b/alib2data/src/tree/ranked/PrefixRankedBarTree.h @@ -30,6 +30,8 @@ #include <alphabet/BarSymbol.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -115,17 +117,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef PrefixRankedBarTree < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( PrefixRankedBarTree < > ) == typeid ( PrefixRankedBarTree < SymbolType, RankType > ) ) - return this; - - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > bars = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < BarSymbols > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( m_Data ) ); - - return new PrefixRankedBarTree < > ( std::move ( bars ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -319,6 +310,17 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < tree::PrefixRankedBarTree < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::PrefixRankedBarTree < SymbolType, RankType >, tree::PrefixRankedBarTree < > >::value >::type > { + static tree::PrefixRankedBarTree < > eval ( tree::PrefixRankedBarTree < SymbolType, RankType > && value ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > bars = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getBars ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( value ).getContent ( ) ); + + return tree::PrefixRankedBarTree < > ( std::move ( bars ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* PREFIX_RANKED_BAR_TREE_H_ */ diff --git a/alib2data/src/tree/ranked/PrefixRankedNonlinearPattern.h b/alib2data/src/tree/ranked/PrefixRankedNonlinearPattern.h index 83a5b0a94dadcfdac118d260c0b2f577b538fa14..aaa42e6bce5c7ed907bda3d438e4d278ef8771e4 100644 --- a/alib2data/src/tree/ranked/PrefixRankedNonlinearPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedNonlinearPattern.h @@ -29,6 +29,8 @@ #include <alphabet/SubtreeWildcardSymbol.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -127,18 +129,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef PrefixRankedNonlinearPattern < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( PrefixRankedNonlinearPattern < > ) == typeid ( PrefixRankedNonlinearPattern < SymbolType, RankType > ) ) - return this; - - common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( this->template accessElement < SubtreeWildcard > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > nonlinearAlphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < NonlinearAlphabet > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( m_Data ) ); - - return new PrefixRankedNonlinearPattern < > ( std::move ( wildcard ), std::move ( nonlinearAlphabet ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -361,6 +351,18 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < tree::PrefixRankedNonlinearPattern < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::PrefixRankedNonlinearPattern < SymbolType, RankType >, tree::PrefixRankedNonlinearPattern < > >::value >::type > { + static tree::PrefixRankedNonlinearPattern < > eval ( tree::PrefixRankedNonlinearPattern < SymbolType, RankType > && value ) { + common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( value ).getSubtreeWildcard ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > nonlinearAlphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getNonlinearVariables ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( value ).getContent ( ) ); + + return tree::PrefixRankedNonlinearPattern < > ( std::move ( wildcard ), std::move ( nonlinearAlphabet ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* PREFIX_RANKED_NONLINEAR_PATTERN_H_ */ diff --git a/alib2data/src/tree/ranked/PrefixRankedPattern.h b/alib2data/src/tree/ranked/PrefixRankedPattern.h index f7f93a44d9ff43d6f496fd8b0759908b800a51c5..34eb38d355c7aa3e76d058d872f681f7ab6ebfa1 100644 --- a/alib2data/src/tree/ranked/PrefixRankedPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedPattern.h @@ -29,6 +29,8 @@ #include <alphabet/SubtreeWildcardSymbol.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -114,17 +116,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef PrefixRankedPattern < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( PrefixRankedPattern < > ) == typeid ( PrefixRankedPattern < SymbolType, RankType > ) ) - return this; - - common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( this->template accessElement < SubtreeWildcard > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( m_Data ) ); - - return new PrefixRankedPattern < > ( std::move ( wildcard ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -303,6 +294,17 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < tree::PrefixRankedPattern < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::PrefixRankedPattern < SymbolType, RankType >, tree::PrefixRankedPattern < > >::value >::type > { + static tree::PrefixRankedPattern < > eval ( tree::PrefixRankedPattern < SymbolType, RankType > && value ) { + common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( value ).getSubtreeWildcard ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( value ).getContent ( ) ); + + return tree::PrefixRankedPattern < > ( std::move ( wildcard ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* PREFIX_RANKED_PATTERN_H_ */ diff --git a/alib2data/src/tree/ranked/PrefixRankedTree.h b/alib2data/src/tree/ranked/PrefixRankedTree.h index 005e9775ace1aab141ea813758b0e19ee87b1fee..3d8960080f16e10a5ca1c5b206adc0592611d1bb 100644 --- a/alib2data/src/tree/ranked/PrefixRankedTree.h +++ b/alib2data/src/tree/ranked/PrefixRankedTree.h @@ -27,6 +27,8 @@ #include "../common/TreeToXMLComposer.h" #include <tree/common/TreeNormalize.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -102,16 +104,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef PrefixRankedTree < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( PrefixRankedTree < > ) == typeid ( PrefixRankedTree < SymbolType, RankType > ) ) - return this; - - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( m_Data ) ); - - return new PrefixRankedTree < > ( std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -270,6 +262,16 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < tree::PrefixRankedTree < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::PrefixRankedTree < SymbolType, RankType >, tree::PrefixRankedTree < > >::value >::type > { + static tree::PrefixRankedTree < > eval ( tree::PrefixRankedTree < SymbolType, RankType > && value ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = alphabet::SymbolNormalize::normalizeRankedSymbols ( std::move ( value ).getContent ( ) ); + + return tree::PrefixRankedTree < > ( std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* PREFIX_RANKED_TREE_H_ */ diff --git a/alib2data/src/tree/ranked/RankedNonlinearPattern.h b/alib2data/src/tree/ranked/RankedNonlinearPattern.h index e03fa77a88be40f2bf53637f629001d8b82a7ab6..35166ad717039142b79681137bafbb7b4c072d75 100644 --- a/alib2data/src/tree/ranked/RankedNonlinearPattern.h +++ b/alib2data/src/tree/ranked/RankedNonlinearPattern.h @@ -28,6 +28,8 @@ #include "../common/TreeAuxiliary.h" #include <tree/common/TreeNormalize.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -135,18 +137,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef RankedNonlinearPattern < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( RankedNonlinearPattern < > ) == typeid ( RankedNonlinearPattern < SymbolType, RankType > ) ) - return this; - - common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( this->template accessElement < SubtreeWildcard > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > nonlinearAlphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < NonlinearAlphabet > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::tree < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = TreeNormalize::normalizeRankedTree ( std::move ( m_content ) ); - - return new RankedNonlinearPattern < > ( std::move ( wildcard ), std::move ( nonlinearAlphabet ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -331,6 +321,18 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < tree::RankedNonlinearPattern < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::RankedNonlinearPattern < SymbolType, RankType >, tree::RankedNonlinearPattern < > >::value >::type > { + static tree::RankedNonlinearPattern < > eval ( tree::RankedNonlinearPattern < SymbolType, RankType > && value ) { + common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( value ).getSubtreeWildcard ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > nonlinearAlphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getNonlinearVariables ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::tree < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = tree::TreeNormalize::normalizeRankedTree ( std::move ( value ).getContent ( ) ); + + return tree::RankedNonlinearPattern < > ( std::move ( wildcard ), std::move ( nonlinearAlphabet ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* RANKED_NONLINEAR_PATTERN_H_ */ diff --git a/alib2data/src/tree/ranked/RankedPattern.h b/alib2data/src/tree/ranked/RankedPattern.h index 913a6df28eebf18ed5178739c0ea88b2ea9b464d..a01abd6817b388553eba72698d14c299c6d62d91 100644 --- a/alib2data/src/tree/ranked/RankedPattern.h +++ b/alib2data/src/tree/ranked/RankedPattern.h @@ -28,6 +28,8 @@ #include "../common/TreeAuxiliary.h" #include <tree/common/TreeNormalize.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -125,17 +127,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef RankedPattern < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( RankedPattern < > ) == typeid ( RankedPattern < SymbolType, RankType > ) ) - return this; - - common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( this->template accessElement < SubtreeWildcard > ( ).get ( ) ) ); - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::tree < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = TreeNormalize::normalizeRankedTree ( std::move ( m_content ) ); - - return new RankedPattern < > ( std::move ( wildcard ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -291,6 +282,17 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < tree::RankedPattern < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::RankedPattern < SymbolType, RankType >, tree::RankedPattern < > >::value >::type > { + static tree::RankedPattern < > eval ( tree::RankedPattern < SymbolType, RankType > && value ) { + common::ranked_symbol < DefaultSymbolType, DefaultRankType > wildcard = alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( value ).getSubtreeWildcard ( ) ); + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::tree < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = tree::TreeNormalize::normalizeRankedTree ( std::move ( value ).getContent ( ) ); + + return tree::RankedPattern < > ( std::move ( wildcard ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* RANKED_PATTERN_H_ */ diff --git a/alib2data/src/tree/ranked/RankedTree.h b/alib2data/src/tree/ranked/RankedTree.h index 31818582cb9042d0ab21e65f893c08822f89fd3a..88b9a28135056da53d39490e238d7b41876ad1af 100644 --- a/alib2data/src/tree/ranked/RankedTree.h +++ b/alib2data/src/tree/ranked/RankedTree.h @@ -29,6 +29,8 @@ #include <tree/common/TreeNormalize.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -118,16 +120,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef RankedTree < > normalized_type; - - virtual RankedTreeBase * normalize ( ) && { - if ( typeid ( RankedTree < > ) == typeid ( RankedTree < SymbolType, RankType > ) ) - return this; - - ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::tree < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = TreeNormalize::normalizeRankedTree ( std::move ( m_content ) ); - - return new RankedTree < > ( std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -273,6 +265,16 @@ public: } }; +template < class SymbolType, class RankType > +struct normalize < tree::RankedTree < SymbolType, RankType >, typename std::enable_if < ! std::is_same < tree::RankedTree < SymbolType, RankType >, tree::RankedTree < > >::value >::type > { + static tree::RankedTree < > eval ( tree::RankedTree < SymbolType, RankType > && value ) { + ext::set < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > alphabet = alphabet::SymbolNormalize::normalizeRankedAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::tree < common::ranked_symbol < DefaultSymbolType, DefaultRankType > > content = tree::TreeNormalize::normalizeRankedTree ( std::move ( value ).getContent ( ) ); + + return tree::RankedTree < > ( std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* RANKED_TREE_H_ */ diff --git a/alib2data/src/tree/unranked/PrefixBarTree.h b/alib2data/src/tree/unranked/PrefixBarTree.h index 9a406158833243d0503695cbe064f1a6faa77e05..4356645be90d737f71a7910cbe9b7d7aa0aca986 100644 --- a/alib2data/src/tree/unranked/PrefixBarTree.h +++ b/alib2data/src/tree/unranked/PrefixBarTree.h @@ -28,6 +28,8 @@ #include <alphabet/BarSymbol.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -112,17 +114,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef PrefixBarTree < > normalized_type; - - virtual UnrankedTreeBase * normalize ( ) && { - if ( typeid ( PrefixBarTree < > ) == typeid ( PrefixBarTree < SymbolType > ) ) - return this; - - DefaultSymbolType bar = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < BarSymbol > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::vector < DefaultSymbolType > content = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( m_Data ) ); - - return new PrefixBarTree < > ( std::move ( bar ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -303,6 +294,17 @@ public: } }; +template < class SymbolType > +struct normalize < tree::PrefixBarTree < SymbolType >, typename std::enable_if < ! std::is_same < tree::PrefixBarTree < SymbolType >, tree::PrefixBarTree < > >::value >::type > { + static tree::PrefixBarTree < > eval ( tree::PrefixBarTree < SymbolType > && value ) { + DefaultSymbolType bar = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getBar ( ) ); + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::vector < DefaultSymbolType > content = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( value ).getContent ( ) ); + + return tree::PrefixBarTree < > ( std::move ( bar ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* PREFIX_BAR_TREE_H_ */ diff --git a/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h b/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h index 52abf2ae8567f07a5f182dbbc970611e4a5a2382..31e9bb379d1ea16874600d1b10cb74fd75c94689 100644 --- a/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h +++ b/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h @@ -27,6 +27,8 @@ #include "../common/TreeAuxiliary.h" #include <tree/common/TreeNormalize.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -139,18 +141,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef UnrankedNonlinearPattern < > normalized_type; - - virtual UnrankedTreeBase * normalize ( ) && { - if ( typeid ( UnrankedNonlinearPattern < > ) == typeid ( UnrankedNonlinearPattern < SymbolType > ) ) - return this; - - DefaultSymbolType wildcard = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < SubtreeWildcard > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > nonlinearAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < NonlinearAlphabet > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::tree < DefaultSymbolType > content = TreeNormalize::normalizeTree ( std::move ( m_content ) ); - - return new UnrankedNonlinearPattern < > ( std::move ( wildcard ), std::move ( nonlinearAlphabet ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -319,6 +309,18 @@ public: } }; +template < class SymbolType > +struct normalize < tree::UnrankedNonlinearPattern < SymbolType >, typename std::enable_if < ! std::is_same < tree::UnrankedNonlinearPattern < SymbolType >, tree::UnrankedNonlinearPattern < > >::value >::type > { + static tree::UnrankedNonlinearPattern < > eval ( tree::UnrankedNonlinearPattern < SymbolType > && value ) { + DefaultSymbolType wildcard = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getSubtreeWildcard ( ) ); + ext::set < DefaultSymbolType > nonlinearAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getNonlinearVariables ( ) ); + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::tree < DefaultSymbolType > content = tree::TreeNormalize::normalizeTree ( std::move ( value ).getContent ( ) ); + + return tree::UnrankedNonlinearPattern < > ( std::move ( wildcard ), std::move ( nonlinearAlphabet ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* UNRANKED_NONLINEAR_PATTERN_H_ */ diff --git a/alib2data/src/tree/unranked/UnrankedPattern.h b/alib2data/src/tree/unranked/UnrankedPattern.h index 0770226641519d84ca3b3ca6397b116adcb6a701..f4e57d99aaa0294e6160bc05ccb69ee2acc73cf5 100644 --- a/alib2data/src/tree/unranked/UnrankedPattern.h +++ b/alib2data/src/tree/unranked/UnrankedPattern.h @@ -27,6 +27,8 @@ #include "../common/TreeAuxiliary.h" #include <tree/common/TreeNormalize.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -123,17 +125,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef UnrankedPattern < > normalized_type; - - virtual UnrankedTreeBase * normalize ( ) && { - if ( typeid ( UnrankedPattern < > ) == typeid ( UnrankedPattern < SymbolType > ) ) - return this; - - DefaultSymbolType wildcard = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( this->template accessElement < SubtreeWildcard > ( ).get ( ) ) ); - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::tree < DefaultSymbolType > content = TreeNormalize::normalizeTree ( std::move ( m_content ) ); - - return new UnrankedPattern < > ( std::move ( wildcard ), std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -277,6 +268,17 @@ public: } }; +template < class SymbolType > +struct normalize < tree::UnrankedPattern < SymbolType >, typename std::enable_if < ! std::is_same < tree::UnrankedPattern < SymbolType >, tree::UnrankedPattern < > >::value >::type > { + static tree::UnrankedPattern < > eval ( tree::UnrankedPattern < SymbolType > && value ) { + DefaultSymbolType wildcard = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getSubtreeWildcard ( ) ); + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::tree < DefaultSymbolType > content = tree::TreeNormalize::normalizeTree ( std::move ( value ).getContent ( ) ); + + return tree::UnrankedPattern < > ( std::move ( wildcard ), std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* UNRANKED_PATTERN_H_ */ diff --git a/alib2data/src/tree/unranked/UnrankedTree.h b/alib2data/src/tree/unranked/UnrankedTree.h index 46e6e618487b8d33d76e1668e9885a5109b9f19c..ef2b0667c0d4e959bf6b8acead13f33b0b32631c 100644 --- a/alib2data/src/tree/unranked/UnrankedTree.h +++ b/alib2data/src/tree/unranked/UnrankedTree.h @@ -27,6 +27,8 @@ #include "../common/TreeAuxiliary.h" #include <tree/common/TreeNormalize.h> +#include <core/normalize.hpp> + namespace tree { class GeneralAlphabet; @@ -114,16 +116,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef UnrankedTree < > normalized_type; - - virtual UnrankedTreeBase * normalize ( ) && { - if ( typeid ( UnrankedTree < > ) == typeid ( UnrankedTree < SymbolType > ) ) - return this; - - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ); - ext::tree < DefaultSymbolType > content = TreeNormalize::normalizeTree ( std::move ( m_content ) ); - - return new UnrankedTree < > ( std::move ( alphabet ), std::move ( content ) ); - } }; } /* namespace tree */ @@ -254,6 +246,16 @@ public: } }; +template < class SymbolType > +struct normalize < tree::UnrankedTree < SymbolType >, typename std::enable_if < ! std::is_same < tree::UnrankedTree < SymbolType >, tree::UnrankedTree < > >::value >::type > { + static tree::UnrankedTree < > eval ( tree::UnrankedTree < SymbolType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); + ext::tree < DefaultSymbolType > content = tree::TreeNormalize::normalizeTree ( std::move ( value ).getContent ( ) ); + + return tree::UnrankedTree < > ( std::move ( alphabet ), std::move ( content ) ); + } +}; + } /* namespace alib */ #endif /* UNRANKED_TREE_H_ */ diff --git a/alib2data/test-src/string/StringTest.cpp b/alib2data/test-src/string/StringTest.cpp index ecfd931a31a0dfe3c4463a98d100ff9ed6dd17a8..c1c5499ba17851bea45c4909b8ec944f6c8da6b0 100644 --- a/alib2data/test-src/string/StringTest.cpp +++ b/alib2data/test-src/string/StringTest.cpp @@ -102,58 +102,51 @@ void StringTest::testStringInMap ( ) { } void StringTest::testNormalize ( ) { - string::LinearString < char > raw ( ext::vector < char > { 'a', 'b' } ); - string::String s1 ( raw ); - s1.normalize ( ); - string::String s2 ( raw ); + string::LinearString < char > s1 ( ext::vector < char > { 'a', 'b' } ); + string::LinearString < > s2 = alib::normalize < string::LinearString < char > >::eval ( string::LinearString < char > ( s1 ) ); std::string tmp1 = alib::XmlDataFactory::toString ( s1 ); std::cout << tmp1 << std::endl; - string::String s1x = alib::XmlDataFactory::fromString ( tmp1 ); + string::LinearString < > s1x = alib::XmlDataFactory::fromString ( tmp1 ); std::string tmp2 = alib::XmlDataFactory::toString ( s2 ); std::cout << tmp2 << std::endl; - string::String s2x = alib::XmlDataFactory::fromString ( tmp2 ); + string::LinearString < > s2x = alib::XmlDataFactory::fromString ( tmp2 ); CPPUNIT_ASSERT ( s1x == s2x ); } void StringTest::testNormalize2 ( ) { - string::LinearString < alib::Object > raw ( ext::vector < alib::Object > { alib::Object ( 'a' ), alib::Object ( 'b' ) } ); - string::String s1 ( raw ); - s1.normalize ( ); - string::String s2 ( raw ); + string::LinearString < alib::Object > s1 ( ext::vector < alib::Object > { alib::Object ( 'a' ), alib::Object ( 'b' ) } ); + string::LinearString < > s2 = alib::normalize < string::LinearString < alib::Object > >::eval ( string::LinearString < alib::Object > ( s1 ) ); std::string tmp1 = alib::XmlDataFactory::toString ( s1 ); std::cout << tmp1 << std::endl; - string::String s1x = alib::XmlDataFactory::fromString ( tmp1 ); + string::LinearString < > s1x = alib::XmlDataFactory::fromString ( tmp1 ); std::string tmp2 = alib::XmlDataFactory::toString ( s2 ); std::cout << tmp2 << std::endl; - string::String s2x = alib::XmlDataFactory::fromString ( tmp2 ); + string::LinearString < > s2x = alib::XmlDataFactory::fromString ( tmp2 ); CPPUNIT_ASSERT ( s1 == s1x ); CPPUNIT_ASSERT ( s1 == s2x ); } void StringTest::testNormalize3 ( ) { - string::LinearString < ext::set < char > > raw ( ext::vector < ext::set < char > > { ext::set < char > { 'a' }, ext::set < char > { 'b' } } ); - string::String s1 ( raw ); - s1.normalize ( ); - string::String s2 ( raw ); + string::LinearString < ext::set < char > > s1 ( ext::vector < ext::set < char > > { ext::set < char > { 'a' }, ext::set < char > { 'b' } } ); + string::LinearString < > s2 = alib::normalize < string::LinearString < ext::set < char > > >::eval ( string::LinearString < ext::set < char > > ( s1 ) ); std::string tmp1 = alib::XmlDataFactory::toString ( s1 ); std::cout << tmp1 << std::endl; - string::String s1x = alib::XmlDataFactory::fromString ( tmp1 ); + string::LinearString < > s1x = alib::XmlDataFactory::fromString ( tmp1 ); std::string tmp2 = alib::XmlDataFactory::toString ( s2 ); std::cout << tmp2 << std::endl; - string::String s2x = alib::XmlDataFactory::fromString ( tmp2 ); + string::LinearString < > s2x = alib::XmlDataFactory::fromString ( tmp2 ); CPPUNIT_ASSERT ( s1x == s2x ); - string::LinearString < alib::Object > rawRef ( ext::vector < alib::Object > { alib::Object ( container::ObjectsSet < alib::Object > ( ext::set < alib::Object > { alib::Object ( primitive::Character ( 'a' ) ) } ) ), alib::Object ( container::ObjectsSet < alib::Object > ( ext::set < alib::Object > { alib::Object ( primitive::Character ( 'b' ) ) } ) ) } ); - string::String ref ( rawRef ); + string::LinearString < alib::Object > ref ( ext::vector < alib::Object > { alib::Object ( container::ObjectsSet < alib::Object > ( ext::set < alib::Object > { alib::Object ( primitive::Character ( 'a' ) ) } ) ), alib::Object ( container::ObjectsSet < alib::Object > ( ext::set < alib::Object > { alib::Object ( primitive::Character ( 'b' ) ) } ) ) } ); std::cout << s1x << std::endl; std::cout << ref << std::endl; diff --git a/alib2data_experimental/src/graph/directed/AdjacencyListDirectedGraph.h b/alib2data_experimental/src/graph/directed/AdjacencyListDirectedGraph.h index 4e677d946459b1c6c419e586b8a581c01b152ae4..4c76f9f83785d4b44296470b70002545981b1263 100644 --- a/alib2data_experimental/src/graph/directed/AdjacencyListDirectedGraph.h +++ b/alib2data_experimental/src/graph/directed/AdjacencyListDirectedGraph.h @@ -92,10 +92,6 @@ public: alib::ObjectBase * inc ( ) && override; typedef AdjacencyListDirectedGraph normalized_type; - - virtual AdjacencyListDirectedGraph * normalize ( ) && override { - return this; - } }; } // namespace graph diff --git a/alib2data_experimental/src/graph/directed/AdjacencyMatrixDirectedGraph.h b/alib2data_experimental/src/graph/directed/AdjacencyMatrixDirectedGraph.h index 48914374e1d064dc3e1015f9e47b0522661be907..a82e1a6a84d07182d3f36573e8da06c1fbe969b6 100644 --- a/alib2data_experimental/src/graph/directed/AdjacencyMatrixDirectedGraph.h +++ b/alib2data_experimental/src/graph/directed/AdjacencyMatrixDirectedGraph.h @@ -95,10 +95,6 @@ public: alib::ObjectBase * inc ( ) && override; typedef AdjacencyMatrixDirectedGraph normalized_type; - - virtual AdjacencyMatrixDirectedGraph * normalize ( ) && override { - return this; - } }; } // namespace graph diff --git a/alib2data_experimental/src/graph/undirected/AdjacencyListUndirectedGraph.h b/alib2data_experimental/src/graph/undirected/AdjacencyListUndirectedGraph.h index cb766efa52d6f02c84cc5876242e1c16a685c521..982af1776a5ad4882f467dd5bddfa0761c66aa8a 100644 --- a/alib2data_experimental/src/graph/undirected/AdjacencyListUndirectedGraph.h +++ b/alib2data_experimental/src/graph/undirected/AdjacencyListUndirectedGraph.h @@ -89,10 +89,6 @@ public: alib::ObjectBase * inc ( ) && override; typedef AdjacencyListUndirectedGraph normalized_type; - - virtual AdjacencyListUndirectedGraph * normalize ( ) && override { - return this; - } }; } // namespace graph diff --git a/alib2data_experimental/src/graph/undirected/AdjacencyMatrixUndirectedGraph.h b/alib2data_experimental/src/graph/undirected/AdjacencyMatrixUndirectedGraph.h index a577858bded6365d939d1b0ba4578e6d6064e637..779dfa67de1fae22dd1f52ff4e69349e143b5f4f 100644 --- a/alib2data_experimental/src/graph/undirected/AdjacencyMatrixUndirectedGraph.h +++ b/alib2data_experimental/src/graph/undirected/AdjacencyMatrixUndirectedGraph.h @@ -92,10 +92,6 @@ public: alib::ObjectBase * inc ( ) && override; typedef AdjacencyMatrixUndirectedGraph normalized_type; - - virtual AdjacencyMatrixUndirectedGraph * normalize ( ) && override { - return this; - } }; } // namespace graph diff --git a/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.h b/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.h index b8c930af0a0c039af8e1a86ce9177f00c51771da..8defbea305826e543ba8fe9fe8f80c0807b16fee 100644 --- a/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.h +++ b/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.h @@ -110,10 +110,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef SuffixTrieTerminatingSymbol normalized_type; - - virtual SuffixTrieTerminatingSymbol * normalize ( ) && { - return this; - } }; } /* namespace tree */ diff --git a/alib2data_experimental/src/string/LinearStringTerminatingSymbol.h b/alib2data_experimental/src/string/LinearStringTerminatingSymbol.h index 172beb7e08d4262bbbca9b8d2b0e8aac6e683e39..2e386ad0afc23a2598c2082c4968823f1f46b9af 100644 --- a/alib2data_experimental/src/string/LinearStringTerminatingSymbol.h +++ b/alib2data_experimental/src/string/LinearStringTerminatingSymbol.h @@ -93,10 +93,6 @@ public: virtual alib::ObjectBase * inc ( ) &&; typedef LinearStringTerminatingSymbol normalized_type; - - virtual LinearStringTerminatingSymbol * normalize ( ) && { - return this; - } }; } /* namespace string */ diff --git a/alib2std/src/extensions/type_traits.hpp b/alib2std/src/extensions/type_traits.hpp index 214292277a8a1b9602c039310d8ee9d8da9e1a82..3eace89a9036d159961c04711b5d6b06ec2835c2 100644 --- a/alib2std/src/extensions/type_traits.hpp +++ b/alib2std/src/extensions/type_traits.hpp @@ -25,17 +25,6 @@ namespace ext { static const bool value = sizeof(Yes) == sizeof(has_clone::test((typename std::remove_reference<T>::type*)0)); }; - template<class T> - struct has_normalize { - typedef char (&Yes)[1]; - typedef char (&No)[2]; - - template<class U> - static Yes test(U * data, typename std::enable_if< std::is_pointer<decltype(std::move ( * data ).normalize())>::value>::type * = 0); - static No test(...); - static const bool value = sizeof(Yes) == sizeof(has_normalize::test((typename std::remove_reference<T>::type*)0)); - }; - // ---------------------------------------------------------------------------------------------------- template < size_t N, typename ... T >