Metadata¶
Aka bootleg reflection
Introduction¶
cronch is mostly an interface for consuming metadata. The rest of its API is just layers on other libraries that do all the heavy lifting.
Customisation points¶
-
template<typename T>
class metadata¶ This is the main customisation point of cronch. It is used to add a type to the introspection system and to thereby allow the serializing and deserializing of it.
The unspecialised form has no members and is completely empty. To make a type consumable by cronch, you must specialise this struct for your type and define the needed members. See Metadata concepts for more information.
Possible fields
-
meta::concepts::view members¶
Members of the type for use when serializing and deserializing. See
meta::mems
for the provided concrete type for this.
Example
#include <cronch/meta.hpp> #include <cronch/metadata.hpp> struct my_type { int my_field; }; namespace cronch { template<> struct metadata<my_type> { static constexpr auto name = "my_type"; static constexpr auto fields = cronch::meta::fields( cronch::meta::field("my_field", &my_type::my_field)); }; } // namespace cronch
-
meta::concepts::view members¶
Helper macros¶
-
CRONCH_META_TYPE(type, fields)¶
Shortcut for generating
metadata<type>
. The name is set totype
while the fields are passed tometa::mems
and set as the value ofmetadata<type>::members
.Example
#include <cronch/meta.hpp> struct my_type { int i; }; CRONCH_META_TYPE(my_type, (cronch::meta::field("i", &my_type::i)))
-
CRONCH_META_TYPE(type)
Same as CRONCH_META_TYPE(type, fields) but without the fields
Important Note
These macros must be used either in the cronch
namespace or outside of any namespaces.
Registration helpers¶
-
template<typename T, typename V>
class field¶ Holds a field belonging to T with type V.
Constructors
-
template<typename T, typename R, typename S>
class property¶ Holds a property of T, the value of which is set via setter and obtained via getter. serializing a type requires all getters for it to be non-null while deserializing it requires all setters to be non-null
Constructors
-
constexpr property::property(std::string_view name, R (T::* getter) = nullptr, void (T::* setter) = nullptr)¶
- constexpr property::property(std::string_view name, R(* getter)(const T* ) = nullptr, void(* setter)(T* , S) = nullptr)
- constexpr property::property(std::string_view name, R(* getter)(const T&) = nullptr, void(* setter)(T&, S) = nullptr)
-
constexpr property::property(std::string_view name, R (T::* getter) = nullptr, void (T::* setter) = nullptr)¶
-
template<typename ...Fs>
class mems¶ Holds the members of a type (which may be
property
orfield
’s)Constructors
Note¶
All these types are simply implementations of concepts in Metadata concepts that are provided to make cronch easier to use. There is nothing to stop you defining your own accessor types and using those instead of/in conjunction with the above.