1+
2+ #include < Reflect.hpp>
3+
4+ #include " Animal.h"
5+ #include " Registration.h"
6+ #include " TestUtilsAnimal.h"
7+
8+ using namespace test_utils ;
9+
10+ namespace test_mirror
11+ {
12+ void registerTypeAnimal (std::vector<rtl::Function>& fns)
13+ {
14+ // class 'Animal', methods & constructors.
15+ fns.push_back (rtl::type ().record <Animal>(animal::class_)
16+ .build ());
17+
18+ fns.push_back (rtl::type ().member <Animal>()
19+ .constructor <std::string>()
20+ .build ()); // overloaded constructor.
21+
22+ fns.push_back (rtl::type ().member <Animal>()
23+ .method (animal::str_setFamilyName)
24+ .build (&Animal::setFamilyName)); // unique method, no overloads.
25+
26+ // Unique const-method, no overloads.
27+ fns.push_back (rtl::type ().member <Animal>()
28+ .methodConst (animal::str_getFamilyName)
29+ .build (&Animal::getFamilyName));
30+
31+ // Overloaded method, taking const-ref as argument.
32+ fns.push_back (rtl::type ().member <Animal>()
33+ .method <const std::string&>(animal::str_setAnimalName)
34+ .build (&Animal::setAnimalName));
35+
36+ // Static method, taking const-ref as argument.
37+ fns.push_back (rtl::type ().member <Animal>()
38+ .methodStatic <const std::string&>(animal::str_updateZooKeeper)
39+ .build (&Animal::updateZooKeeper));
40+
41+ #if defined(__GNUC__) && !defined(__clang__)
42+ /*
43+ GCC here fails to automatically resolve the correct overloaded functor
44+ when both a lvalue reference and an rvalue overload exist.
45+ To disambiguate, explicitly cast the member function pointer, e.g.:
46+
47+ static_cast<void (Animal::*)(std::string&)>(&Animal::setAnimalName)
48+ */
49+ fns.push_back (rtl::type ().member <Animal>()
50+ .method <std::string&>(animal::str_setAnimalName)
51+ .build (static_cast <void (Animal::*)(std::string&)>(&Animal::setAnimalName))); // overloaded method, taking non-const lvalue reference as argument.
52+
53+ fns.push_back (rtl::type ().member <Animal>()
54+ .method <std::string&&>(animal::str_setAnimalName)
55+ .build (static_cast <void (Animal::*)(std::string&&)>(&Animal::setAnimalName))); // overloaded method, taking rvalue reference as argument.
56+
57+ fns.push_back (rtl::type ().member <Animal>()
58+ .methodStatic <std::string&>(animal::str_updateZooKeeper)
59+ .build (static_cast <std::string (*)(std::string&)>(&Animal::updateZooKeeper))); // static method, taking non-const lvalue reference as argument.
60+
61+ fns.push_back (rtl::type ().member <Animal>()
62+ .methodStatic <std::string&&>(animal::str_updateZooKeeper)
63+ .build (static_cast <std::string (*)(std::string&&)>(&Animal::updateZooKeeper))); // static method, taking rvalue reference as argument.
64+ #else
65+ fns.push_back (rtl::type ().member <Animal>()
66+ .method <std::string&>(animal::str_setAnimalName)
67+ .build (&Animal::setAnimalName)); // overloaded method, taking non-const lvalue reference as argument.
68+
69+ fns.push_back (rtl::type ().member <Animal>()
70+ .method <std::string&&>(animal::str_setAnimalName)
71+ .build (&Animal::setAnimalName)); // overloaded method, taking rvalue reference as argument.
72+
73+ fns.push_back (rtl::type ().member <Animal>()
74+ .methodStatic <std::string&>(animal::str_updateZooKeeper)
75+ .build (&Animal::updateZooKeeper)); // static method, taking non-const lvalue reference as argument.
76+
77+ fns.push_back (rtl::type ().member <Animal>()
78+ .methodStatic <std::string&&>(animal::str_updateZooKeeper)
79+ .build (&Animal::updateZooKeeper)); // static method, taking rvalue reference as argument.
80+ #endif
81+ }
82+ }
0 commit comments