8 #include <rttr/registration>
9 #ifdef NAP_ENABLE_PYTHON
10 #include "pythonmodule.h"
12 #include <utility/dllexport.h>
141 using Enum = rttr::enumeration;
192 return static_cast<EPropertyMetaData>(
static_cast<uint8_t
>(a) &
static_cast<uint8_t
>(b));
197 return static_cast<EPropertyMetaData>(
static_cast<uint8_t
>(a) |
static_cast<uint8_t
>(b));
205 return type.is_arithmetic() || type.is_enumeration() || type == rtti::TypeInfo::get<std::string>();
213 const rtti::Variant& meta_data =
property.get_metadata(
"flags");
214 if (!meta_data.is_valid())
217 uint8_t current_flags = meta_data.convert<uint8_t>();
218 return (current_flags & (uint8_t)flags) != 0;
227 const rtti::Variant& meta_data =
property.get_metadata(
"filetype");
228 return meta_data.is_valid() ?
229 meta_data.convert<uint8_t>() == (uint8_t)filetype :
false;
261 auto result = base.get_method(methodName);
262 if (result.is_valid())
265 return type.get_method(methodName);
287 struct void_ {
typedef void type; };
289 template<
typename Type,
typename =
void>
292 using List = rttr::detail::type_list<>;
295 template<
typename Type>
296 struct BaseClassList<Type, typename void_<typename Type::base_class_list>::type>
298 using List =
typename Type::base_class_list;
312 template <
typename Return,
typename... Args>
313 bool isReturnTypeLValueReference(Return(*f)(Args...))
315 return std::is_lvalue_reference<Return>();
318 template <
typename Return,
typename Class,
typename... Arg>
319 bool isReturnTypeLValueReference(Return(Class::*f)(Arg...))
321 return std::is_lvalue_reference<Return>();
324 template <
typename Return,
typename Class,
typename... Arg>
325 bool isReturnTypeLValueReference(Return(Class::*f)(Arg...)
const)
327 return std::is_lvalue_reference<Return>();
340 #define RTTI_OF(Type) nap::rtti::TypeInfo::get<Type>()
352 #define RTTI_ENABLE(...) \
353 RTTR_ENABLE(__VA_ARGS__) \
354 RTTR_REGISTRATION_FRIEND
361 #define CONCAT_UNIQUE_NAMESPACE(x, y) namespace x##y
362 #define UNIQUE_REGISTRATION_NAMESPACE(id) CONCAT_UNIQUE_NAMESPACE(__rtti_registration_, id)
370 #ifdef NAP_ENABLE_PYTHON
371 #define RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR_1(Type) \
372 UNIQUE_REGISTRATION_NAMESPACE(__COUNTER__) \
376 using namespace rttr; \
377 namespace py = pybind11; \
378 using PythonClassType = nap::rtti::PythonClass<Type, nap::detail::BaseClassList<Type>::List>; \
379 std::string rtti_class_type_name = #Type; \
380 registration::class_<Type> rtti_class_type(#Type); \
381 PythonClassType python_class(#Type);
382 #else // NAP_ENABLE_PYTHON
383 #define RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR_1(Type) \
384 UNIQUE_REGISTRATION_NAMESPACE(__COUNTER__) \
388 using namespace rttr; \
389 std::string rtti_class_type_name = #Type; \
390 registration::class_<Type> rtti_class_type(#Type);
391 #endif // NAP_ENABLE_PYTHON
401 #ifdef NAP_ENABLE_PYTHON
402 #define RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR_2(Type, Description) \
403 UNIQUE_REGISTRATION_NAMESPACE(__COUNTER__) \
405 static const char* getTypeDescription() { return Description; } \
408 using namespace rttr; \
409 namespace py = pybind11; \
410 using PythonClassType = nap::rtti::PythonClass<Type, nap::detail::BaseClassList<Type>::List>; \
411 std::string rtti_class_type_name = #Type; \
412 registration::class_<Type> rtti_class_type(#Type); \
413 rtti_class_type.method(nap::rtti::method::description, &getTypeDescription); \
414 PythonClassType python_class(#Type);
415 #else // NAP_ENABLE_PYTHON
416 #define RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR_2(Type, Description) \
417 UNIQUE_REGISTRATION_NAMESPACE(__COUNTER__) \
419 static const char* getTypeDescription() { return Description; } \
422 using namespace rttr; \
423 std::string rtti_class_type_name = #Type; \
424 registration::class_<Type> rtti_class_type(#Type); \
425 rtti_class_type.method(nap::rtti::method::description, &getTypeDescription);
426 #endif // NAP_ENABLE_PYTHON
429 #define GET_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR_MACRO(_1,_2,NAME,...) NAME
438 #define RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(...) GET_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR_MACRO(__VA_ARGS__, RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR_2, RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR_1)(__VA_ARGS__)
452 #ifdef NAP_ENABLE_PYTHON
453 #define RTTI_PROPERTY_3(Name, Member, Flags) \
454 rtti_class_type.property(Name, Member)( metadata("flags", (uint8_t)(Flags))); \
455 python_class.registerFunction([](pybind11::module& module, PythonClassType::PybindClass& cls) \
457 if(((uint8_t)(Flags) & (uint8_t)(nap::rtti::EPropertyMetaData::ReadOnly)) != 0) \
458 cls.def_readonly(Name, Member); \
460 cls.def_readwrite(Name, Member); \
463 #define RTTI_PROPERTY_3(Name, Member, Flags) \
464 rtti_class_type.property(Name, Member)( metadata("flags", (uint8_t)(Flags)));
465 #endif // NAP_ENABLE_PYTHON
475 #ifdef NAP_ENABLE_PYTHON
476 #define RTTI_PROPERTY_4(Name, Member, Flags, Description) \
477 rtti_class_type.property(Name, Member)( \
478 metadata("flags", (uint8_t)(Flags)), \
479 metadata("description", (const char*)(Description))); \
480 python_class.registerFunction([](pybind11::module& module, PythonClassType::PybindClass& cls) \
482 if(((uint8_t)(Flags) & (uint8_t)(nap::rtti::EPropertyMetaData::ReadOnly)) != 0) \
483 cls.def_readonly(Name, Member); \
485 cls.def_readwrite(Name, Member); \
488 #define RTTI_PROPERTY_4(Name, Member, Flags, Description) \
489 rtti_class_type.property(Name, Member)( \
490 metadata("flags", (uint8_t)(Flags)), \
491 metadata("description", (const char*)(Description)));
492 #endif // NAP_ENABLE_PYTHON
494 #define GET_PROPERTY_MACRO(_1,_2,_3,_4,NAME,...) NAME
505 #define RTTI_PROPERTY(...) GET_PROPERTY_MACRO(__VA_ARGS__, RTTI_PROPERTY_4, RTTI_PROPERTY_3)(__VA_ARGS__)
520 #ifdef NAP_ENABLE_PYTHON
521 #define RTTI_PROPERTY_FILELINK_4(Name, Member, Flags, FileType) \
522 rtti_class_type.property(Name, Member)( \
523 metadata("flags", (uint8_t)(nap::rtti::EPropertyMetaData::FileLink | Flags)), \
524 metadata("filetype", (uint8_t)(FileType))); \
525 python_class.registerFunction([](pybind11::module& module, PythonClassType::PybindClass& cls) \
527 cls.def_readwrite(Name, Member); \
529 #else // NAP_ENABLE_PYTHON
530 #define RTTI_PROPERTY_FILELINK_4(Name, Member, Flags, FileType) \
531 rtti_class_type.property(Name, Member)( \
532 metadata("flags", (uint8_t)(nap::rtti::EPropertyMetaData::FileLink | Flags)), \
533 metadata("filetype", (uint8_t)(FileType)));
534 #endif // NAP_ENABLE_PYTHON
545 #ifdef NAP_ENABLE_PYTHON
546 #define RTTI_PROPERTY_FILELINK_5(Name, Member, Flags, FileType, Description) \
547 rtti_class_type.property(Name, Member)( \
548 metadata("flags", (uint8_t)(nap::rtti::EPropertyMetaData::FileLink | Flags)), \
549 metadata("filetype", (uint8_t)(FileType)), \
550 metadata("description", (const char*)(Description))); \
551 python_class.registerFunction([](pybind11::module& module, PythonClassType::PybindClass& cls) \
553 cls.def_readwrite(Name, Member); \
555 #else // NAP_ENABLE_PYTHON
556 #define RTTI_PROPERTY_FILELINK_5(Name, Member, Flags, FileType, Description) \
557 rtti_class_type.property(Name, Member)( \
558 metadata("flags", (uint8_t)(nap::rtti::EPropertyMetaData::FileLink | Flags)), \
559 metadata("filetype", (uint8_t)(FileType)), \
560 metadata("description", (const char*)(Description)));
561 #endif // NAP_ENABLE_PYTHON
563 #define GET_PROPERTY_FILELINK_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
574 #define RTTI_PROPERTY_FILELINK(...) GET_PROPERTY_FILELINK_MACRO(__VA_ARGS__, RTTI_PROPERTY_FILELINK_5, RTTI_PROPERTY_FILELINK_4)(__VA_ARGS__)
587 #ifdef NAP_ENABLE_PYTHON
588 #define RTTI_FUNCTION(Name, Member) \
589 rtti_class_type.method(Name, Member); \
590 python_class.registerFunction([](pybind11::module& module, PythonClassType::PybindClass& cls) \
592 cls.def(Name, Member, nap::detail::isReturnTypeLValueReference(Member) ? py::return_value_policy::reference : py::return_value_policy::automatic_reference); \
594 #else // NAP_ENABLE_PYTHON
595 #define RTTI_FUNCTION(Name, Member) \
596 rtti_class_type.method(Name, Member);
597 #endif // NAP_ENABLE_PYTHON
604 #ifdef NAP_ENABLE_PYTHON
605 #define RTTI_CUSTOM_REGISTRATION_FUNCTION(Func) \
606 python_class.registerFunction(std::bind(&Func<PythonClassType::PybindClass>, std::placeholders::_1, std::placeholders::_2));
607 #else // NAP_ENABLE_PYTHON
608 #define RTTI_CUSTOM_REGISTRATION_FUNCTION(Func)
609 #endif // NAP_ENABLE_PYTHON
623 #ifdef NAP_ENABLE_PYTHON
624 #define RTTI_CONSTRUCTOR(...) \
625 rtti_class_type.constructor<__VA_ARGS__>()(policy::ctor::as_raw_ptr); \
626 python_class.registerFunction([](pybind11::module& module, PythonClassType::PybindClass& cls) \
628 cls.def(py::init<__VA_ARGS__>()); \
630 #else // NAP_ENABLE_PYTHON
631 #define RTTI_CONSTRUCTOR(...) \
632 rtti_class_type.constructor<__VA_ARGS__>()(policy::ctor::as_raw_ptr);
633 #endif // NAP_ENABLE_PYTHON
648 #ifdef NAP_ENABLE_PYTHON
649 #define RTTI_VALUE_CONSTRUCTOR(...) \
650 rtti_class_type.constructor<__VA_ARGS__>()(policy::ctor::as_object); \
651 python_class.registerFunction([](pybind11::module& module, PythonClassType::PybindClass& cls) \
653 cls.def(py::init<__VA_ARGS__>()); \
655 #else // NAP_ENABLE_PYTHON
656 #define RTTI_VALUE_CONSTRUCTOR(...) \
657 rtti_class_type.constructor<__VA_ARGS__>()(policy::ctor::as_object);
658 #endif // NAP_ENABLE_PYTHON
669 #ifdef NAP_ENABLE_PYTHON
670 #define RTTI_END_CLASS \
671 nap::rtti::PythonModule& python_module = nap::rtti::PythonModule::get("nap"); \
672 python_module.registerTypeImportCallback(rtti_class_type_name, \
673 [](std::vector<std::string>& baseTypes) \
675 PythonClassType::GetBaseTypes(baseTypes); \
677 [python_class](py::module& module) \
679 python_class.invoke(module); \
684 #define RTTI_END_CLASS \
687 #endif // NAP_ENABLE_PYTHON
701 #define RTTI_BEGIN_STRUCT_NO_DEFAULT_CONSTRUCTOR_1(Type) \
702 RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(Type)
712 #define RTTI_BEGIN_STRUCT_NO_DEFAULT_CONSTRUCTOR_2(Type, Description) \
713 RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(Type, Description)
715 #define GET_RTTI_BEGIN_STRUCT_NO_DEFAULT_CONSTRUCTOR_MACRO(_1,_2,NAME,...) NAME
725 #define RTTI_BEGIN_STRUCT_NO_DEFAULT_CONSTRUCTOR(...) GET_RTTI_BEGIN_STRUCT_NO_DEFAULT_CONSTRUCTOR_MACRO(__VA_ARGS__, RTTI_BEGIN_STRUCT_NO_DEFAULT_CONSTRUCTOR_2, RTTI_BEGIN_STRUCT_NO_DEFAULT_CONSTRUCTOR_1)(__VA_ARGS__)
737 #define RTTI_END_STRUCT \
751 #define RTTI_BEGIN_CLASS_1(Type) \
752 RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(Type) \
762 #define RTTI_BEGIN_CLASS_2(Type, Description) \
763 RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(Type, Description) \
766 #define GET_RTTI_BEGIN_CLASS_MACRO(_1,_2,NAME,...) NAME
775 #define RTTI_BEGIN_CLASS(...) GET_RTTI_BEGIN_CLASS_MACRO(__VA_ARGS__, RTTI_BEGIN_CLASS_2, RTTI_BEGIN_CLASS_1)(__VA_ARGS__)
789 #define RTTI_BEGIN_STRUCT_1(Type) \
790 RTTI_BEGIN_STRUCT_NO_DEFAULT_CONSTRUCTOR(Type) \
791 RTTI_VALUE_CONSTRUCTOR()
801 #define RTTI_BEGIN_STRUCT_2(Type, Description) \
802 RTTI_BEGIN_STRUCT_NO_DEFAULT_CONSTRUCTOR(Type, Description) \
803 RTTI_VALUE_CONSTRUCTOR()
805 #define GET_RTTI_BEGIN_STRUCT_MACRO(_1,_2,NAME,...) NAME
814 #define RTTI_BEGIN_STRUCT(...) GET_RTTI_BEGIN_STRUCT_MACRO(__VA_ARGS__, RTTI_BEGIN_STRUCT_2, RTTI_BEGIN_STRUCT_1)(__VA_ARGS__)
825 #define RTTI_BEGIN_ENUM(Type) \
826 UNIQUE_REGISTRATION_NAMESPACE(__COUNTER__) \
830 using namespace rttr; \
831 registration::enumeration<Type>(#Type) \
839 #define RTTI_ENUM_VALUE(Value, String) \
845 #define RTTI_END_ENUM \
861 #define RTTI_DEFINE_BASE_1(Type) \
862 RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(Type) \
872 #define RTTI_DEFINE_BASE_2(Type, Description) \
873 RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(Type, Description) \
876 #define GET_RTTI_DEFINE_BASE_MACRO(_1,_2,NAME,...) NAME
885 #define RTTI_DEFINE_BASE(...) GET_RTTI_DEFINE_BASE_MACRO(__VA_ARGS__, RTTI_DEFINE_BASE_2, RTTI_DEFINE_BASE_1)(__VA_ARGS__)
896 #define RTTI_DEFINE_CLASS_1(Type) \
897 RTTI_BEGIN_CLASS(Type) \
905 #define RTTI_DEFINE_CLASS_2(Type, Description) \
906 RTTI_BEGIN_CLASS(Type, Description) \
909 #define GET_RTTI_DEFINE_CLASS_MACRO(_1,_2,NAME,...) NAME
916 #define RTTI_DEFINE_CLASS(...) GET_RTTI_DEFINE_CLASS_MACRO(__VA_ARGS__, RTTI_DEFINE_CLASS_2, RTTI_DEFINE_CLASS_1)(__VA_ARGS__)
927 #define RTTI_DEFINE_STRUCT_1(Type) \
928 RTTI_BEGIN_STRUCT(Type) \
936 #define RTTI_DEFINE_STRUCT_2(Type, Description) \
937 RTTI_BEGIN_STRUCT(Type, Description) \
940 #define GET_RTTI_DEFINE_STRUCT_MACRO(_1,_2,NAME,...) NAME
947 #define RTTI_DEFINE_STRUCT(...) GET_RTTI_DEFINE_STRUCT_MACRO(__VA_ARGS__, RTTI_DEFINE_STRUCT_2, RTTI_DEFINE_STRUCT_1)(__VA_ARGS__)
EPropertyMetaData
Definition: typeinfo.h:163
constexpr const char * toObject
to object pointer
Definition: typeinfo.h:155
constexpr const char * assign
assignment
Definition: typeinfo.h:154
@ Embedded
An embedded pointer.
@ VertShader
Points to a .frag file, must be used with EPropertyMetaData::FileLink.
rttr::variant_array_view VariantArray
Definition: typeinfo.h:145
@ ImageSequence
Points to a an image sequence, must be used with EPropertyMetaData::FileLink.
@ Required
Load will fail if the property isn't set.
@ FragShader
Points to a .vert file, must be used with EPropertyMetaData::FileLink.
rttr::variant_associative_view VariantMap
Definition: typeinfo.h:146
constexpr const char * description
rtti type description
Definition: typeinfo.h:153
bool isTypeMatch(const rtti::TypeInfo &typeA, const rtti::TypeInfo &typeB, ETypeCheck typeCheck)
Definition: typeinfo.h:245
bool isFileType(const rtti::Property &property, EPropertyFileType filetype)
Definition: typeinfo.h:225
Definition: deserializeresult.h:28
rttr::enumeration Enum
Definition: typeinfo.h:141
rttr::property Property
Definition: typeinfo.h:142
constexpr const char * toString
to object path
Definition: typeinfo.h:156
constexpr const char * translateTargetID
transform id
Definition: typeinfo.h:157
@ Any
Can point to any file, default.
bool hasFlag(const rtti::Property &property, EPropertyMetaData flags)
Definition: typeinfo.h:211
@ ReadOnly
A read only property in Python.
@ Default
Uses the (class) default if the property isn't set.
bool isPrimitive(const rtti::TypeInfo &type)
Definition: typeinfo.h:203
rttr::method findMethodRecursive(const rtti::TypeInfo &type, const std::string &methodName)
Definition: typeinfo.h:257
Definition: templateapp.h:17
@ EXACT_MATCH
The type needs to be of the exact same kind.
rttr::instance Instance
Definition: typeinfo.h:144
EPropertyFileType
Definition: typeinfo.h:175
rttr::variant Variant
Definition: typeinfo.h:143
@ IS_DERIVED_FROM
The type is derived from the specified type.
@ Python
Points to a .py file, must be used with EPropertyMetaData::FileLink.
rttr::type TypeInfo
Definition: typeinfo.h:140
ETypeCheck
Definition: typeinfo.h:236
EPropertyMetaData operator&(EPropertyMetaData a, EPropertyMetaData b)
Definition: typeinfo.h:190
EPropertyMetaData operator|(EPropertyMetaData a, EPropertyMetaData b)
Definition: typeinfo.h:195
@ Audio
Points to an audio file, must be used with EPropertyMetaData::FileLink.