Property

class rlogic::Property

Represents a generic property slot of the rlogic::LogicNode and its derived classes. Properties can have primitive types (string, integer, etc.) or complex types (structs, arrays). Complex types can have “children”, i.e. nested properties: named fields (structs), or indexed fields (arrays).

Public Functions

EPropertyType getType() const

Returns the type of this Property

Return

the type of this Property

std::string_view getName() const

Returns the name of this Property. Note that not all properties have a name - for example an array element does not have a name. In that case the result will be an empty string view. Struct fields always have a non-empty name.

Return

the name of this Property

size_t getChildCount() const

Returns the amount of available child (nested) properties. If the Property is of type rlogic::EPropertyType::Struct, the returned number will correspond to the number of named properties of the struct. If the Property is of type rlogic::EPropertyType::Array, the method will return the array size. For all other property types getChildCount returns zero.

Return

the number of nested properties.

bool hasChild(std::string_view name) const

Return whether the rlogic::Property has a child with the given name

Return

whether the child with the given name exists

Parameters
  • name: the name of the child that should be checked for existence

const Property *getChild(size_t index) const

Returns the child property with the given index. index must be < getChildCount().

This method can be used to get nested properties of structs and arrays. For primitive types this will always return nullptr.

Note that array indexing in getChild follows C++ conventions and not Lua conventions! Inside the Lua scripts, you can and must use Lua conventions when indexing arrays (start at 1, end at N) while in C++ you must use [0, N-1].

Struct properties can also be retrieved by index. The ordering is not guaranteed to match the order of declaration inside Lua scripts (Lua explicitly warns to not rely on ordering of named table entries!). However, once a script is created, the index will not change, i.e. it is permitted that user code caches the property index for faster future access.

Return

the child with the given index, or nullptr if the property is primitive or the index is out of range

Parameters
  • [in] index: zero based index of child property to retrieve

Property *getChild(size_t index)

Returns the child property with the given index. index must be < getChildCount().

This method can be used to get nested properties of structs and arrays. For primitive types this will always return nullptr.

Note that array indexing in getChild follows C++ conventions and not Lua conventions! Inside the Lua scripts, you can and must use Lua conventions when indexing arrays (start at 1, end at N) while in C++ you must use [0, N-1].

Struct properties can also be retrieved by index. The ordering is not guaranteed to match the order of declaration inside Lua scripts (Lua explicitly warns to not rely on ordering of named table entries!). However, once a script is created, the index will not change, i.e. it is permitted that user code caches the property index for faster future access.

Return

the child with the given index, or nullptr if the property is primitive or the index is out of range

Parameters
  • [in] index: zero based index of child property to retrieve

Property *getChild(std::string_view name)

Searches for a child with the given name. Only properties of type rlogic::EPropertyType::Struct can return a child by name. In case of a primitive property or array this method will return nullptr.

Note that this method may be slower than getChild(size_t index) as it must do a string-based search.

Return

the child with the given name, or nullptr if property is not of type rlogic::EPropertyType::Struct

Parameters
  • [in] name: name of child property to retrieve

const Property *getChild(std::string_view name) const

Searches for a child with the given name. Only properties of type rlogic::EPropertyType::Struct can return a child by name. In case of a primitive property or array this method will return nullptr.

Note that this method may be slower than getChild(size_t index) as it must do a string-based search.

Return

the child with the given name, or nullptr if property is not of type rlogic::EPropertyType::Struct

Parameters
  • [in] name: name of child property to retrieve

template<typename T>
std::optional<T> get() const

Returns the value of this property. The supported template types are defined by rlogic::IsPrimitiveProperty where IsPrimitiveProperty<T>::value == true for a type T.

Attention! We recommend always specifying the template argument T explicitly, and don’t rely on the compiler’s type deduction! If T is not one of the supported types, a static_assert will be triggered!

Returns nullopt if the template type T does not match the internal type of the property.

Return

the value of this Property as std::optional or std::nullopt if T does not match.

template<typename T>
bool set(T value)

Sets the value of this Property. Same rules apply to template parameter T as in get()

Attention! We recommend always specifying the template argument T explicitly, and don’t rely on the compiler’s type deduction! If T is not one of the supported types, a static_assert will be triggered!

set() will report an error if the Property is linked. Use hasIncomingLink() to check in advance.

Return

true if setting the value was successful, false otherwise.

Parameters
  • value: the value to set for this Property

bool isLinked() const

Checks if this property is linked to a property of another node.

Property can be either on inputs side or outputs side of a node (or both in case of rlogic::LuaInterface), which defines what type of link is applicable - an incoming or outgoing. This query checks for any links, regardless of data flow direction. See hasIncomingLink() hasOutgoingLink() for dedicated checks

Return

true if the property is linked, false otherwise.

bool hasIncomingLink() const

Checks if there is any incoming link to this property, i.e. data is flowing to it from another node’s property. There can be only one incoming link per input property.

Return

true if the property is an input and is linked, false otherwise.

bool hasOutgoingLink() const

Checks if there is any outgoing link from this property, i.e. data is flowing from it to another node’s property. There can be multiple outgoing links per output property.

Return

true if the property is an output and is linked, false otherwise.

std::optional<PropertyLink> getIncomingLink() const

Returns information about the incoming link to this property, namely which property is the source of the link. Only certain properties can have an incoming link, see rlogic::LogicEngine::link for details.

Return

incoming link data or std::nullopt if there is no link.

size_t getOutgoingLinksCount() const

Returns the number of outgoing links from this property. Only certain properties can have outgoing links, see rlogic::LogicEngine::link for details.

Return

number of outgoing links from this property.

std::optional<PropertyLink> getOutgoingLink(size_t index) const

Returns information about the outgoing link from this property, namely which property is the target of the link with given index. Use getOutgoingLinksCount to query how many outgoing links there are. Only certain properties can have outgoing links, see rlogic::LogicEngine::link for details.

Return

outgoing link data or std::nullopt if there is no link with given index.

Parameters
  • [in] index: zero based index of outgoing link to retrieve

const LogicNode &getOwningLogicNode() const

Get rlogic::LogicNode that owns this property. Every property is owned by a rlogic::LogicNode and represents either its input or output.

Return

rlogic::LogicNode that owns this property.

LogicNode &getOwningLogicNode()

Get rlogic::LogicNode that owns this property. Every property is owned by a rlogic::LogicNode and represents either its input or output.

Return

rlogic::LogicNode that owns this property.

Property(std::unique_ptr<internal::PropertyImpl> impl) noexcept

Constructor of Property. User is not supposed to call this - properties are created by other factory classes

Parameters
  • impl: implementation details of the property

~Property() noexcept

Destructor of Property. User is not supposed to call this - properties are destroyed by other factory classes

Property(const Property &other) = delete

Copy Constructor of Property is deleted because properties are not supposed to be copied

Parameters
  • other: property to copy from

Property(Property &&other) = delete

Move Constructor of Property is deleted because properties are not supposed to be moved

Parameters
  • other: property to move from

Property &operator=(const Property &other) = delete

Assignment operator of Property is deleted because properties are not supposed to be copied

Parameters
  • other: property to assign from

Property &operator=(Property &&other) = delete

Move assignment operator of Property is deleted because properties are not supposed to be moved

Parameters
  • other: property to move from

Public Members

std::unique_ptr<internal::PropertyImpl> m_impl

Implementation details of the Property class