Attributes#

Attributes are similar to properties but are dynamic, i.e., they are not specified by the class and can change type. Like properties, values are restricted to the types in navground::core::Attribute. Classes with attributes save/load their attributes from YAML.

#include "navground/core/attribute.h"
using navground::core::Attribute = Property::Field#
using navground::core::Attributes = std::map<std::string, Attribute>#

A type the holds a dictionary of named attributes name -> value

struct HasAttributes#

This class defines set and get methods to access dynamic attributes.

Subclassed by navground::sim::Agent, navground::sim::World

Public Functions

inline const Attributes &get_attributes() const#

Gets all attributes.

Returns:

The attributes.

inline void set_attributes(const Attributes &values)#

Sets all attributes.

Parameters:

values[in] The attributes.

inline void set(const std::string &name, const Property::Field &value)#

Set the value of a named attribute.

Parameters:
  • name[in] The name of the property

  • value[in] The desired value for the attribute

inline std::optional<Attribute> get(const std::string &name) const#

Gets the value of the specified attribute.

Parameters:

name[in] The name of the attribute

Returns:

The value of the attribute

inline std::optional<Attribute> has(const std::string &name) const#

Checks if the specified attribute is set.

Parameters:

name[in] The name of the attribute

Returns:

True if the attribute is present.

inline void remove(const std::string &name)#

Remove the specified attribute.

Parameters:

name[in] The name of the attribute

inline void clear()#

Remove all attributes.

template<typename T>
inline std::optional<T> get_typed(const std::string &name) const#

Gets the value of the specified attribute.

Parameters:

name[in] The name

Template Parameters:

T – The desired type

Returns:

The value static casted to T if possible, else null.