Traits.h
Go to the documentation of this file.
1 #pragma once
3 
4 namespace lanelet {
5 namespace traits {
6 struct PointTag {};
7 struct BoundingBoxTag {};
8 struct LineStringTag {};
9 struct PolygonTag {};
10 struct LaneletTag {};
11 struct AreaTag {};
13 
19 template <typename T>
21  using DataType = typename T::DataType;
22  using ConstType = typename T::ConstType;
23  using MutableType = typename T::MutableType;
24  using TwoDType = typename T::TwoDType;
25  using ThreeDType = typename T::ThreeDType;
26  using Category = typename T::Category;
27 };
28 
29 // specialization for RegulatoryElementPtr
30 template <>
38 };
39 template <>
47 };
48 
50 template <typename PrimitiveT>
51 struct Owned {
52  using Type = PrimitiveT;
53 };
54 
55 template <>
57  using Type = Point3d;
58 };
59 
60 template <>
61 struct Owned<Polygon3d> {
62  using Type = Point3d;
63 };
64 
65 template <>
66 struct Owned<Lanelet> {
67  using Type = LineString3d;
68 };
69 
70 template <>
71 struct Owned<Area> {
72  using Type = LineString3d;
73 };
74 
75 template <typename PrimitiveT>
77 
79 template <typename PrimitiveT>
81 
83 template <typename PrimitiveT>
85 
87 template <typename PrimitiveT>
89 
91 template <typename PrimitiveT>
93 
95 template <typename PrimitiveT>
96 auto to3D(const PrimitiveT& primitive) -> ThreeD<PrimitiveT> {
97  return ThreeD<PrimitiveT>(primitive);
98 }
99 
101 template <typename PrimitiveT>
102 auto to2D(const PrimitiveT& primitive) -> TwoD<PrimitiveT> {
103  return TwoD<PrimitiveT>(primitive);
104 }
105 
107 template <typename PrimitiveT>
108 ConstPrimitiveType<PrimitiveT> toConst(const PrimitiveT& primitive) {
109  return ConstPrimitiveType<PrimitiveT>(primitive);
110 }
111 
112 template <typename PrimitiveT>
113 constexpr bool isConst() {
114  return std::is_same<PrimitiveT, ConstPrimitiveType<PrimitiveT>>::value;
115 }
116 
118 template <typename PrimitiveT>
119 constexpr bool is2D() {
120  return std::is_same<std::decay_t<PrimitiveT>, TwoD<PrimitiveT>>::value;
121 }
122 
124 template <typename PrimitiveT>
125 constexpr bool is3D() {
126  return std::is_same<std::decay_t<PrimitiveT>, ThreeD<PrimitiveT>>::value;
127 }
128 
129 enum class Dimensions { Two = 2, Three = 3 };
130 
132 template <typename PointT>
133 struct PointTraits : PrimitiveTraits<PointT> {
134  using BasicPoint = typename PointT::BasicPoint;
137  static constexpr bool IsPrimitive = true;
138  static constexpr Dimensions Dimension = PointT::Dimension;
139 };
140 
142 template <typename LineStringT>
143 struct LineStringTraits : PrimitiveTraits<LineStringT> {
145  using HybridType = typename LineStringT::HybridType;
146 };
147 
149 template <typename PolygonT>
150 struct PolygonTraits : PrimitiveTraits<PolygonT> {
151  using PointType = typename PolygonT::PointType;
152  using HybridType = typename PolygonT::HybridType;
153 };
154 
155 template <typename PointT>
157 
158 template <typename PointT>
160 
161 template <typename PointT>
163 
164 template <typename PointT>
165 auto toBasicPoint(const PointT& point) -> std::enable_if_t<PointTraits<PointT>::IsPrimitive, BasicPointT<PointT>> {
166  return point.basicPoint();
167 }
168 template <typename PointT>
169 auto toBasicPoint(const PointT& point)
170  -> std::enable_if_t<!PointTraits<PointT>::IsPrimitive && std::is_same<PointT, BasicPointT<PointT>>::value, PointT> {
171  return point;
172 }
173 template <typename PointT>
174 auto toBasicPoint(const PointT& point)
175  -> std::enable_if_t<!PointTraits<PointT>::IsPrimitive && !std::is_same<PointT, BasicPointT<PointT>>::value,
177  return BasicPointT<PointT>(point);
178 }
179 
180 template <typename PrimT, typename TagT>
181 constexpr bool isCategory() {
182  return std::is_same<typename PrimitiveTraits<std::decay_t<PrimT>>::Category, TagT>::value;
183 }
184 
185 template <typename T>
186 constexpr bool noRegelem() {
187  return !traits::isCategory<T, traits::RegulatoryElementTag>();
188 }
189 
190 template <typename LineStringT>
192 
193 template <typename PrimT>
194 Id getId(const PrimT& prim) {
195  return prim.id();
196 }
197 } // namespace traits
198 
199 namespace utils {
200 // make trait based helper functions available in utils namespace
201 using traits::getId;
202 using traits::to2D;
203 using traits::to3D;
205 using traits::toConst;
206 } // namespace utils
207 } // namespace lanelet
typename LineStringT ::DataType DataType
Definition: Traits.h:21
typename PolygonT::PointType PointType
Definition: Traits.h:151
typename Owned< PrimitiveT >::Type OwnedT
Definition: Traits.h:76
std::shared_ptr< RegulatoryElement > RegulatoryElementPtr
Definition: Forward.h:192
Specialization of traits for polygons.
Definition: Traits.h:150
constexpr bool isCategory()
Definition: Traits.h:181
typename PointTraits< PointT >::BasicPoint BasicPointT
Definition: Traits.h:156
ConstPrimitiveType< PrimitiveT > toConst(const PrimitiveT &primitive)
Converts a primitive to its matching const type.
Definition: Traits.h:108
int64_t Id
Definition: Forward.h:198
Specialization of traits for linestrings.
Definition: Traits.h:143
typename LineStringTraits< LineStringT >::PointType PointType
Definition: Traits.h:191
typename PointTraits< PointT >::ConstPoint ConstPointT
Definition: Traits.h:159
The famous (mutable) lanelet class.
Identifies LaneletPrimitives.
Definition: Traits.h:11
typename LineStringT ::MutableType MutableType
Definition: Traits.h:23
constexpr bool isConst()
Definition: Traits.h:113
typename PrimitiveTraits< PrimitiveT >::ThreeDType ThreeD
f Utility for determinig the matching three dimensional type for a primitive
Definition: Traits.h:92
Identifies PolygonPrimitives.
Definition: Traits.h:10
Identifies bounding boxes.
Definition: Traits.h:8
typename PrimitiveTraits< PointT >::ConstType ConstPoint
Definition: Traits.h:135
Identifies RegulatoryElementPrimitives.
Definition: Traits.h:20
Identifies LineStringPrimitives.
Definition: Traits.h:9
A normal 3d linestring with mutable data.
A mutable 3d point.
typename PolygonT::HybridType HybridType
Definition: Traits.h:152
typename LineStringT::PointType PointType
Definition: Traits.h:144
PrimitiveT Type
Definition: Traits.h:52
Identifies PointPrimitives.
Definition: Traits.h:7
Data container for all RegulatoryElement types.
typename PrimitiveTraits< PrimitiveT >::ConstType ConstPrimitiveType
Utility for determinig the matching const type for a primitive.
Definition: Traits.h:80
std::shared_ptr< const RegulatoryElement > RegulatoryElementConstPtr
Definition: Forward.h:194
typename PointT::BasicPoint BasicPoint
Definition: Traits.h:134
typename PrimitiveTraits< PrimitiveT >::TwoDType TwoD
Utility for determinig the matching two dimensional type for a primitive.
Definition: Traits.h:88
A mutable clockwise oriented, open (ie start point != end point) polygon in 3d.
typename LineStringT ::TwoDType TwoDType
Definition: Traits.h:24
Famous Area class that represents a basic area as element of the map.
Can be used to determine which primitive type is managed by a primitive.
Definition: Traits.h:51
constexpr bool noRegelem()
Definition: Traits.h:186
auto toBasicPoint(const PointT &point) -> std::enable_if_t< PointTraits< PointT >::IsPrimitive, BasicPointT< PointT >>
Definition: Traits.h:165
constexpr bool is3D()
Checks (at compile time) whether a primitive is three dimensional.
Definition: Traits.h:125
typename LineStringT ::ThreeDType ThreeDType
Definition: Traits.h:25
BoundingBox2d to2D(const BoundingBox3d &primitive)
typename LineStringT ::Category Category
Definition: Traits.h:26
constexpr bool is2D()
Checks (at compile time) whether a primitive is two dimensional.
Definition: Traits.h:119
Id getId(const PrimT &prim)
Definition: Traits.h:194
typename PointTraits< PointT >::MutablePoint MutablePointT
Definition: Traits.h:162
BoundingBox3d to3D(const BoundingBox2d &primitive)
Identifies AreaPrimitives.
Definition: Traits.h:12
Specialization of traits for points.
Definition: Traits.h:133
typename LineStringT::HybridType HybridType
Definition: Traits.h:145
typename PrimitiveTraits< PointT >::MutableType MutablePoint
Definition: Traits.h:136
typename PrimitiveTraits< PrimitiveT >::MutableType MutablePrimitiveType
Utility for determinig the matching mutable type for a primitive.
Definition: Traits.h:84
typename LineStringT ::ConstType ConstType
Definition: Traits.h:22


lanelet2_core
Author(s): Fabian Poggenhans
autogenerated on Tue Jun 6 2023 02:23:32