Refureku v2.2.0
C++17 runtime reflection library.
rfk::Field Class Referencefinal
Inheritance diagram for rfk::Field:
rfk::FieldBase rfk::VariableBase rfk::Entity

Public Member Functions

REFUREKU_INTERNAL Field (char const *name, std::size_t id, Type const &type, EFieldFlags flags, Struct const *owner, std::size_t memoryOffset, Entity const *outerEntity=nullptr) noexcept
 
REFUREKU_INTERNAL Field (Field &&) noexcept
 
template<typename ValueType , typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
RFK_NODISCARD ValueType get (InstanceType &instance) const
 Get the value corresponding to this field in the provided instance. This method in not safe if you provide a wrong ValueType. More...
 
template<typename ValueType >
RFK_NODISCARD ValueType getUnsafe (void *instance) const
 Get the value corresponding to this field in the provided instance. This method in not safe if you provide a wrong ValueType. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::get for safety if you know the static type of your instance in the calling context. More...
 
template<typename ValueType >
RFK_NODISCARD ValueType getUnsafe (void const *instance) const
 Get the value corresponding to this field in the provided instance. This method in not safe if you provide a wrong ValueType. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::get for safety if you know the static type of your instance in the calling context. More...
 
template<typename ValueType , typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
void set (InstanceType &instance, ValueType &&value) const
 Set the value corresponding to this field in the provided instance. This method is not safe if you provide a wrong ValueType. More...
 
template<typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
void set (InstanceType &instance, void const *valuePtr, std::size_t valueSize) const
 Copy valueSize bytes starting from valuePtr into this field's address in instance. More...
 
template<typename ValueType >
void setUnsafe (void *instance, ValueType &&value) const
 Set the value corresponding to this field in the provided instance. This method is not safe if you provide a wrong ValueType. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::set for safety if you know the static type of your instance in the calling context. More...
 
REFUREKU_API void setUnsafe (void *instance, void const *valuePtr, std::size_t valueSize) const
 Copy valueSize bytes starting from valuePtr into this field's address in instance. More...
 
template<typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
RFK_NODISCARD void * getPtr (InstanceType &instance) const
 Get a pointer to this field in the provided instance. More...
 
RFK_NODISCARD REFUREKU_API void * getPtrUnsafe (void *instance) const
 Get a pointer to this field in the provided instance. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::getPtr for safety if you know the static type of your instance in the calling context. More...
 
template<typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
RFK_NODISCARD void const * getConstPtr (InstanceType const &instance) const
 Get a const pointer to this field in the provided instance. More...
 
RFK_NODISCARD REFUREKU_API void const * getConstPtrUnsafe (void const *instance) const noexcept
 Get a const pointer to this field in the provided instance. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::getConstPtr for safety if you know the static type of your instance in the calling context. More...
 
RFK_NODISCARD REFUREKU_API std::size_t getMemoryOffset () const noexcept
 Get the memory offset of this field in an instance of its owner class (Field::getOwner()). More...
 
- Public Member Functions inherited from rfk::FieldBase
RFK_NODISCARD REFUREKU_API EAccessSpecifier getAccess () const noexcept
 Get the access specifier of this field in its owner struct/class. More...
 
RFK_NODISCARD REFUREKU_API bool isStatic () const noexcept
 Check whether this field is static or not. If the field is static, it can safely be cast to StaticField. More...
 
RFK_NODISCARD REFUREKU_API bool isMutable () const noexcept
 Check whether this field is mutable or not. More...
 
RFK_NODISCARD REFUREKU_API EFieldFlags getFlags () const noexcept
 Get the flags qualifying this field. More...
 
RFK_NODISCARD REFUREKU_API Struct const * getOwner () const noexcept
 Get the struct owning this field. More...
 
- Public Member Functions inherited from rfk::VariableBase
REFUREKU_API Type const & getType () const noexcept
 Get the type of this variable. More...
 
- Public Member Functions inherited from rfk::Entity
 Entity (Entity const &)=delete
 
RFK_NODISCARD REFUREKU_API Property const * getPropertyAt (std::size_t propertyIndex) const noexcept
 Retrieve the property at the given index. If propertyIndex is greater or equal to the properties count, the behaviour is undefined. More...
 
