Class Attribute

Class Documentation

class Attribute

An attribute represents one value of a tag of a lanelet primitive.

They are internally represented as strings but can be interpreted as numbers.

The result of the last as… is cached, therefore repeated calls to the same as.. function are very cheap.

Public Types

using Cache = boost::variant<bool, double, Id, int, Velocity>

Public Functions

Attribute() = default
inline Attribute(const std::string &value)
inline Attribute(std::string &&value)
inline Attribute(const char *value)
Attribute(bool value)
Attribute(Id value)
Attribute(int value)
Attribute(double value)
Attribute(const Velocity &value)
Optional<bool> asBool() const

interpret this attribute as bool value

Throws:

ConversionError – if the attribute could not be interpreted as bool

Returns:

bool value

Optional<double> asDouble() const

interpret this attribute as double value

Returns:

double if possible to convert the value

Optional<Id> asId() const

interpret this attribute as an id

Returns:

id if possible to convert the value

Optional<int> asInt() const

interpret this attribute as an int

Returns:

int if possible to convert the value

Optional<Velocity> asVelocity() const

interpret this attribute as Velocity

The function can understand and correctly parse units in the attribute. “2.

km/h”, “2.mps”, etc. To obtain the velocity as a double, divide it by the desired unit:

double v = attr.asVelocity() / KMH;

Returns:

Velocity if possible to convert the value

template<typename T>
Optional<ValueOfT<T>> as() const

templated version. Works ony for the as.. above

inline const std::string &value() const

gets the value of this attribute

Returns:

value

void setValue(const std::string &value)

set the value of this attribute

Parameters:

value – new value

template<>
inline Optional<double> as() const
template<>
inline Optional<double> as() const
template<>
inline Optional<int> as() const
template<>
inline Optional<int> as() const
template<>
inline Optional<bool> as() const
template<>
inline Optional<bool> as() const
template<>
inline Optional<Id> as() const
template<>
inline Optional<Id> as() const
template<>
inline Optional<Velocity> as() const
template<>
inline Optional<Velocity> as() const
template<>
inline Optional<const char*> as() const
template<>
inline Optional<const char*> as() const