Properties#

#include "navground/core/property.h"
template<typename T, class C>
using navground::core::TypedGetter = std::function<T(const C*)>#

A function that gets a value of type T from an object of type C.

template<typename T, class C>
using navground::core::TypedSetter = std::function<void(C*, const T&)>#

A function that sets a value of type T of an object of type C.

struct Property#

This class defines a property (similar to Python built-in properties), i.e., a pair of getter and setter. In addition, it holds (for auto-documentation) a default value, a description, and the name of the involved types. A property has a value of type Field, which is one of bool, int, float, string, navground::core::Vector2 or a collection (a vector in C++, a list in Python) thereof. Properties are used to configure sub-classes of navground::core::HasProperties when using bindings like YAML or Python. Properties values are accessed using the methods exposed by navground::core::HasProperties.

Public Types

using Scalar = std::variant<bool, int, ng_float_t, std::string, Vector2>#

The type of the scalar values held by the property.

using Field = std::variant<bool, int, ng_float_t, std::string, Vector2, std::vector<bool>, std::vector<int>, std::vector<ng_float_t>, std::vector<std::string>, std::vector<Vector2>>#

The type of the value held by the property.

using Getter = std::function<Field(const HasProperties*)>#

The type of the property value getter, i.e., a function that gets the property value from the owner.

using Setter = std::function<void(HasProperties*, const Field&)>#

The type of the property value setter, i.e., a function that sets the property value of the owner.

using Schema = std::function<void(YAML::Node&)>#

A custom YAML schema modifier

Public Members

Getter getter#

The property value getter.

Setter setter#

The property value setter.

Field default_value#

The property default value, i.e., the value of the property when the object is initialized.

std::string type_name#

The name of the property value type, used for auto documentation.

std::string description#

A textual description of the property, used for auto documentation.

std::string owner_type_name#

The name of the property-owner type.

std::vector<std::string> deprecated_names#

Alternative deprecated names for the property

bool readonly#

Whether the property is readonly

Schema schema#

A custom YAML schema for the property to add validity constrains

Public Static Functions

template<typename T, class C>
static inline Property make(const TypedGetter<T, C> &getter, const TypedSetter<T, C> &setter, const T &default_value, const std::string &description = "", const Schema &schema = nullptr, const std::vector<std::string> &deprecated_names = {})#

Makes a property from a pair of typed setters and getters. It erases the type of the property (T) and of the property owner (C) from the interface, replacing typed by generic getters and setters. The property type is effectively preserved inside the getter and setter.

Parameters:
  • getter[in] A typed getter

  • setter[in] A typed setter

  • default_value[in] The property default value

  • description[in] The property description

  • deprecated_names[in] A list of deprecated alias names for this property.

  • schema[in] An optional schema

Template Parameters:
  • T – The type of the property

  • C – The type of the property owner

Returns:

A property

template<typename T, class C>
static inline Property make(const TypedGetter<T, C> &getter, const std::string &description = "", const Schema &schema = nullptr, const std::vector<std::string> &deprecated_names = {})#

Makes a readonly property with a getter. It erases the type of the property (T) and of the property owner (C) from the interface, replacing typed by generic getter. The property type is effectively preserved inside the getter. The property default is set to T{}.

Parameters:
  • getter[in] A typed getter

  • description[in] The property description

  • deprecated_names[in] A list of deprecated alias names for this property.

  • schema[in] An optional schema

Template Parameters:
  • T – The type of the property

  • C – The type of the property owner

Returns:

A property

template<typename T, class C>
static inline core::Property make(T (C::* getter)() const, const std::string &description = "", const std::vector<std::string> &deprecated_names = {}, const Schema &schema = nullptr)#

Makes a readonly property from a class getter. It erases the type of the property (T) and of the property owner (C) from the interface, replacing typed by generic getter. The property type is effectively preserved inside the getter. The property default is set to T{}.

Parameters:
  • getter[in] The getter

  • description[in] The property description

  • deprecated_names[in] A list of deprecated alias names for this property.

  • schema[in] An optional schema

Template Parameters:
  • T – The type of the property

  • C – The type of the property owner

Returns:

A property

template<typename T, class C, typename U>
static inline Property make(U (C::* getter)() const, void (C::* setter)(const U&), const T &default_value, const std::string &description = "", const Schema &schema = nullptr, const std::vector<std::string> &deprecated_names = {})#

Makes a property from a pair of class setters and getters. It erases the type of the property (T) and of the property owner (C) from the interface, replacing typed by generic getters and setters. The property type is effectively preserved inside the getter and setter.

