Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
LinearStringTerminatingSymbol.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/iostream>
9
10#include <alib/set>
11#include <alib/vector>
12#include <alib/deque>
13
14#include <core/components.hpp>
15
16#include <sax/Token.h>
17#include <core/xmlApi.hpp>
18
19#include <string/LinearString.h>
20
21namespace string {
22
23class GeneralAlphabet;
24class TerminatingSymbol;
25
30class LinearStringTerminatingSymbol final : public core::Components < LinearStringTerminatingSymbol, ext::set < DefaultSymbolType >, component::Set, GeneralAlphabet, DefaultSymbolType, component::Value, TerminatingSymbol > {
32
33public:
34 explicit LinearStringTerminatingSymbol ( DefaultSymbolType terminatingSymbol );
37 explicit LinearStringTerminatingSymbol ( DefaultSymbolType terminatingSymbol, const LinearString < > & str );
38
39 virtual const ext::set < DefaultSymbolType > & getAlphabet ( ) const {
40 return accessComponent < GeneralAlphabet > ( ).get ( );
41 }
42
44 accessComponent < GeneralAlphabet > ( ).add( symbols );
45 }
46
48 return accessComponent < TerminatingSymbol > ( ).get ( );
49 }
50
54 void appendSymbol ( DefaultSymbolType symbol );
55
60
62
66 bool isEmpty ( ) const;
67
68 auto operator <=> ( const LinearStringTerminatingSymbol & other ) const {
69 return std::tie ( m_Data, getAlphabet() ) <=> std::tie ( other.m_Data, other.getAlphabet() );
70 }
71
72 bool operator == ( const LinearStringTerminatingSymbol & other ) const {
73 return std::tie ( m_Data, getAlphabet() ) == std::tie ( other.m_Data, other.getAlphabet() );
74 }
75
76 friend ext::ostream & operator << ( ext::ostream & out, const LinearStringTerminatingSymbol & instance );
77};
78
79} /* namespace string */
80
81namespace core {
82
83template < >
84struct xmlApi < string::LinearStringTerminatingSymbol > {
86 static bool first ( const ext::deque < sax::Token >::const_iterator & input );
87 static std::string xmlTagName ( );
88 static void compose ( ext::deque < sax::Token > & output, const string::LinearStringTerminatingSymbol & data );
89};
90
91template < >
92class SetConstraint< string::LinearStringTerminatingSymbol, DefaultSymbolType, string::GeneralAlphabet > {
93public:
94 static bool used ( const string::LinearStringTerminatingSymbol & str, const DefaultSymbolType & symbol ) {
95 const ext::vector<DefaultSymbolType>& content = str.getContent ( );
96 return std::find(content.begin(), content.end(), symbol) != content.end();
97 }
98
100 return true;
101 }
102
104 }
105};
106
107template < >
108class ElementConstraint< string::LinearStringTerminatingSymbol, DefaultSymbolType, string::TerminatingSymbol > {
109public:
110 static bool available ( const string::LinearStringTerminatingSymbol & str, const DefaultSymbolType & symbol ) {
111 return str.getAlphabet ( ).contains ( symbol );
112 }
113
115 }
116};
117
118} /* namespace core */
119
Definition: components.hpp:181
static void valid(const string::LinearStringTerminatingSymbol &, const DefaultSymbolType &)
Definition: LinearStringTerminatingSymbol.h:114
static bool available(const string::LinearStringTerminatingSymbol &str, const DefaultSymbolType &symbol)
Definition: LinearStringTerminatingSymbol.h:110
Definition: components.hpp:25
static bool available(const string::LinearStringTerminatingSymbol &, const DefaultSymbolType &)
Definition: LinearStringTerminatingSymbol.h:99
static void valid(const string::LinearStringTerminatingSymbol &, const DefaultSymbolType &)
Definition: LinearStringTerminatingSymbol.h:103
static bool used(const string::LinearStringTerminatingSymbol &str, const DefaultSymbolType &symbol)
Definition: LinearStringTerminatingSymbol.h:94
Definition: setComponents.hpp:26
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Definition: ostream.h:14
Definition: set.hpp:44
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: vector.hpp:125
auto end() &
Inherited behavior of end for non-const instance.
Definition: vector.hpp:155
Definition: Object.h:16
Definition: LinearStringTerminatingSymbol.h:30
void extendAlphabet(const ext::set< DefaultSymbolType > &symbols)
Definition: LinearStringTerminatingSymbol.h:43
const DefaultSymbolType & getTerminatingSymbol() const
Definition: LinearStringTerminatingSymbol.h:47
void appendSymbol(DefaultSymbolType symbol)
Definition: LinearStringTerminatingSymbol.cpp:35
bool operator==(const LinearStringTerminatingSymbol &other) const
Definition: LinearStringTerminatingSymbol.h:72
auto operator<=>(const LinearStringTerminatingSymbol &other) const
Definition: LinearStringTerminatingSymbol.h:68
LinearStringTerminatingSymbol(DefaultSymbolType terminatingSymbol)
Definition: LinearStringTerminatingSymbol.cpp:26
void setContent(ext::vector< DefaultSymbolType > data)
Definition: LinearStringTerminatingSymbol.cpp:46
virtual const ext::set< DefaultSymbolType > & getAlphabet() const
Definition: LinearStringTerminatingSymbol.h:39
const ext::vector< DefaultSymbolType > & getContent() const
Definition: LinearStringTerminatingSymbol.cpp:42
bool isEmpty() const
Definition: LinearStringTerminatingSymbol.cpp:57
friend ext::ostream & operator<<(ext::ostream &out, const LinearStringTerminatingSymbol &instance)
Definition: LinearStringTerminatingSymbol.cpp:61
Linear string.
Definition: LinearString.h:57
Definition: BarSymbol.cpp:12
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
Definition: RandomStringFactory.cpp:12
Definition: xmlApi.hpp:27