template<typename PropertyType , typename = std::enable_if_t<std::is_base_of_v<Property, PropertyType> && !std::is_same_v<PropertyType, Property>>>
RFK_NODISCARD PropertyType const * getProperty (bool isChildClassValid=true) const noexcept
 Retrieve a property of a given type from this entity. More...
 
RFK_NODISCARD REFUREKU_API Property const * getProperty (Struct const &archetype, bool isChildClassValid=true) const noexcept
 Retrieve the first property matching with the provided archetype. More...
 
RFK_NODISCARD REFUREKU_API Property const * getPropertyByName (char const *name) const noexcept
 Retrieve the first property named with the provided name. More...
 
RFK_NODISCARD REFUREKU_API Property const * getPropertyByPredicate (Predicate< Property > predicate, void *userData) const
 Retrieve a property matching with a predicate. More...
 
template<typename PropertyType , typename = std::enable_if_t<std::is_base_of_v<Property, PropertyType> && !std::is_same_v<PropertyType, Property>>>
RFK_NODISCARD Vector< PropertyType const * > getProperties (bool isChildClassValid=true) const noexcept
 Retrieve all properties matching with the provided archetype. If PropertyType uses multiple inheritance, its first inherited type must be rfk::Property or derived. More...
 
RFK_NODISCARD REFUREKU_API Vector< Property const * > getProperties (Struct const &archetype, bool isChildClassValid=true) const noexcept
 Retrieve all properties matching with the provided archetype. More...
 
RFK_NODISCARD REFUREKU_API Vector< Property const * > getPropertiesByName (char const *name) const noexcept
 Retrieve all properties named with the provided name. More...
 
RFK_NODISCARD REFUREKU_API Vector< Property const * > getPropertiesByPredicate (Predicate< Property > predicate, void *userData) const
 Retrieve all properties matching with a predicate in this entity. More...
 
RFK_NODISCARD REFUREKU_API std::size_t getPropertiesCount () const noexcept
 Get the number of properties attached to this entity. More...
 
REFUREKU_API bool foreachProperty (Visitor< Property > visitor, void *userData) const
 Execute the given visitor on all properties attached to this entity. More...
 
RFK_NODISCARD REFUREKU_API char const * getName () const noexcept
 Get the name of the entity. More...
 
RFK_NODISCARD REFUREKU_API bool hasSameName (char const *name) const noexcept
 Check that this entity has the same name as the provided string. More...
 
RFK_NODISCARD REFUREKU_API std::size_t getId () const noexcept
 Get the program-unique id of the entity. More...
 
RFK_NODISCARD REFUREKU_API EEntityKind getKind () const noexcept
 Get the kind of the entity. Knowing the kind allows to safely cast to child classes. Check the EEntityKind documentation for more information. More...
 
RFK_NODISCARD REFUREKU_API Entity const * getOuterEntity () const noexcept
 Get the outer entity of the entity. It basically corresponds to the entity this entity was declared in from a source-code point of view. A nullptr outer entity means the entity was declared at file level. More...
 
REFUREKU_API bool addProperty (Property const &property) noexcept
 Add a property to this entity. More...
 
REFUREKU_API void setOuterEntity (Entity const *outerEntity) noexcept
 Setter for the field _outerEntity. More...
 
REFUREKU_API void setPropertiesCapacity (std::size_t capacity) noexcept
 Set the number of properties for this entity. Useful to avoid reallocations when adding a lot of properties. If the number of properties is already >= to the provided capacity, this method has no effect. More...
 
Entityoperator= (Entity const &)=delete
 
Entityoperator= (Entity &&)=delete
 
RFK_NODISCARD REFUREKU_API bool operator== (Entity const &other) const noexcept
 
RFK_NODISCARD REFUREKU_API bool operator!= (Entity const &other) const noexcept
 

Additional Inherited Members

- Protected Member Functions inherited from rfk::FieldBase
REFUREKU_INTERNAL FieldBase (FieldBaseImpl *implementation) noexcept
 
REFUREKU_INTERNAL FieldBase (FieldBase &&) noexcept
 
- Protected Member Functions inherited from rfk::VariableBase
REFUREKU_INTERNAL VariableBase (VariableBaseImpl *implementation) noexcept
 
REFUREKU_INTERNAL VariableBase (VariableBase &&) noexcept
 
