-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data): Allow wrapped fields to be read as normal object with a s…
…ingle field
- Loading branch information
Showing
6 changed files
with
100 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/// @file | ||
/// @brief Class @ref cubos::core::reflection::WrapperTrait. | ||
/// @ingroup core-reflection | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <string> | ||
|
||
#include <cubos/core/reflection/reflect.hpp> | ||
#include <cubos/core/reflection/traits/fields.hpp> | ||
#include <cubos/core/reflection/type.hpp> | ||
|
||
namespace cubos::core::reflection | ||
{ | ||
/// @brief Describes the single field of a reflected type. | ||
/// @ingroup core-reflection | ||
class CUBOS_CORE_API WrapperTrait | ||
{ | ||
public: | ||
CUBOS_REFLECT; | ||
|
||
~WrapperTrait() | ||
{ | ||
delete mAddressOf; | ||
}; | ||
|
||
/// @brief Constructs. | ||
template <typename F, typename O> | ||
WrapperTrait(F O::* pointer) | ||
: mType(reflect<F>()) | ||
, mAddressOf(new FieldsTrait::AddressOfImpl<O, F>(pointer)) | ||
{ | ||
} | ||
|
||
/// @brief Gets the type of the single field. | ||
/// @return Type. | ||
const Type& type() const | ||
{ | ||
return mType; | ||
} | ||
|
||
/// @brief Gets a pointer to the field on a given instance of the reflected type. | ||
/// @param instance Pointer to the instance. | ||
/// @return Pointer to the field on the given instance. | ||
void* value(const void* instance) const | ||
{ | ||
return reinterpret_cast<void*>(this->mAddressOf->get(instance)); | ||
} | ||
|
||
private: | ||
const Type& mType; | ||
const FieldsTrait::AddressOf* mAddressOf; | ||
}; | ||
} // namespace cubos::core::reflection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <cubos/core/reflection/external/string.hpp> | ||
#include <cubos/core/reflection/traits/wrapper.hpp> | ||
#include <cubos/core/reflection/type.hpp> | ||
#include <cubos/core/tel/logging.hpp> | ||
|
||
using namespace cubos::core::reflection; | ||
|
||
CUBOS_REFLECT_IMPL(WrapperTrait) | ||
{ | ||
return Type::create("cubos::core::ecs::WrapperTrait"); | ||
} |