XLE
v0.02.0
|
Get and set properties associated with a native C++ class More...
#include <ClassAccessors.h>
Classes | |
class | ChildList |
class | Property |
Public Member Functions | |
size_t | GetPropertyCount () const |
const Property & | GetPropertyByIndex (size_t index) const |
size_t | GetChildListCount () const |
const ChildList & | GetChildListByIndex (size_t index) const |
bool | TryOpaqueGet (void *dst, size_t dstSize, ImpliedTyping::TypeDesc dstType, const void *src, uint64 id, bool stringForm=false) const |
template<typename ResultType , typename Type > | |
bool | TryGet (ResultType &result, const Type &src, uint64 id) const |
template<typename ResultType > | |
bool | TryGet (ResultType &result, const void *src, uint64 id) const |
bool | TryOpaqueSet (void *dst, uint64 id, const void *src, ImpliedTyping::TypeDesc srcType, bool stringForm=false) const |
bool | TryOpaqueSet (void *dst, uint64 id, size_t arrayIndex, const void *src, ImpliedTyping::TypeDesc srcType, bool stringForm=false) const |
template<typename Type > | |
bool | TryOpaqueSet (Type &dst, uint64 id, const void *src, ImpliedTyping::TypeDesc srcType, bool stringForm=false) const |
template<typename ValueType , typename Type > | |
bool | TrySet (const ValueType &valueSrc, Type &dst, uint64 id) const |
std::pair< void *, const ClassAccessors * > | TryCreateChild (void *dst, uint64 childListId) const |
template<typename Type > | |
std::pair< void *, const ClassAccessors * > | TryCreateChild (Type &dst, uint64 childListId) const |
template<typename GetFn , typename SetFn > | |
void | Add (const utf8 name[], GetFn &&getter, SetFn &&setter, size_t fixedArrayLength=1) |
template<typename ChildType , typename CreateFn , typename GetCountFn , typename GetByIndexFn , typename GetByKeyFn > | |
void | AddChildList (const utf8 name[], CreateFn &&, GetCountFn &&, GetByIndexFn &&, GetByKeyFn &&) |
ClassAccessors (size_t associatedType) | |
Protected Member Functions | |
Property & | PropertyForId (uint64 id) |
Protected Attributes | |
size_t | _associatedType |
VariantFunctions | _getters |
VariantFunctions | _setters |
std::vector< std::pair< uint64, Property > > | _properties |
std::vector< std::pair< uint64, ChildList > > | _childLists |
Get and set properties associated with a native C++ class
This class is designed to facilite interaction between a native class and data. For a class type, we can define get and set operations, with a given string name. The system can use these properties for serialisation tasks (as well as binding to data in various ways.
To use this system, classes must define a specialisation of GetAccessors<Type>(). That exposes a list of get and set operations to the system. Typically these get and set operations will use the default implementations. But sometimes custom functionality can be provided for special types.
Here is a typical implementation of GetAccessors<>()
Notice that some accessors provide access to a member. The "Size" accessor has a special case "get" implementation. We could have provided a "set" for "Size" as well – but in this case it's ommitted.
Classes with registered accessors can be used with the AccessorSerialize and AccessorDeserialize functions. These can load and save these types automatically.
This system is particularly useful for types that require multiple different types of serialisation methods (or multiple data-based ways to interact with them). For example, the editor performs string based get and sets on native types. At the same type, we may want to have separate code to load and save those types from disk. This is a perfect type to use class accessors.