Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Concepts
FormalRegExpSymbol.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26
27#include "FormalRegExpElement.h"
29
30namespace regexp {
31
41template < class SymbolType >
42class FormalRegExpSymbol : public ext::NullaryNode < FormalRegExpElement < SymbolType > > {
46 SymbolType m_symbol;
47
51 void accept ( typename FormalRegExpElement < SymbolType >::Visitor & visitor ) const override {
52 visitor.visit ( * this );
53 }
54
55public:
61 explicit FormalRegExpSymbol ( SymbolType symbol );
62
67
71 FormalRegExpSymbol < SymbolType > * clone ( ) && override;
72
76 ext::smart_ptr < UnboundedRegExpElement < SymbolType > > asUnbounded ( ) const override;
77
81 bool testSymbol ( const SymbolType & symbol ) const override;
82
86 void computeMinimalAlphabet ( ext::set < SymbolType > & alphabet ) const override;
87
91 bool checkAlphabet ( const ext::set < SymbolType > & alphabet ) const override;
92
98 const SymbolType & getSymbol ( ) const &;
99
105 SymbolType && getSymbol ( ) &&;
106
110 std::strong_ordering operator <=> ( const FormalRegExpElement < SymbolType > & other ) const override {
111 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this <=> static_cast < decltype ( ( * this ) ) > ( other );
112
113 return ext::type_index ( typeid ( * this ) ) <=> ext::type_index ( typeid ( other ) );
114 }
115
123 std::strong_ordering operator <=> ( const FormalRegExpSymbol < SymbolType > & ) const;
124
128 bool operator == ( const FormalRegExpElement < SymbolType > & other ) const override {
129 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this == static_cast < decltype ( ( * this ) ) > ( other );
130
131 return false;
132 }
133
142
146 void operator >>( ext::ostream & out ) const override;
147
153 }
154};
155
156} /* namespace regexp */
157
158#include "../unbounded/UnboundedRegExpSymbol.h"
159
160namespace regexp {
161
162template < class SymbolType >
163FormalRegExpSymbol < SymbolType >::FormalRegExpSymbol ( SymbolType symbol ) : m_symbol ( std::move ( symbol ) ) {
164}
165
166template < class SymbolType >
168 return new FormalRegExpSymbol ( * this );
169}
170
171template < class SymbolType >
172FormalRegExpSymbol < SymbolType > * FormalRegExpSymbol < SymbolType >::clone ( ) && {
173 return new FormalRegExpSymbol ( std::move ( * this ) );
174}
175
176template < class SymbolType >
179}
180
181template < class SymbolType >
183 return m_symbol <=> other.m_symbol;
184}
185
186template < class SymbolType >
188 return m_symbol == other.m_symbol;
189}
190
191template < class SymbolType >
193 out << "(FormalRegExpSymbol " << m_symbol << ")";
194}
195
196template < class SymbolType >
198 return symbol == this->m_symbol;
199}
200
201template < class SymbolType >
203 alphabet.insert ( m_symbol );
204}
205
206template < class SymbolType >
208 return alphabet.count ( m_symbol );
209}
210
211template < class SymbolType >
213 return this->m_symbol;
214}
215
216template < class SymbolType >
218 return std::move ( this->m_symbol );
219}
220
221} /* namespace regexp */
222
224
static DefaultSymbolType normalizeSymbol(SymbolType &&symbol)
Definition: SymbolNormalize.h:68
Nullary node is specialisation of Anyary node to no children.
Definition: tree_base.hpp:358
Definition: ostream.h:14
Definition: set.hpp:44
Managed pointer simulating value like behavior.
Definition: memory.hpp:233
Definition: typeindex.h:37
Definition: FormalRegExpElement.h:67
virtual void visit(const FormalRegExpAlternation< SymbolType > &)=0
Definition: FormalRegExpElement.h:62
Represents the symbol in the regular expression. The can't have any children.
Definition: FormalRegExpSymbol.h:42
const SymbolType & getSymbol() const &
Definition: FormalRegExpSymbol.h:212
bool checkAlphabet(const ext::set< SymbolType > &alphabet) const override
Definition: FormalRegExpSymbol.h:207
bool operator==(const FormalRegExpElement< SymbolType > &other) const override
< SymbolType >::operator == ( const FormalRegExpElement < SymbolType > & other ) const;
Definition: FormalRegExpSymbol.h:128
FormalRegExpSymbol< SymbolType > * clone() const &override
( ) const &
FormalRegExpSymbol(SymbolType symbol)
Creates a new instance of the symbol node using the actual symbol to represent.
Definition: FormalRegExpSymbol.h:163
void operator>>(ext::ostream &out) const override
< FormalRegExpElement < SymbolType > >::operator >> ( ext::ostream & )
Definition: FormalRegExpSymbol.h:192
bool testSymbol(const SymbolType &symbol) const override
Definition: FormalRegExpSymbol.h:197
std::strong_ordering operator<=>(const FormalRegExpElement< SymbolType > &other) const override
< SymbolType >::operator <=> ( const FormalRegExpElement < SymbolType > & other ) const;
Definition: FormalRegExpSymbol.h:110
ext::smart_ptr< FormalRegExpElement< DefaultSymbolType > > normalize() &&override
< SymbolType >::normalize ( ) &&
Definition: FormalRegExpSymbol.h:151
ext::smart_ptr< UnboundedRegExpElement< SymbolType > > asUnbounded() const override
( ) const &
Definition: FormalRegExpSymbol.h:177
void computeMinimalAlphabet(ext::set< SymbolType > &alphabet) const override
Definition: FormalRegExpSymbol.h:202
Definition: UnboundedRegExpElement.h:62
Represents the symbol in the regular expression. The can't have any children.
Definition: UnboundedRegExpSymbol.h:42
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: sigHandler.cpp:20
Definition: ToAutomaton.h:15
Definition: FordFulkerson.hpp:16