This namespace implements convenience functions to handle 3-value logic operations needed for applying diagram filters.
- See also
- clanguml::common::model::diagram_filter
-
clanguml::common::model::filter_visitor
|
using | value_t = std::optional< bool > |
|
◆ value_t
Alias for 3-value logic values
If optional holds nullopt, the value is undefined.
Definition at line 37 of file tvl.h.
◆ all_of()
template<typename InputIterator , typename Predicate >
value_t clanguml::common::model::tvl::all_of |
( |
InputIterator |
first, |
|
|
InputIterator |
last, |
|
|
Predicate |
pred |
|
) |
| |
|
inline |
3-value logic equivalent of std::all_of
- Template Parameters
-
InputIterator | Iterator type |
Predicate | Predicate type |
- Parameters
-
first | First iterator element |
last | Last iterator element |
pred | Predicate to apply to each element |
- Returns
- True, if all elements are true or undefined
Definition at line 113 of file tvl.h.
114{
116
117 for (InputIterator it = first; it != last; it++) {
118 value_t m = pred(*it);
119 if (m.has_value()) {
120 if (m.value()) {
121 res = true;
122 }
123 else {
124 res = false;
125 break;
126 }
127 }
128 }
129
130 return res;
131}
◆ and_()
Calculate 3-value logic AND value.
- Parameters
-
- Returns
- Result of AND operation.
Definition at line 46 of file tvl.h.
47{
48 if (!l.has_value())
49 return r;
50
51 if (!r.has_value())
52 return l;
53
54 return r.value() && l.value();
55}
◆ any_of()
template<typename InputIterator , typename Predicate >
value_t clanguml::common::model::tvl::any_of |
( |
InputIterator |
first, |
|
|
InputIterator |
last, |
|
|
Predicate |
pred |
|
) |
| |
|
inline |
3-value logic equivalent of std::any_of
- Template Parameters
-
InputIterator | Iterator type |
Predicate | Predicate type |
- Parameters
-
first | First iterator element |
last | Last iterator element |
pred | Predicate to apply to each element |
- Returns
- True, if at least 1 element is true
Definition at line 144 of file tvl.h.
145{
147
148 for (InputIterator it = first; it != last; it++) {
149 value_t m = pred(*it);
150 if (m.has_value()) {
151 if (m.value()) {
152 res = true;
153 return res;
154 }
155 res = false;
156 }
157 }
158
159 return res;
160}
◆ is_false()
bool clanguml::common::model::tvl::is_false |
( |
const value_t & |
v | ) |
|
|
inline |
Whether the value holds false
- Parameters
-
- Returns
- True, if v holds false
Definition at line 92 of file tvl.h.
92{ return v.has_value() && !v.value(); }
◆ is_true()
bool clanguml::common::model::tvl::is_true |
( |
const value_t & |
v | ) |
|
|
inline |
Whether the value holds true
- Parameters
-
- Returns
- True, if v holds true
Definition at line 84 of file tvl.h.
84{ return v.has_value() && v.value(); }
◆ is_undefined()
bool clanguml::common::model::tvl::is_undefined |
( |
const value_t & |
v | ) |
|
|
inline |
Whether the value is undefined
- Parameters
-
- Returns
- True, if v has no value
Definition at line 100 of file tvl.h.
100{ return !v.has_value(); }
◆ or_()
Calculate 3-value logic OR value.
- Parameters
-
- Returns
- Result of OR operation.
Definition at line 64 of file tvl.h.
65{
66 if (!l.has_value() && !r.has_value())
67 return {};
68
69 if (l.has_value() && l.value())
70 return true;
71
72 if (r.has_value() && r.value())
73 return true;
74
75 return false;
76}