Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FailStateLabel.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 <compare>
27
28#include <object/Object.h>
29
30namespace label {
31
37public:
42 explicit FailStateLabel ( );
43
51 std::strong_ordering operator <=> ( const FailStateLabel & ) const {
52 return std::strong_ordering::equal;
53 }
54
62 bool operator == ( const FailStateLabel & ) const {
63 return true;
64 }
65
75
79 template < typename Base >
80 static inline Base instance ( );
81};
82
83template < typename Base >
84inline Base FailStateLabel::instance ( ) {
85 if constexpr ( std::is_integral_v < Base > ) {
86 return -1;
87 } else if constexpr ( std::is_same_v < Base, std::string > ) {
88 return std::string ( "fail" );
89 } else if constexpr ( std::is_same_v < Base, FailStateLabel > ) {
90 return FailStateLabel ( );
91 } else if constexpr ( std::is_same_v < Base, object::Object > ) {
92 return object::Object ( FailStateLabel ( ) );
93 } else {
94 static_assert ( std::is_same_v < Base, Base >, "Unsupported type of instance" );
95 }
96}
97
98} /* namespace label */
99
Definition: ostream.h:14
Represents label of the fail state of an automaton.
Definition: FailStateLabel.h:36
static Base instance()
Factory for the label construction of the label based on given type.
Definition: FailStateLabel.h:84
std::strong_ordering operator<=>(const FailStateLabel &) const
Definition: FailStateLabel.h:51
FailStateLabel()
Creates a new instance of the label.
friend ext::ostream & operator<<(ext::ostream &out, const FailStateLabel &instance)
Definition: FailStateLabel.cpp:16
bool operator==(const FailStateLabel &) const
Definition: FailStateLabel.h:62
Definition: Object.h:16
Definition: FailStateLabel.cpp:12