Parameters:
  • getter[in] A getter

  • setter[in] A setter

  • default_value[in] The property default value

  • description[in] The property description

  • deprecated_names[in] A list of deprecated alias names for this property.

  • schema[in] An optional schema

Template Parameters:
  • T – The type of the property

  • C – The type of the property owner

  • U – The type manipulated by the getter and setter.

Returns:

A property

template<typename T, class C, typename U>
static inline Property make(U (C::* getter)() const, void (C::* setter)(U), const T &default_value, const std::string &description = "", const Schema &schema = nullptr, const std::vector<std::string> &deprecated_names = {})#

Makes a property from a pair of class setters and getters. It erases the type of the property (T) and of the property owner (C) from the interface, replacing typed by generic getters and setters. The property type is effectively preserved inside the getter and setter.

Parameters:
  • getter[in] A getter

  • setter[in] A setter

  • default_value[in] The property default value

  • description[in] The property description

  • deprecated_names[in] A list of deprecated alias names for this property.

  • schema[in] An optional schema

Template Parameters:
  • T – The type of the property

  • C – The type of the property owner

  • U – The type manipulated by the getter and setter.

Returns:

A property

template<typename T, class C, typename U>
static inline Property make_readwrite(U C::* param, const T &default_value, const std::string &description = "", const Schema &schema = nullptr, const std::vector<std::string> &deprecated_names = {})#

Makes a property that gets and sets a class member. It erases the type of the property (T) and of the property owner (C) from the interface, replacing typed by generic getters and setters. The property type is effectively preserved inside the getter and setter.

Parameters:
  • param[in] A class member

  • default_value[in] The property default value

  • description[in] The property description

  • deprecated_names[in] A list of deprecated alias names for this property.

  • schema[in] An optional schema

Template Parameters:
  • T – The type of the property

  • C – The type of the property owner

  • U – The type of param

Returns:

A property

template<typename T, class C, typename U>
static inline Property make_readonly(U C::* param, const std::string &description = "", const Schema &schema = nullptr, const std::vector<std::string> &deprecated_names = {})#

Makes a readonly property that gets a class member. It erases the type of the property (T) and of the property owner (C) from the interface, replacing typed by generic getter. The property type is effectively preserved inside the getter. The property default is set to T{}.

Parameters:
  • param[in] A class member

  • description[in] The property description

  • deprecated_names[in] A list of deprecated alias names for this property.

  • schema[in] An optional schema

Template Parameters:
  • T – The type of the property

  • C – The type of the property owner

  • U – The type of param

Returns:

A property

template<class C, typename U>
static inline Property make_readonly(U C::* param, const std::string &description = "", const Schema &schema = nullptr, const std::vector<std::string> &deprecated_names = {})#

Makes a readonly property that gets a class member. It erases the type of the property (T) and of the property owner (C) from the interface, replacing typed by generic getter. The property type is effectively preserved inside the getter. The property default is set to T{}.

Parameters:
  • param[in] A class member

  • description[in] The property description

  • deprecated_names[in] A list of deprecated alias names for this property.

  • schema[in] An optional schema

Template Parameters:
  • C – The type of the property owner

  • U – The type of param and property

Returns:

A property

using navground::core::Properties = std::map<std::string, Property>#

A type the holds a dictionary of named properties name -> property

struct HasProperties#

This class defines set and get methods to access named properties.

Subclassed by navground::core::HasRegister< Behavior >, navground::core::HasRegister< BehaviorModulation >, navground::core::HasRegister< Kinematics >, navground::core::HasRegister< Scenario >, navground::core::HasRegister< StateEstimation >, navground::core::HasRegister< Task >, navground::core::HasRegister< T >

Public Functions

virtual const Properties &get_properties() const = 0#

Gets all properties associated with an owner.

All the properties associated with a owner type.

Returns:

The properties.

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

Set the value of a named property. Fails silently if no property can be found or if the value has a non-compatible type.

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

  • value[in] The desired value for the property

template<typename V>
inline void set_value(const std::string &name, const V &value)#

Set the value of a named property, similar to set but casting the value to V.

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

  • value[in] The desired value for the property

Template Parameters:

V – The type of the desired value

inline Property::Field get(const std::string &name) const#

Gets the value of the specified property.

Parameters:

name[in] The name of the property

Throws:

std::runtime_error – A runtime error if no property is found.

Returns:

The value of the property