Awali
Another Weighted Automata library
priority.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 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 PRIORITY_HH
18 #define PRIORITY_HH
19 
20 #include<utility>
21 
22 namespace awali{
23 namespace priority {
24 
25 
26 /* Concept: priority::value is of any of the type priority::ONE<T>,
27  * priority::TWO<T>, priority::THREE<T>, etc.. for some type T (different each
28  * time).
29  * Since it is more specific, static linkage will preferentially use a function
30  * using FIVE<T>, over FOUR<T>, over THREE<T>, etc...
31  * Example: assuming existence of functions:
32  * - template<typename P> f(..., ONE<P>) and
33  * - template<typename P> f(..., TWO<P>)
34  * Then a call to f(..., priority::value) will always call the second function.
35  * This is useful when multiple algorithms that are doing the same thing are
36  * conditional (eg. works only for some weightsets) and we don't wan't to
37  * enforce that only one function f(...) exists at the same time.
38  * (Cf algos/are-equivalent.hh for a use case)
39  *
40  * On order to allow usage to be more transparent give types:
41  * - priority::TOP<T>
42  * - priority::HIGH<T>
43  * - priority::MEDIUM<T>
44  * - priority::LOW<T>
45  * - priority::BOTTOM<T>
46  * Hence if both functions
47  * - template<typename P> f(..., MEDIUM<P>) and
48  * - template<typename P> f(..., HIGH<P>)
49  * exists, a call to f(...,priority::value) will choose the second one.
50  */
51  template<typename T>
52  struct _p {
53  };
54 
55  template<typename T>
56  using ONE = _p<T>;
57 
58 
59  template<typename T>
60  using TWO = _p<_p<T>>;
61 
62  template<typename T>
63  using THREE = _p<_p<_p<T>>>;
64 
65  template<typename T>
66  using FOUR = _p<_p<_p<_p<T>>>>;
67 
68  template<typename T>
69  using FIVE = _p<_p<_p<_p<_p<T>>>>>;
70 
71  // These values are for dynamical fallback between priorities
72  static constexpr FIVE<void> five;
73  static constexpr FOUR<void> four;
74  static constexpr THREE<void> three;
75  static constexpr TWO<void> two;
76  static constexpr ONE<void> one;
77 
78  template<typename T>
79  using TOP = FIVE<T>;
80 
81  template<typename T>
82  using HIGH = FOUR<T>;
83 
84  template<typename T>
85  using MEDIUM = THREE<T>;
86 
87  template<typename T>
88  using LOW = TWO<T>;
89 
90  template<typename T>
91  using BOTTOM = ONE<T>;
92 
93  static constexpr TOP<void> value, top;
94  static constexpr HIGH<void> high;
95  static constexpr MEDIUM<void> medium;
96  static constexpr LOW<void> low;
97  static constexpr BOTTOM<void> bottom;
98 
99 } //end of ns priority
100 } //end of ns awali
101 
102 
103 #endif /* PRIORITY_HH */
static constexpr TOP< void > value
Definition: priority.hh:93
static constexpr FIVE< void > five
Definition: priority.hh:72
static constexpr FOUR< void > four
Definition: priority.hh:73
static constexpr MEDIUM< void > medium
Definition: priority.hh:95
static constexpr THREE< void > three
Definition: priority.hh:74
static constexpr TWO< void > two
Definition: priority.hh:75
static constexpr ONE< void > one
Definition: priority.hh:76
static constexpr HIGH< void > high
Definition: priority.hh:94
static constexpr BOTTOM< void > bottom
Definition: priority.hh:97
static constexpr LOW< void > low
Definition: priority.hh:96
static constexpr TOP< void > top
Definition: priority.hh:93
Definition: priority.hh:52
Main namespace of Awali.
Definition: ato.hh:22