Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
UnboundedRegExp.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
27
28namespace regexp {
29
30template < class SymbolType = DefaultSymbolType >
31class UnboundedRegExp;
32
33} /* namespace regexp */
34
35#include <ext/iostream>
36#include <ext/algorithm>
37
38#include <alib/string>
39#include <alib/set>
40
41#include <core/components.hpp>
43
45
46#include <core/normalize.hpp>
48
49#include "../formal/FormalRegExp.h"
50
51namespace regexp {
52
53class GeneralAlphabet;
54
79template < class SymbolType >
80class UnboundedRegExp final : public core::Components < UnboundedRegExp < SymbolType >, ext::set < SymbolType >, component::Set, GeneralAlphabet > {
85
86public:
91
95 explicit UnboundedRegExp ( );
96
104
111
115 explicit UnboundedRegExp ( const FormalRegExp < SymbolType > & other );
116
123 return this->template accessComponent < GeneralAlphabet > ( ).get ( );
124 }
125
132 return std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) );
133 }
134
141
148
155
163 auto operator <=> ( const UnboundedRegExp & other ) const {
164 return std::tie ( m_regExp.getStructure ( ), getAlphabet ( ) ) <=> std::tie ( other.m_regExp.getStructure ( ), other.getAlphabet ( ) );
165 }
166
174 bool operator == ( const UnboundedRegExp & other ) const {
175 return std::tie ( m_regExp.getStructure ( ), getAlphabet ( ) ) == std::tie ( other.m_regExp.getStructure ( ), other.getAlphabet ( ) );
176 }
177
186 friend ext::ostream & operator << ( ext::ostream & out, const UnboundedRegExp & instance ) {
187 return out << "(UnboundedRegExp " << instance.getRegExp ( ).getStructure ( ) << ")";
188 }
189};
190
191template < class SymbolType >
193 if ( !this->m_regExp.getStructure ( ).checkAlphabet ( getAlphabet ( ) ) )
194 throw exception::CommonException ( "Input symbols not in the alphabet." );
195}
196
197template < class SymbolType >
199}
200
201template < class SymbolType >
202UnboundedRegExp < SymbolType >::UnboundedRegExp ( UnboundedRegExpStructure < SymbolType > regExp ) : UnboundedRegExp ( regExp.getStructure ( ).computeMinimalAlphabet ( ), regExp ) {
203}
204
205template < class SymbolType >
207}
208
209template < class SymbolType >
211 return m_regExp;
212}
213
214template < class SymbolType >
216 return std::move ( m_regExp );
217}
218
219template < class SymbolType >
221 if ( !param.getStructure ( ).checkAlphabet ( getAlphabet ( ) ) )
222 throw exception::CommonException ( "Input symbols not in the alphabet." );
223
224 this->m_regExp = std::move ( param );
225}
226
227} /* namespace regexp */
228
229namespace core {
230
236template < class SymbolType >
237class SetConstraint< regexp::UnboundedRegExp < SymbolType >, SymbolType, regexp::GeneralAlphabet > {
238public:
247 static bool used ( const regexp::UnboundedRegExp < SymbolType > & regexp, const SymbolType & symbol ) {
248 return regexp.getRegExp ( ).getStructure ( ).testSymbol ( symbol );
249 }
250
260 return true;
261 }
262
269 static void valid ( const regexp::UnboundedRegExp < SymbolType > &, const SymbolType & ) {
270 }
271};
272
278template < class SymbolType >
279struct normalize < regexp::UnboundedRegExp < SymbolType > > {
282
283 return regexp::UnboundedRegExp < > ( alphabet, std::move ( value ).getRegExp ( ).normalize ( ) );
284 }
285};
286
287} /* namespace core */
288
289extern template class regexp::UnboundedRegExp < >;
290
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
Definition: components.hpp:181
static void valid(const regexp::UnboundedRegExp< SymbolType > &, const SymbolType &)
Definition: UnboundedRegExp.h:269
static bool used(const regexp::UnboundedRegExp< SymbolType > &regexp, const SymbolType &symbol)
Definition: UnboundedRegExp.h:247
static bool available(const regexp::UnboundedRegExp< SymbolType > &, const SymbolType &)
Definition: UnboundedRegExp.h:259
Definition: setComponents.hpp:26
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
Definition: ostream.h:14
Definition: set.hpp:44
Formal regular expression represents regular expression. It describes regular languages....
Definition: FormalRegExp.h:78
Represents unbounded regular expression structure. Regular expression is stored as a tree of Unbounde...
Definition: UnboundedRegExpStructure.h:47
Unbounded regular expression represents regular expression. It describes regular languages....
Definition: UnboundedRegExp.h:80
ext::set< SymbolType > && getAlphabet() &&
Definition: UnboundedRegExp.h:131
SymbolType symbol_type
Definition: UnboundedRegExp.h:90
const ext::set< SymbolType > & getAlphabet() const &
Definition: UnboundedRegExp.h:122
UnboundedRegExp()
Creates a new instance of the expression. The default constructor creates expression describing empty...
Definition: UnboundedRegExp.h:198
friend ext::ostream & operator<<(ext::ostream &out, const UnboundedRegExp &instance)
Definition: UnboundedRegExp.h:186
bool operator==(const UnboundedRegExp &other) const
Definition: UnboundedRegExp.h:174
void setRegExp(UnboundedRegExpStructure< SymbolType > param)
Definition: UnboundedRegExp.h:220
const UnboundedRegExpStructure< SymbolType > & getRegExp() const &
Definition: UnboundedRegExp.h:210
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
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: ToAutomaton.h:15
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
static regexp::UnboundedRegExp< > eval(regexp::UnboundedRegExp< SymbolType > &&value)
Definition: UnboundedRegExp.h:280
Definition: normalize.hpp:13