template<typename ValueType >
RFK_NODISCARD ValueType get (void *ptr) const
 Get the data stored in the provided ptr. This method in not safe if you provide a wrong DataType. More...
 
template<typename ValueType >
RFK_NODISCARD ValueType get (void const *ptr) const
 Get the data stored in the provided ptr. This method in not safe if you provide a wrong DataType. Overload of the same method for const pointers. More...
 
template<typename ValueType >
void set (void *ptr, ValueType &&value) const
 Set the provided pointer content. This method is not safe if you provide a wrong ValueType. More...
 
REFUREKU_INTERNAL void set (void *target, void const *source, std::size_t bytesCount) const
 Copy dataSize bytes starting from data into the variable. More...
 
- Protected Member Functions inherited from rfk::Entity
REFUREKU_INTERNAL Entity (Entity &&) noexcept
 
REFUREKU_INTERNAL Entity (EntityImpl *implementation) noexcept
 
- Static Protected Member Functions inherited from rfk::VariableBase
RFK_NORETURN static REFUREKU_API void throwConstViolationException (char const *message)
 Throw a ConstViolation exception with the specified message. /!\ This method is called from template methods so it must be exported. More...
 
- Static Protected Attributes inherited from rfk::VariableBase
template<typename T >
static constexpr bool is_value_v = !std::is_lvalue_reference_v<T> && !std::is_rvalue_reference_v<T>
 

Member Function Documentation

◆ get()

template<typename ValueType , typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
RFK_NODISCARD ValueType rfk::Field::get ( InstanceType &  instance) const

Get the value corresponding to this field in the provided instance. This method in not safe if you provide a wrong ValueType.

