11 class HasIdVisitor :
public RuleParameterVisitor {
13 explicit HasIdVisitor(
Id id) :
id_{
id} {}
14 void operator()(
const ConstPoint3d&
p)
override {
found_ |= p.id() ==
id_; }
17 void operator()(
const ConstWeakLanelet& ll)
override {
21 ConstLanelet llet(ll.lock());
24 void operator()(
const ConstWeakArea& ar)
override {
28 ConstArea area(ar.lock());
31 bool operator!()
const {
return !
found_; }
38 class GetIdVisitor :
public RuleParameterVisitor {
42 boost::apply_visitor(visitor, param);
45 template <
typename PrimT>
46 void appendID(
const PrimT& p) {
50 void operator()(
const ConstPoint3d& p)
override { appendID(p); }
51 void operator()(
const ConstLineString3d& l)
override { appendID(l); }
52 void operator()(
const ConstPolygon3d& p)
override { appendID(p); }
53 void operator()(
const ConstWeakLanelet& ll)
override {
58 void operator()(
const ConstWeakArea& ar)
override {
68 class ToConstVisitor :
public RuleParameterVisitor {
70 void operator()(
const ConstPoint3d& p)
override {
param_ =
p; }
71 void operator()(
const ConstLineString3d& l)
override {
param_ = l; }
72 void operator()(
const ConstPolygon3d& p)
override {
param_ =
p; }
73 void operator()(
const ConstWeakLanelet& ll)
override {
param_ = ll; }
74 void operator()(
const ConstWeakArea& ar)
override {
param_ = ar; }
77 boost::apply_visitor(*
this, rule);
88 #if __cplusplus < 201703L 115 if (ruleName.empty()) {
120 auto it = inst.registry_.find(ruleName);
121 if (it != inst.registry_.end()) {
122 return it->second(data);
124 throw InvalidInputError(
"No regulatory element found that implements rule " + ruleName);
129 return utils::transform(registry, [](
const auto& elem) {
return elem.first; });
139 for (
const auto& param : parameters()) {
140 params.
insert(std::make_pair(
141 param.first,
utils::transform(param.second, [](
const auto& elem) { return traits::toConst(elem); })));
147 for (
const auto& elems : parameters()) {
148 visitor.
role = elems.first;
149 for (
const auto& elem : elems.second) {
150 boost::apply_visitor(visitor, elem);
156 for (
const auto& elems : parameters()) {
157 visitor.
role = elems.first;
158 for (
const auto& elem : elems.second) {
159 boost::apply_visitor(visitor, elem);
165 HasIdVisitor hasId(
id);
172 return ToConstVisitor().apply(primitive);
176 stream <<
"[id: " << obj.
id();
178 stream <<
", parameters: ";
180 stream <<
'{' << param.first <<
':' <<
' ';
181 for (
auto& rule : param.second) {
187 return stream <<
']';
Id id() const noexcept
get the unique id of this primitive
template class for registering new RegulatoryElements.
static constexpr const char Outer[]
static constexpr char RuleName[]
std::string role
applyVisitor will set the current role here
std::shared_ptr< RegulatoryElement > RegulatoryElementPtr
A hybrid map is just like a normal map with keys as string, but elements can also be accessed using a...
Id getId< RuleParameter >(const RuleParameter &prim)
Extracts the id of a rule parameter.
virtual ~RegulatoryElement()
static constexpr const char CancelLine[]
static constexpr const char RefLine[]
std::pair< iterator, bool > insert(const value_type &v)
auto transform(Iterator begin, Iterator end, const Func f)
std::ostream & operator<<(std::ostream &stream, const Attribute &obj)
static RegulatoryElementFactory & instance()
static constexpr const char Left[]
static constexpr const char Yield[]
std::shared_ptr< RegulatoryElementData > RegulatoryElementDataPtr
static constexpr const char Right[]
std::map< std::string, FactoryFcn > registry_
static constexpr char RuleName[]
bool has(const ConstArea &ll, Id id)
returns true if element of a regulatory element has a matching Id
Creates regulatory elements based on their type.
static RegulatoryElementPtr create(std::string ruleName, const RegulatoryElementDataPtr &data)
create a regulatory element based on the name of the rule
std::string role
applyVisitor will set the current role here
boost::variant< ConstPoint3d, ConstLineString3d, ConstPolygon3d, ConstWeakLanelet, ConstWeakArea > ConstRuleParameter
Const-version of the parameters.
bool empty() const
returns true if this object contains no parameters
static constexpr const char RegulatoryElement[]
static constexpr const char Inner[]
static constexpr const char Lanelet[]
static constexpr const char RightOfWay[]
ConstRuleParameter param_
ConstRuleParameter toConst< RuleParameter >(const RuleParameter &primitive)
You can inherit from this visitor to perform an operation on each parameter of a regulatory element...
Id getId< ConstRuleParameter >(const ConstRuleParameter &prim)
A general rule or limitation for a lanelet (abstract base class)
static constexpr const char Subtype[]
static RegisterRegulatoryElement< GenericRegulatoryElement > genRegelem
void applyVisitor(RuleParameterVisitor &visitor) const
applies a visitor to every parameter in the regulatory element
static constexpr const char Refers[]
ConstRuleParameterMap getParameters() const
Returns all parameters as const object (coversion overhead for const)
static std::vector< std::string > availableRules()
returns regulatory element names that this factory can handle
static constexpr RoleNamesItem Map[]
std::pair< const char *, const RoleName > RoleNamesItem
static constexpr const char Centerline[]
boost::variant< Point3d, LineString3d, Polygon3d, WeakLanelet, WeakArea > RuleParameter
static constexpr const char Cancels[]