Go to the documentation of this file.
3 #include <boost/variant.hpp>
66 static constexpr
const char Refers[] =
"refers";
67 static constexpr
const char RefLine[] =
"ref_line";
68 static constexpr
const char Yield[] =
"yield";
69 static constexpr
const char RightOfWay[] =
"right_of_way";
70 static constexpr
const char Cancels[] =
"cancels";
71 static constexpr
const char CancelLine[] =
"cancel_line";
74 static constexpr
const char Left[] =
"left";
75 static constexpr
const char Right[] =
"right";
77 static constexpr
const char Inner[] =
"inner";
78 static constexpr
const char Outer[] =
"outer";
79 static constexpr
const char Lanelet[] =
"lanelet";
90 using RuleParameter = boost::variant<Point3d, LineString3d, Polygon3d, WeakLanelet, WeakArea>;
94 boost::variant<ConstPoint3d, ConstLineString3d, ConstPolygon3d, ConstWeakLanelet, ConstWeakArea>;
176 private boost::noncopyable {
185 static constexpr
char RuleName[] =
"basic_regulatory_element";
201 template <
typename T>
203 static_assert(traits::isConst<T>(),
"You must pass a const primitive type");
204 auto it =
constData()->parameters.find(role);
208 return utils::getVariant<T>(it->second);
213 template <
typename T>
215 static_assert(traits::isConst<T>(),
"You must pass a const primitive type");
216 auto it =
constData()->parameters.find(role);
220 return utils::getVariant<T>(it->second);
224 std::vector<std::string>
roles()
const {
229 template <
typename T>
248 template <
typename T>
250 auto it =
data()->parameters.find(role);
254 return utils::getVariant<T>(it->second);
272 static constexpr
char RuleName[] =
"regulatory_element";
282 template <
typename PrimitiveT>
283 void addParameter(
const std::string& role,
const PrimitiveT& primitive);
286 template <
typename PrimitiveT>
325 bool has(
const RegulatoryElement& regElem,
Id id);
355 return create(ruleName, std::make_shared<RegulatoryElementData>(
id, map, attributes));
387 static_assert(!
utils::strequal(T::RuleName,
"basic_regulatory_element"),
388 "You did not provide a RuleName for your regulatoryElement!");
391 return std::shared_ptr<T>(
new T(data));
396 template <
typename PrimitiveT>
401 template <
typename PrimitiveT>
406 template <
typename T>
408 static_assert(traits::isConst<T>(),
"You must pass a const primitive type!");
411 for (
const auto& elem : params.second) {
412 auto telem = boost::get<MutableT>(&elem);
413 if (telem && telem->id() ==
id) {
424 for (
const auto& elem : params.second) {
434 inline boost::optional<ConstLanelet> RegulatoryElement::find<ConstLanelet>(
Id id)
const {
436 for (
const auto& elem : params.second) {
437 const auto* telem = boost::get<WeakLanelet>(&elem);
438 if (telem !=
nullptr && !telem->expired() && telem->lock().id() ==
id) {
439 return telem->lock();
447 inline boost::optional<ConstArea> RegulatoryElement::find<ConstArea>(
Id id)
const {
449 for (
const auto& elem : params.second) {
450 const auto* telem = boost::get<WeakArea>(&elem);
451 if (telem !=
nullptr && !telem->expired() && telem->lock().id() ==
id) {
452 return telem->lock();
467 return utils::strong(utils::getVariant<ConstWeakLanelet>(it->second));
475 return utils::strong(utils::getVariant<ConstWeakLanelet>(it->second));
484 return utils::strong(utils::getVariant<ConstWeakArea>(it->second));
492 return utils::strong(utils::getVariant<ConstWeakArea>(it->second));
496 template <
typename T>
499 return std::is_same<DataT, RegulatoryElementData>::value;
507 template <
typename T,
typename RetT>
508 using IfRE = std::enable_if_t<traits::isRegulatoryElementT<T>(), RetT>;
constexpr Id InvalId
indicates a primitive that is not part of a map
std::map< std::string, FactoryFcn > registry_
Base class for all mutable Primitives of lanelet2.
@ Cancels
primitive(s) that invalidate a rule (eg end of speed zone)
@ RefLine
The referring line where the rule becomes active.
std::vector< T > getParameters(RoleName role)
virtual ~RuleParameterVisitor()=default
std::vector< std::string > roles() const
returns all the roles this regulatory element has
A GenericRegulatoryElement can hold any parameters.
void setId(Id id) noexcept
Common data class for all lanelet primitives.
Data container for all RegulatoryElement types.
virtual void operator()(const ConstLineString3d &)
bool empty() const
returns true if this object contains no parameters
std::shared_ptr< RegulatoryElement > RegulatoryElementPtr
std::pair< const char *, const RoleName > RoleNamesItem
RuleParameterMap & parameters()
const AttributeMap & attributes() const
get the attributes of this primitive
ConstRuleParameter ConstType
static constexpr const char Inner[]
@ Yield
A lanelet that has to yield.
HybridMap< Attribute, decltype(AttributeNamesString::Map)&, AttributeNamesString::Map > AttributeMap
RoleName
Typical role names within lanelet (for faster lookup)
Id getId()
returns a unique id by incrementing a counter each time this is called.
Lists which role strings are mapped to which enum value.
Optional< T > find(Id id) const
Finds a parameter by its id, independent of the role.
std::shared_ptr< RegulatoryElementData > RegulatoryElementDataPtr
std::ostream & operator<<(std::ostream &stream, const Attribute &obj)
An immutable clockwise oriented, open (ie start point != end point) polygon in 3d.
auto transform(Iterator begin, Iterator end, const Func f)
Id getId< RegulatoryElementConstPtr >(const RegulatoryElementConstPtr &prim)
virtual ~MutableParameterVisitor()=default
size_t size() const
get the number of roles in this regulatoryElement
void applyVisitor(RuleParameterVisitor &visitor) const
applies a visitor to every parameter in the regulatory element
A general rule or limitation for a lanelet (abstract base class)
AttributeMap & attributes() noexcept
get the attributes in a mutable way
std::vector< T > getParameters(const std::string &role) const
Returns a vector of all RuleParameters that could be converted to T.
Creates regulatory elements based on their type.
std::string role
applyVisitor will set the current role here
std::vector< RuleParameter > RuleParameters
Multiple parameters can have the same role in a rule (eg traffic_lights)
RegulatoryElementFactory()=default
iterator find(const key_type &k)
static constexpr const char Refers[]
static constexpr const char Centerline[]
ConstRuleParameterMap getParameters() const
Returns all parameters as const object (coversion overhead for const)
const std::shared_ptr< const RegulatoryElementData > & constData() const
get the internal data of this primitive
virtual void operator()(const ConstPolygon3d &)
auto strong(std::vector< WeakT > v)
transforms a vector of weak_ptrs to a vector of shared_ptrs
Basic element for accessing and managing the elements of a map.
typename Map::iterator iterator
Defines right of way restrictions.
boost::optional< T > Optional
The famous (mutable) lanelet class.
boost::variant< ConstPoint3d, ConstLineString3d, ConstPolygon3d, ConstWeakLanelet, ConstWeakArea > ConstRuleParameter
Const-version of the parameters.
static constexpr const char Left[]
AttributeMap attributes
attributes of this primitive
static constexpr const char Cancels[]
virtual void operator()(const ConstWeakArea &)
used internally by RegulatoryElements to avoid cyclic dependencies.
GenericRegulatoryElement(Id id=InvalId, const RuleParameterMap ¶meters=RuleParameterMap(), const AttributeMap &attributes=AttributeMap())
Construct generically from id, parameters and attributes.
RegulatoryElement(Id id=InvalId, const RuleParameterMap &members=RuleParameterMap(), const AttributeMap &attributes=AttributeMap())
RegulatoryElement(const RegulatoryElementDataPtr &data)
Can be used to determine which primitive type is managed by a primitive.
void addParameter(const std::string &role, const PrimitiveT &primitive)
Add a (mutable) primitive to the regulatory element.
static constexpr const char CancelLine[]
typename PrimitiveTraits< PrimitiveT >::MutableType MutablePrimitiveType
Utility for determinig the matching mutable type for a primitive.
const_iterator end() const
virtual void operator()(const ConstPoint3d &)
std::string role
applyVisitor will set the current role here
RuleParameterMap::iterator iterator
static std::vector< std::string > availableRules()
returns regulatory element names that this factory can handle
virtual ~RegulatoryElement()
RuleParameterMap & parameters() noexcept
getter for all parameters of a regulatory element.
RuleParameter MutableType
ConstPrimitiveType< PrimitiveT > toConst(const PrimitiveT &primitive)
Converts a primitive to its matching const type.
constexpr bool strequal(char const *lhs, char const *rhs)
compares two c-strings at compile time. Do not use this for run time.
std::shared_ptr< const RegulatoryElement > RegulatoryElementConstPtr
Id getId< RegulatoryElementPtr >(const RegulatoryElementPtr &prim)
RegulatoryElementData(Id id, RuleParameterMap parameters=RuleParameterMap(), const AttributeMap &attributes=AttributeMap())
const RuleParameterMap & parameters() const
std::vector< T > getParameters(RoleName role) const
typename T::DataType DataType
static constexpr const char Outer[]
void registerStrategy(const std::string &strategy, const FactoryFcn &factoryFunction)
template class for registering new RegulatoryElements.
bool has(const ConstArea &ll, Id id)
returns true if element of a regulatory element has a matching Id
static constexpr RoleNamesItem Map[]
std::enable_if_t< traits::isRegulatoryElementT< T >(), RetT > IfRE
Basic Primitive class for all primitives of lanelet2.
static RegulatoryElementPtr create(std::string ruleName, const RegulatoryElementDataPtr &data)
create a regulatory element based on the name of the rule
@ RightOfWay
A lanelet that has right of way in a relation.
GenericRegulatoryElement(const RegulatoryElementDataPtr &data)
@ CancelLine
The line from which a rule is invalidated.
Id getId< RuleParameter >(const RuleParameter &prim)
Extracts the id of a rule parameter.
static constexpr const char Right[]
A normal 3d linestring with immutable data.
virtual void operator()(const ConstWeakLanelet &)
A mutable clockwise oriented, open (ie start point != end point) polygon in 3d.
static constexpr char RuleName[]
constexpr bool isRegulatoryElementT()
RuleParameterMap parameters
Id getId< ConstRuleParameter >(const ConstRuleParameter &prim)
You can inherit from this visitor to perform an operation on each parameter of a regulatory element.
ConstRuleParameter toConst< RuleParameter >(const RuleParameter &primitive)
RuleParameterMap::const_iterator const_iterator
static constexpr const char Yield[]
static constexpr const char RefLine[]
std::vector< ConstRuleParameter > ConstRuleParameters
Const version for a range of rule parameters.
RegisterRegulatoryElement()
used internally by RegulatoryElements to avoid cyclic dependencies.
Id id
Id of this primitive (unique across one map)
RegulatoryElementDataPtr data()
static RegulatoryElementPtr create(const std::string &ruleName, Id id, const RuleParameterMap &map, const AttributeMap &attributes=AttributeMap())
static RegulatoryElementFactory & instance()
Identifies RegulatoryElementPrimitives.
ConstRuleParameter ConstType
RuleParameter MutableType
typename Map::const_iterator const_iterator
@ Refers
The primitive(s) that are the origin of this rule (ie signs)
std::shared_ptr< DataType > data() const
A normal 3d linestring with mutable data.
boost::variant< Point3d, LineString3d, Polygon3d, WeakLanelet, WeakArea > RuleParameter
Id id() const noexcept
get the unique id of this primitive
const_iterator begin() const
static constexpr char RuleName[]
virtual void operator()(const Point3d &)=0
HybridMap< RuleParameters, decltype(RoleNameString::Map)&, RoleNameString::Map > RuleParameterMap
Rules are stored in a map internally.
std::function< RegulatoryElementPtr(const RegulatoryElementDataPtr &)> FactoryFcn
Identifies AreaPrimitives.
static constexpr const char RightOfWay[]
lanelet2_core
Author(s): Fabian Poggenhans
autogenerated on Thu Mar 6 2025 03:25:52