Template Parameters
ValueTypeType to retrieve from the field. If ValueType is an rvalue reference, the field value is moved into the return value (so the field value is no longer safe to use). If ValueType is an lvalue reference, return a reference to the field. If ValueType is a value type, the value is copied. If it is a class, ValueType must be copy-constructible.
Parameters
instanceInstance we retrieve the value from.
Exceptions
ConstViolationif:
  • the field is const and ValueType is an RValue type (can't move a const field content);
  • the field is const and ValueType is a non-const reference;
InvalidArchetypeif the field can't be accessed from the provided instance.
Returns
The queried value in the instance.

◆ getConstPtr()

template<typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
RFK_NODISCARD void const * rfk::Field::getConstPtr ( InstanceType const &  instance) const

Get a const pointer to this field in the provided instance.

Parameters
instanceInstance we get the field from.
Returns
Const pointer to this field in the provided instance.
Exceptions
InvalidArchetypeif the field can't be accessed from the provided instance.

◆ getConstPtrUnsafe()

RFK_NODISCARD REFUREKU_API void const * rfk::Field::getConstPtrUnsafe ( void const *  instance) const
noexcept

Get a const pointer to this field in the provided instance. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::getConstPtr for safety if you know the static type of your instance in the calling context.

Parameters
instanceInstance we get the field from.
Returns
Const pointer to this field in the provided instance.

◆ getMemoryOffset()

RFK_NODISCARD REFUREKU_API std::size_t rfk::Field::getMemoryOffset ( ) const
noexcept

Get the memory offset of this field in an instance of its owner class (Field::getOwner()).

Returns
The memory offset in bytes.

◆ getPtr()

template<typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
RFK_NODISCARD void * rfk::Field::getPtr ( InstanceType &  instance) const

Get a pointer to this field in the provided instance.

Parameters
instanceInstance we get the field from.
Returns
Pointer to this field in the provided instance.
Exceptions
ConstViolationif the field is actually const.
InvalidArchetypeif the field can't be accessed from the provided instance.

◆ getPtrUnsafe()

RFK_NODISCARD REFUREKU_API void * rfk::Field::getPtrUnsafe ( void *  instance) const

Get a pointer to this field in the provided instance. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::getPtr for safety if you know the static type of your instance in the calling context.

Parameters
instanceInstance we get the field from.
Returns
Pointer to this field in the provided instance.
Exceptions
ConstViolationif the field is actually const.
InvalidArchetypeif the field can't be accessed from the provided instance.

◆ getUnsafe() [1/2]

template<typename ValueType >
RFK_NODISCARD ValueType rfk::Field::getUnsafe ( void *  instance) const

Get the value corresponding to this field in the provided instance. This method in not safe if you provide a wrong ValueType. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::get for safety if you know the static type of your instance in the calling context.

Note
Since this method doesn't perform any pointer adjustment, it is slightly faster than Field::get.
Template Parameters
ValueTypeType to retrieve from the field. If ValueType is an rvalue reference, the field value is moved into the return value (so the field value is no longer safe to use). If ValueType is an lvalue reference, return a reference to the field. If ValueType is a value type, the value is copied. If it is a class, ValueType must be copy-constructible.
Parameters
instanceInstance we retrieve the value from.
Exceptions
ConstViolationif:
  • the field is const and ValueType is an RValue type (can't move a const field content);
  • the field is const and ValueType is a non-const reference;
Returns
The queried value in the instance.

◆ getUnsafe() [2/2]

template<typename ValueType >
RFK_NODISCARD ValueType rfk::Field::getUnsafe ( void const *  instance) const

Get the value corresponding to this field in the provided instance. This method in not safe if you provide a wrong ValueType. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::get for safety if you know the static type of your instance in the calling context.

Note
This is only an overload of the same method with a const instance. Since this method doesn't perform any pointer adjustment, it is slightly faster than Field::get.
Template Parameters
ValueTypeType to retrieve from the field. If ValueType is an rvalue reference, the field value is moved into the return value (so the field value is no longer safe to use). If ValueType is an lvalue reference, return a reference to the field. If ValueType is a value type, the value is copied. If it is a class, ValueType must be copy-constructible.
Parameters
instanceInstance we retrieve the value from.
Exceptions
ConstViolationif:
  • the field is const and ValueType is an RValue type (can't move a const field content);
  • the field is const and ValueType is a non-const reference;
Returns
The queried value in the instance.

◆ set() [1/2]

template<typename ValueType , typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
void rfk::Field::set ( InstanceType &  instance,
ValueType &&  value 
) const

Set the value corresponding to this field in the provided instance. This method is not safe if you provide a wrong ValueType.

Template Parameters
ValueTypeType to write into the field. If ValueType is an rvalue reference, the value is forwarded into the instance. If ValueType is an lvalue reference, the value is copied into the instance.
Parameters
instanceInstance we set the value in.
valueData to set in the instance.
Exceptions
ConstViolationif the field is actually const and therefore readonly.
InvalidArchetypeif the field can't be accessed from the provided instance.

◆ set() [2/2]

template<typename InstanceType , typename = std::enable_if_t<is_value_v<InstanceType> && internal::IsAdjustableInstanceValue<InstanceType>>>
void rfk::Field::set ( InstanceType &  instance,
void const *  valuePtr,
std::size_t  valueSize 
) const

Copy valueSize bytes starting from valuePtr into this field's address in instance.

Parameters
instanceInstance we write the bytes in.
valuePtrPointer to the value to copy.
valueSizeNumber of bytes to copy into the field.
Exceptions
ConstViolationif the field is actually const and therefore readonly.
InvalidArchetypeif the field can't be accessed from the provided instance.

◆ setUnsafe() [1/2]

template<typename ValueType >
void rfk::Field::setUnsafe ( void *  instance,
ValueType &&  value 
) const

Set the value corresponding to this field in the provided instance. This method is not safe if you provide a wrong ValueType. This method DOES NOT perform any pointer adjustment on the provided instance so it is unsafe if instance is not a valid pointer to an object of the field's owner archetype. Prefer using Field::set for safety if you know the static type of your instance in the calling context.

Template Parameters
ValueTypeType to write into the field. If ValueType is an rvalue reference, the value is forwarded into the instance. If ValueType is an lvalue reference, the value is copied into the instance.
Parameters
instanceInstance we set the value in.
valueData to set in the instance.
Exceptions
ConstViolationif the field is actually const and therefore readonly.

◆ setUnsafe() [2/2]

REFUREKU_API void rfk::Field::setUnsafe ( void *  instance,
void const *  valuePtr,
std::size_t  valueSize 
) const

Copy valueSize bytes starting from valuePtr into this field's address in instance.

Parameters
instanceInstance we write the bytes in.
valuePtrPointer to the value to copy.
valueSizeNumber of bytes to copy into the field.
Exceptions
ConstViolationif the field is actually const and therefore readonly.

The documentation for this class was generated from the following file: