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
-
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
-
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
-
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
-
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
>
boolset
(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!
- Return
true if setting the
value
was successful, false otherwise.- Parameters
value
: the value to set for this Property
-
bool
isLinked
() const¶ Checks if an input property is linked to an output property of another node. Setting values of linked inputs will result in errors, use this to check an input is not linked before setting it. Calling this method for properties which are not inputs will report an error and return false.
- Return
true if the property is an input and is linked, false otherwise.
-
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
-
EPropertyType