Awali
Another Weighted Automata library
kind.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2021 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_CORE_KIND_HH
18 # define AWALI_CORE_KIND_HH
19 
20 # include <istream>
21 # include <stdexcept>
22 # include <type_traits>
23 
25 
26 namespace awali { namespace sttc {
27 
28 
42 
43 # define DEFINE(Abbrev, Name) \
44  struct labels_are_ ## Name \
45  { \
46  static std::string name() \
47  { \
48  return "labels_are_" #Name; \
49  } \
50  static std::string sname() \
51  { \
52  return #Abbrev; \
53  } \
54  \
55  static void make(std::istream& is) \
56  { \
57  /* \
58  * name: lal_char(abc)_ratexpset<law_char(xyz)_b>. \
59  * ^^^ ^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ \
60  * | | | weightset \
61  * | | +-- gens \
62  * | +-- letter_type \
63  * +-- kind \
64  * \
65  * name: lao_ratexpset<law_char(xyz)_b> \
66  * ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ \
67  * kind weightset \
68  */ \
69  char kind[4]; \
70  is.get(kind, sizeof kind); \
71  if (sname() != kind) \
72  throw std::runtime_error("kind::make: unexpected: " \
73  + str_escape(kind) \
74  + ", expected: " + sname()); \
75  } \
76  \
77  }; \
78 
79  /* \
80  template <typename Kinded> \
81  struct is_ ## Abbrev \
82  : std::is_same<typename Kinded::kind_t, labels_are_ ## Name>::type \
83  {}; \
84  \
85  */
87  DEFINE(lal, letters);
89  DEFINE(lan, nullable);
91  DEFINE(lao, one);
93  DEFINE(lar, ratexps);
95  DEFINE(lat, tuples);
97  DEFINE(law, words);
98 
99 # undef DEFINE
100 }}//end of ns awali::stc
101 
102 #endif // !AWALI_CORE_KIND_HH
#define DEFINE(Abbrev, Name)
Define the kinds, and auxiliary tools.
Definition: kind.hh:43
sttc::tupleset< ValueSets... > lat
Definition: lat.hh:22
nullableset< T > lan
Definition: lan.hh:28
oneset lao
Definition: lao.hh:26
Main namespace of Awali.
Definition: ato.hh:22