From 8e230a76cecccfd47599028b589739ec9d9a8eab Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Wed, 29 Mar 2017 13:06:58 +0200 Subject: [PATCH] normalize strings --- alib2data/src/string/CyclicString.h | 14 ++++++++++++++ alib2data/src/string/Epsilon.h | 10 ++++++++++ alib2data/src/string/LinearString.h | 14 ++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/alib2data/src/string/CyclicString.h b/alib2data/src/string/CyclicString.h index b73a41a81c..8386a23477 100644 --- a/alib2data/src/string/CyclicString.h +++ b/alib2data/src/string/CyclicString.h @@ -24,6 +24,8 @@ #include "common/StringAuxiliary.h" #include <exception/CommonException.h> +#include <object/AnyObject.h> + namespace string { class GeneralAlphabet; @@ -90,6 +92,18 @@ public: void compose ( std::deque < sax::Token > & out ) const; virtual alib::ObjectBase * inc ( ) &&; + + virtual StringBase * normalize ( ) && { + std::set < DefaultSymbolType > alphabet; + for ( SymbolType && symbol : std::make_moveable_set ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ) { + alphabet.insert ( DefaultSymbolType ( alib::AnyObject < SymbolType > ( std::move ( symbol ) ) ) ); + } + std::vector < DefaultSymbolType > content; + for ( SymbolType & symbol : m_Data ) { + content.push_back ( DefaultSymbolType ( alib::AnyObject < SymbolType > ( std::move ( symbol ) ) ) ); + } + return new CyclicString < > ( std::move ( alphabet ), std::move ( content ) ); + } }; } /* namespace string */ diff --git a/alib2data/src/string/Epsilon.h b/alib2data/src/string/Epsilon.h index 58b8eff986..743b149c77 100644 --- a/alib2data/src/string/Epsilon.h +++ b/alib2data/src/string/Epsilon.h @@ -20,6 +20,8 @@ #include "common/StringFromXMLParser.h" #include "common/StringToXMLComposer.h" +#include <object/AnyObject.h> + namespace string { class GeneralAlphabet; @@ -83,6 +85,14 @@ public: void compose ( std::deque < sax::Token > & out ) const; virtual alib::ObjectBase * inc ( ) &&; + + virtual StringBase * normalize ( ) && { + std::set < DefaultSymbolType > alphabet; + for ( SymbolType && symbol : std::make_moveable_set ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ) { + alphabet.insert ( DefaultSymbolType ( alib::AnyObject < SymbolType > ( std::move ( symbol ) ) ) ); + } + return new Epsilon < > ( std::move ( alphabet ) ); + } }; template < class SymbolType > diff --git a/alib2data/src/string/LinearString.h b/alib2data/src/string/LinearString.h index 40f48337c2..44ef8f2af6 100644 --- a/alib2data/src/string/LinearString.h +++ b/alib2data/src/string/LinearString.h @@ -26,6 +26,8 @@ #include "../tree/TreeFeatures.h" +#include <object/AnyObject.h> + namespace string { class GeneralAlphabet; @@ -110,6 +112,18 @@ public: void compose ( std::deque < sax::Token > & out ) const; virtual alib::ObjectBase * inc ( ) &&; + + virtual StringBase * normalize ( ) && { + std::set < DefaultSymbolType > alphabet; + for ( SymbolType && symbol : std::make_moveable_set ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ) ) { + alphabet.insert ( DefaultSymbolType ( alib::AnyObject < SymbolType > ( std::move ( symbol ) ) ) ); + } + std::vector < DefaultSymbolType > content; + for ( SymbolType & symbol : m_Data ) { + content.push_back ( DefaultSymbolType ( alib::AnyObject < SymbolType > ( std::move ( symbol ) ) ) ); + } + return new LinearString < > ( std::move ( alphabet ), std::move ( content ) ); + } }; } /* namespace string */ -- GitLab