scenario_simulator_v2 C++ API
rule.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef OPENSCENARIO_INTERPRETER__SYNTAX__RULE_HPP_
16 #define OPENSCENARIO_INTERPRETER__SYNTAX__RULE_HPP_
17 
18 #include <functional>
20 #include <string>
21 #include <utility>
22 
24 {
25 inline namespace syntax
26 {
27 /*
28  Rule (OpenSCENARIO XML 1.3)
29 
30  <xsd:simpleType name="Rule">
31  <xsd:union>
32  <xsd:simpleType>
33  <xsd:restriction base="xsd:string">
34  <xsd:enumeration value="equalTo"/>
35  <xsd:enumeration value="greaterThan"/>
36  <xsd:enumeration value="lessThan"/>
37  <xsd:enumeration value="greaterOrEqual"/>
38  <xsd:enumeration value="lessOrEqual"/>
39  <xsd:enumeration value="notEqualTo"/>
40  </xsd:restriction>
41  </xsd:simpleType>
42  <xsd:simpleType>
43  <xsd:restriction base="parameter"/>
44  </xsd:simpleType>
45  </xsd:union>
46  </xsd:simpleType>
47 */
48 struct Rule
49 {
50  enum value_type {
57  } value;
58 
59  Rule() = default;
60 
61  explicit Rule(value_type value) : value(value) {}
62 
63  constexpr operator value_type() const noexcept { return value; }
64 
65  template <typename T, typename U = T>
66  constexpr auto operator()(const T & lhs, const U & rhs) const noexcept
67  {
68  switch (value) {
69  case equalTo:
70  return equal_to<T>()(std::forward<decltype(lhs)>(lhs), std::forward<decltype(rhs)>(rhs));
71  case greaterThan:
72  return std::greater<void>()(
73  std::forward<decltype(lhs)>(lhs), std::forward<decltype(rhs)>(rhs));
74  case lessThan:
75  return std::less<void>()(
76  std::forward<decltype(lhs)>(lhs), std::forward<decltype(rhs)>(rhs));
77  case greaterOrEqual:
78  return std::greater_equal<T>()(
79  std::forward<decltype(lhs)>(lhs), std::forward<decltype(rhs)>(rhs));
80  case lessOrEqual:
81  return std::less_equal<T>()(
82  std::forward<decltype(lhs)>(lhs), std::forward<decltype(rhs)>(rhs));
83  case notEqualTo:
84  return std::not_equal_to<T>()(
85  std::forward<decltype(lhs)>(lhs), std::forward<decltype(rhs)>(rhs));
86  default:
87  return false;
88  }
89  }
90 };
91 
92 auto operator>>(std::istream &, Rule &) -> std::istream &;
93 
94 auto operator<<(std::ostream &, const Rule &) -> std::ostream &;
95 
96 } // namespace syntax
97 } // namespace openscenario_interpreter
98 
99 #endif // OPENSCENARIO_INTERPRETER__SYNTAX__RULE_HPP_
auto operator>>(std::istream &, Boolean &) -> std::istream &
Definition: boolean.cpp:52
auto operator<<(std::ostream &, const Boolean &) -> std::ostream &
Definition: boolean.cpp:46
Definition: escape_sequence.hpp:22
Definition: rule.hpp:49
Rule(value_type value)
Definition: rule.hpp:61
constexpr auto operator()(const T &lhs, const U &rhs) const noexcept
Definition: rule.hpp:66
@ lessThan
Definition: rule.hpp:53
@ notEqualTo
Definition: rule.hpp:56
@ greaterOrEqual
Definition: rule.hpp:54
@ lessOrEqual
Definition: rule.hpp:55
@ equalTo
Definition: rule.hpp:51
@ greaterThan
Definition: rule.hpp:52
enum openscenario_interpreter::syntax::Rule::value_type value