Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRTESymbolAlphabet.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#include "FormalRTESymbol.h"
27
29#include <ext/utility>
31
32namespace rte {
33
43template < class SymbolType >
44class FormalRTESymbolAlphabet : public FormalRTESymbol < SymbolType >, public ext::VararyNode < FormalRTEElement < SymbolType > > {
48 void accept ( typename FormalRTEElement < SymbolType >::ConstVisitor & visitor ) const override {
49 visitor.visit ( * this );
50 }
51
55 void accept ( typename FormalRTEElement < SymbolType >::Visitor & visitor ) override {
56 visitor.visit ( * this );
57 }
58
59public:
66
71
76
80 bool testSymbol ( const common::ranked_symbol < SymbolType > & symbol ) const override;
81
85 void computeMinimalAlphabet ( ext::set < common::ranked_symbol < SymbolType > > & alphabetF, ext::set < common::ranked_symbol < SymbolType > > & alphabetK ) const override;
86
90 bool checkAlphabet ( const ext::set < common::ranked_symbol < SymbolType > > & alphabetF, const ext::set < common::ranked_symbol < SymbolType > > & alphabetK ) const override;
91
97 const ext::ptr_vector < FormalRTEElement < SymbolType > > & getElements ( ) const;
98
104 const ext::ptr_vector < FormalRTEElement < SymbolType > > & getElements ( );
105
111 const FormalRTEElement < SymbolType > & getElement ( size_t index ) const;
112
118 FormalRTEElement < SymbolType > & getElement ( size_t index );
119
126 void setElement ( size_t index, const FormalRTEElement < SymbolType > & element );
127
134 void setElement ( size_t index, FormalRTEElement < SymbolType > && element );
135
139 std::strong_ordering operator <=> ( const FormalRTEElement < SymbolType > & other ) const override {
140 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this <=> static_cast < decltype ( ( * this ) ) > ( other );
141
142 return ext::type_index ( typeid ( * this ) ) <=> ext::type_index ( typeid ( other ) );
143 }
144
152 std::strong_ordering operator <=> ( const FormalRTESymbolAlphabet < SymbolType > & ) const;
153
157 bool operator == ( const FormalRTEElement < SymbolType > & other ) const override {
158 if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return * this == static_cast < decltype ( ( * this ) ) > ( other );
159
160 return false;
161 }
162
171
175 void operator >>( ext::ostream & out ) const override;
176
182 for ( FormalRTEElement < SymbolType > && element : ext::make_mover ( std::move ( * this ).getChildren ( ) ) )
183 children.push_back ( std::move ( * std::move ( element ).normalize ( ) ) );
184
186 }
187};
188
189template < class SymbolType >
191 if ( this->getChildren ( ).size ( ) != this->getSymbol ( ).getRank ( ) )
192 throw exception::CommonException ( "Symbol's rank and number of children differ. Rank is " + ext::to_string ( this->getSymbol ( ).getRank ( ) ) + ", number of children is " + ext::to_string ( this->getChildren ( ).size ( ) ) + "." );
193
194}
195
196template < class SymbolType >
198 return new FormalRTESymbolAlphabet ( * this );
199}
200
201template < class SymbolType >
202FormalRTESymbolAlphabet < SymbolType > * FormalRTESymbolAlphabet < SymbolType >::clone ( ) && {
203 return new FormalRTESymbolAlphabet ( std::move ( * this ) );
204}
205
206template < class SymbolType >
208 return this->getChildren ( );
209}
210
211template < class SymbolType >
213 return this->getChildren ( );
214}
215
216template < class SymbolType >
218 return this->getChild ( index );
219}
220
221template < class SymbolType >
223 return this->getChild ( index );
224}
225
226template < class SymbolType >
228 setElement ( index, ext::move_copy ( element ) );
229}
230
231template < class SymbolType >
233 this->setChild ( std::move ( element ), index );
234}
235
236template < class SymbolType >
238 return std::tie ( this->getSymbol ( ), this->getChildren ( ) ) <=> std::tie ( other.getSymbol ( ), other.getChildren ( ) );
239}
240
241template < class SymbolType >
243 return std::tie ( this->getSymbol ( ), this->getChildren ( ) ) == std::tie ( other.getSymbol ( ), other.getChildren ( ) );
244}
245
246template < class SymbolType >
248 out << "(FormalRTESymbolAlphabet " << " symbol = " << this->getSymbol ( ) << " children = " << this->getChildren ( ) << "})";
249}
250
251template < class SymbolType >
253 return symbol == this->getSymbol ( );
254}
255
256template < class SymbolType >
258 alphabetF.insert ( this->getSymbol ( ) );
259
260 for ( const FormalRTEElement < SymbolType > & child : this->getElements ( ) )
261 child.computeMinimalAlphabet ( alphabetF, alphabetK );
262}
263
264template < class SymbolType >
266 return alphabetF.count ( this->getSymbol ( ) ) > 0 && std::all_of ( getElements ( ).begin ( ), getElements ( ).end ( ), [&] ( const FormalRTEElement < SymbolType > & e ) {
267 return e.checkAlphabet ( alphabetF, alphabetK );
268 } );
269}
270
271} /* namespace rte */
272
274
static common::ranked_symbol< DefaultSymbolType > normalizeRankedSymbol(common::ranked_symbol< SymbolType > &&symbol)
Definition: SymbolNormalize.h:81
Definition: ranked_symbol.hpp:20
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
Varary node is tree node that can hold any number of children.
Definition: tree_base.hpp:981
ext::ptr_vector< Data >::reverse_iterator insert(typename ext::ptr_vector< Data >::reverse_iterator it, const Data &d)
Inserts a new child at position specified by iterator.
Definition: tree_base.hpp:1187
Definition: ostream.h:14
Implementation of vector storing dynamicaly allocated instances of given type. The class mimicks the ...
Definition: ptr_vector.hpp:44
void push_back(R &&value)
Appends a new value at the end of the container.
Definition: ptr_vector.hpp:1228
Definition: set.hpp:44
Managed pointer simulating value like behavior.
Definition: memory.hpp:233
Definition: typeindex.h:37
Definition: FormalRTEElement.h:59
virtual void visit(const FormalRTEAlternation< SymbolType > &alternation)=0
Definition: FormalRTEElement.h:70
virtual void visit(FormalRTEAlternation< SymbolType > &alternation)=0
Definition: FormalRTEElement.h:54
Represents the terminal symbol in the regular tree expression. The number of children must be the sam...
Definition: FormalRTESymbolAlphabet.h:44
FormalRTESymbolAlphabet(common::ranked_symbol< SymbolType > symbol, ext::ptr_vector< FormalRTEElement< SymbolType > > children)
Creates a new instance of the symbol node using the actual symbol to represent.
Definition: FormalRTESymbolAlphabet.h:190
std::strong_ordering operator<=>(const FormalRTEElement< SymbolType > &other) const override
< SymbolType >::operator <=> ( const FormalRTEElement < SymbolType > & other ) const;
Definition: FormalRTESymbolAlphabet.h:139
void computeMinimalAlphabet(ext::set< common::ranked_symbol< SymbolType > > &alphabetF, ext::set< common::ranked_symbol< SymbolType > > &alphabetK) const override
< SymbolType >::computeMinimalAlphabet ( ext::set < common::ranked_symbol < SymbolType > > &,...
Definition: FormalRTESymbolAlphabet.h:257
void setElement(size_t index, const FormalRTEElement< SymbolType > &element)
Definition: FormalRTESymbolAlphabet.h:227
FormalRTESymbolAlphabet< SymbolType > * clone() const &override
< SymbolType >::clone ( ) const &
bool testSymbol(const common::ranked_symbol< SymbolType > &symbol) const override
< SymbolType >::testSymbol ( const common::ranked_symbol < SymbolType > & ) const
Definition: FormalRTESymbolAlphabet.h:252
const ext::ptr_vector< FormalRTEElement< SymbolType > > & getElements() const
Definition: FormalRTESymbolAlphabet.h:207
bool checkAlphabet(const ext::set< common::ranked_symbol< SymbolType > > &alphabetF, const ext::set< common::ranked_symbol< SymbolType > > &alphabetK) const override
< SymbolType >::checkAlphabet ( const ext::set < common::ranked_symbol < SymbolType > > &,...
Definition: FormalRTESymbolAlphabet.h:265
ext::smart_ptr< FormalRTEElement< DefaultSymbolType > > normalize() &&override
< SymbolType >::normalize ( ) &&
Definition: FormalRTESymbolAlphabet.h:180
bool operator==(const FormalRTEElement< SymbolType > &other) const override
< SymbolType >::operator == ( const FormalRTEElement < SymbolType > & other ) const;
Definition: FormalRTESymbolAlphabet.h:157
const FormalRTEElement< SymbolType > & getElement(size_t index) const
Definition: FormalRTESymbolAlphabet.h:217
void operator>>(ext::ostream &out) const override
< FormalRTEElement < SymbolType > >::operator >> ( ext::ostream & ) const
Definition: FormalRTESymbolAlphabet.h:247
Represents the common part of SubstitutionSymbol and TerminalSymbol.
Definition: FormalRTESymbol.h:37
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: Permutation.hpp:18
Definition: sigHandler.cpp:20
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
auto move_copy(const T &param)
Allow moving of copied instance of the source.
Definition: utility.hpp:45
reference_mover< T > make_mover(T &param)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
all_of(T &&...) -> all_of< T... >
Definition: ToFTAGlushkov.h:22
Definition: FordFulkerson.hpp:16