-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reflection): impl nullable trait
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// @file | ||
/// @brief Class @ref cubos::core::reflection::NullableTrait. | ||
/// @ingroup core-reflection | ||
|
||
#pragma once | ||
|
||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
namespace cubos::core::reflection | ||
{ | ||
/// @brief Used to manipulate values of null-representable types. | ||
/// @see See @ref examples-core-reflection-traits-nullable for an example of using this trait. | ||
/// @ingroup core-reflection | ||
class NullableTrait | ||
{ | ||
public: | ||
/// @brief Function pointer to check if a value represents null. | ||
using IsNull = bool (*)(const void* instance); | ||
|
||
/// @brief Function pointer to set a value to its null representation. | ||
using SetToNull = void (*)(void* instance); | ||
|
||
/// @brief Constructs. | ||
/// @param into IsNull. | ||
/// @param from SetToNull. | ||
NullableTrait(IsNull isNull, SetToNull setToNull); | ||
|
||
/// @brief Checks if the given value represents null. | ||
/// @param instance Instance. | ||
/// @return Whether the value represents null. | ||
bool isNull(const void* instance) const; | ||
|
||
/// @brief Sets a value to its null representation. | ||
/// @param instance Instance. | ||
void setToNull(void* instance) const; | ||
|
||
private: | ||
IsNull mIsNull; | ||
SetToNull mSetToNull; | ||
}; | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <cubos/core/reflection/traits/nullable.hpp> | ||
|
||
using cubos::core::reflection::NullableTrait; | ||
|
||
NullableTrait::NullableTrait(IsNull isNull, SetToNull setToNull) | ||
: mIsNull(isNull) | ||
, mSetToNull(setToNull) | ||
{ | ||
} | ||
|
||
bool NullableTrait::isNull(const void* instance) const | ||
{ | ||
return mIsNull(instance); | ||
} | ||
|
||
void NullableTrait::setToNull(void* instance) const | ||
{ | ||
mSetToNull(instance); | ||
} |