1+
2+ #include < vector>
3+ #include < string>
4+ #include < iostream>
5+
6+ #include " ../../CxxTestProps/inc/Date.h"
7+ #include " ../../CxxTestProps/inc/Book.h"
8+ #include " ../../CxxTestProps/inc/Animal.h"
9+ #include " ../../CxxTestProps/inc/Person.h"
10+ #include " ../../CxxTestProps/inc/Library.h"
11+ #include " ../../CxxTestProps/inc/Complex.h"
12+ #include " ../src/MyReflectionTests/MyReflectingType.h"
13+
14+ #include " TestUtilsBook.h"
15+ #include " TestUtilsDate.h"
16+ #include " TestUtilsPerson.h"
17+ #include " TestUtilsAnimal.h"
18+ #include " GlobalTestUtils.h"
19+
20+ #include " RTLibInterface.h"
21+ #include " CxxMirrorThreadingTest.h"
22+
23+ using namespace test_utils ;
24+
25+ namespace rtl_tests
26+ {
27+ void InitMirror::reflectingEvent ()
28+ {
29+ auto _ = rtl::CxxMirror ({
30+
31+ rtl::type ().ns (event::ns).record <nsdate::Event>(event::struct_).build (),
32+
33+ rtl::type ().member <nsdate::Event>().method (event::str_reset).build (&nsdate::Event::reset),
34+ });
35+
36+ std::cout << " \n [t2]\t rtl_tests::InitMirror::reflectingEvent() ==> Done.\n " ;
37+ }
38+
39+
40+ void InitMirror::reflectingLibrary ()
41+ {
42+ auto _ = rtl::CxxMirror ({
43+
44+ rtl::type ().record <Library>(library::class_).build (),
45+
46+ rtl::type ().member <Library>().methodStatic (library::str_addBook).build (&Library::addBook),
47+
48+ rtl::type ().member <Library>().methodStatic (library::str_getBookByTitle).build (&Library::getBookByTitle)
49+ });
50+
51+ std::cout << " \n [t5]\t rtl_tests::InitMirror::reflectingLibrary() ==> Done.\n " ;
52+ }
53+
54+
55+ void InitMirror::reflectingDate ()
56+ {
57+ auto _ = rtl::CxxMirror ({
58+
59+ rtl::type ().ns (date::ns).record <nsdate::Date>(date::struct_).build (),
60+
61+ rtl::type ().member <nsdate::Date>().constructor <std::string>().build (),
62+
63+ rtl::type ().member <nsdate::Date>().constructor <unsigned , unsigned , unsigned >().build (),
64+
65+ rtl::type ().member <nsdate::Date>().method (date::str_updateDate).build (&nsdate::Date::updateDate),
66+
67+ rtl::type ().member <nsdate::Date>().methodConst (date::str_getAsString).build (&nsdate::Date::getAsString)
68+ });
69+
70+ std::cout << " \n [t1]\t rtl_tests::InitMirror::reflectingDate() ==> Done.\n " ;
71+ }
72+
73+
74+ void InitMirror::reflectingCalender ()
75+ {
76+ auto _ = rtl::CxxMirror ({
77+
78+ rtl::type ().ns (date::ns).record <nsdate::Calender>(calender::struct_).build (),
79+
80+ rtl::type ().member <nsdate::Calender>().methodStatic (calender::str_create).build (&nsdate::Calender::create),
81+
82+ rtl::type ().member <nsdate::Calender>().method (calender::str_getTheEvent).build (&nsdate::Calender::getTheEvent),
83+
84+ rtl::type ().member <nsdate::Calender>().method (calender::str_getTheDate).build (&nsdate::Calender::getTheDate),
85+
86+ rtl::type ().member <nsdate::Calender>().method (calender::str_getSavedEvent).build (&nsdate::Calender::getSavedEvent),
87+
88+ rtl::type ().member <nsdate::Calender>().method (calender::str_getSavedDate).build (&nsdate::Calender::getSavedDate)
89+ });
90+
91+ std::cout << " \n [t7]\t rtl_tests::InitMirror::reflectingCalender() ==> Done.\n " ;
92+ }
93+
94+
95+ void InitMirror::reflectingPodsStl ()
96+ {
97+ auto _ = rtl::CxxMirror ({
98+
99+ rtl::type ().function (" strlen" ).build (std::strlen),
100+
101+ rtl::type ().record <void >(" void" ).build (),
102+
103+ rtl::type ().record <char >(" char" ).build (),
104+
105+ rtl::type ().record <std::vector<int >>(" vector_int" ).build (),
106+
107+ rtl::type ().ns (" std" ).record <std::string>(" string" ).build (),
108+
109+ rtl::type ().ns (" std" ).record <std::string_view>(" string_view" ).build (),
110+
111+ rtl::type ().member <std::string>().methodConst (" empty" ).build (&std::string::empty),
112+
113+ rtl::type ().member <std::string_view>().methodConst (" empty" ).build (&std::string_view::empty),
114+
115+ rtl::type ().member <std::vector<int >>().methodConst (" empty" ).build (&std::vector<int >::empty),
116+
117+ rtl::type ().member <std::vector<int >>().method <const int &>(" push_back" ).build (&std::vector<int >::push_back)
118+ });
119+
120+ std::cout << " \n [t6]\t rtl_tests::InitMirror::reflectingPodsStl() ==> Done.\n " ;
121+ }
122+
123+
124+ void InitMirror::reflectingCStyleFunctions ()
125+ {
126+ auto _ = rtl::CxxMirror ({
127+
128+ rtl::type ().function <void >(str_reverseString).build (reverseString),
129+
130+ rtl::type ().function <std::string>(str_reverseString).build (reverseString),
131+
132+ rtl::type ().function <const char *>(str_reverseString).build (reverseString),
133+
134+ rtl::type ().function (str_getComplexNumAsString).build (getComplexNumAsString),
135+
136+ rtl::type ().ns (str_complex).function (str_setReal).build (complex ::setReal),
137+
138+ rtl::type ().ns (str_complex).function (str_setImaginary).build (complex ::setImaginary),
139+
140+ rtl::type ().ns (str_complex).function (str_getMagnitude).build (complex ::getMagnitude),
141+
142+ rtl::type ().ns (" ext" ).function (" sendString" ).build (my_type::ext::sendString),
143+
144+ rtl::type ().ns (" ext" ).function <const char *>(" sendAsString" ).build (my_type::ext::sendAsString),
145+
146+ rtl::type ().ns (" ext" ).function <my_type::Person>(" sendAsString" ).build (my_type::ext::sendAsString),
147+
148+ rtl::type ().ns (" ext" ).function <my_type::Person&&>(" sendAsString" ).build (my_type::ext::sendAsString)
149+ });
150+
151+ std::cout << " \n [t9]\t rtl_tests::InitMirror::reflectingCStyleFunctions() ==> Done.\n " ;
152+ }
153+
154+
155+ void InitMirror::reflectingBook ()
156+ {
157+ auto _ = rtl::CxxMirror ({
158+
159+ rtl::type ().record <Book>(book::class_).build (),
160+
161+ rtl::type ().member <Book>().constructor <double , std::string>().build (),
162+
163+ rtl::type ().member <Book>().method (book::str_setAuthor).build (&Book::setAuthor),
164+
165+ rtl::type ().member <Book>().method (book::str_addPreface).build (&Book::addPreface),
166+
167+ rtl::type ().member <Book>().method (book::str_setDescription).build (&Book::setDescription),
168+
169+ rtl::type ().member <Book>().method (book::str_getPublishedOn).build (&Book::getPublishedOn),
170+
171+ rtl::type ().member <Book>().method (book::str_addCopyrightTag).build (&Book::addCopyrightTag),
172+
173+ rtl::type ().member <Book>().method <void >(book::str_updateBookInfo).build (&Book::updateBookInfo),
174+
175+ rtl::type ().member <Book>().method <const char *, double , std::string>(book::str_updateBookInfo).build (&Book::updateBookInfo),
176+
177+ rtl::type ().member <Book>().method <std::string, double , const char *>(book::str_updateBookInfo).build (&Book::updateBookInfo)
178+ });
179+
180+ std::cout << " \n [t0]\t rtl_tests::InitMirror::reflectingBook() ==> Done.\n " ;
181+ }
182+
183+
184+ void InitMirror::reflectingMyTypePerson ()
185+ {
186+ auto _ = rtl::CxxMirror ({
187+
188+ rtl::type ().record <my_type::Person>(" Person" ).build (),
189+
190+ rtl::type ().member <my_type::Person>().constructor <std::string>().build (),
191+
192+ rtl::type ().member <my_type::Person>().method (" getName" ).build (&my_type::Person::getName),
193+
194+ rtl::type ().member <my_type::Person>().methodStatic (" getDefaults" ).build (&my_type::Person::getDefaults),
195+
196+ rtl::type ().member <my_type::Person>().method (" updateAddress" ).build (&my_type::Person::updateAddress),
197+
198+ rtl::type ().member <my_type::Person>().methodConst (" updateAddress" ).build (&my_type::Person::updateAddress),
199+
200+ rtl::type ().member <my_type::Person>().method (" setTitle" ).build (&my_type::Person::setTitle),
201+
202+ rtl::type ().member <my_type::Person>().method <std::string&&>(" setOccupation" ).build (&my_type::Person::setOccupation),
203+
204+ rtl::type ().member <my_type::Person>().method <const std::string&>(" setOccupation" ).build (&my_type::Person::setOccupation),
205+
206+ rtl::type ().member <my_type::Person>().method <std::string>(" setProfile" ).build (&my_type::Person::setProfile),
207+
208+ rtl::type ().member <my_type::Person>().method <std::string&>(" setProfile" ).build (&my_type::Person::setProfile),
209+
210+ rtl::type ().member <my_type::Person>().methodConst (" getProfile" ).build (&my_type::Person::getProfile)
211+ });
212+
213+ std::cout << " \n [t8]\t rtl_tests::InitMirror::reflectingMyTypePerson() ==> Done.\n " ;
214+ }
215+
216+
217+ void InitMirror::reflectingPerson ()
218+ {
219+ auto _ = rtl::CxxMirror ({
220+
221+ rtl::type ().record <Person>(person::class_).build (),
222+
223+ rtl::type ().member <Person>().constructor <std::string>().build (),
224+
225+ rtl::type ().member <Person>().methodStatic (person::str_createPtr).build (&Person::createPtr),
226+
227+ rtl::type ().member <Person>().method <void >(person::str_updateAddress).build (&Person::updateAddress),
228+
229+ rtl::type ().member <Person>().method <std::string>(person::str_updateAddress).build (&Person::updateAddress),
230+
231+ rtl::type ().member <Person>().method (person::str_getFirstName).build (&Person::getFirstName),
232+
233+ rtl::type ().member <Person>().methodConst (person::str_updateLastName).build (&Person::updateLastName),
234+
235+ rtl::type ().member <Person>().methodConst <void >(person::str_updateAddress).build (&Person::updateAddress),
236+
237+ rtl::type ().member <Person>().methodConst <std::string>(person::str_updateAddress).build (&Person::updateAddress),
238+
239+ rtl::type ().member <Person>().methodStatic (person::str_getDefaults).build (&Person::getDefaults),
240+
241+ rtl::type ().member <Person>().methodStatic (person::str_createConst).build (&Person::createConst),
242+
243+ rtl::type ().member <Person>().methodStatic <void >(person::str_getProfile).build (&Person::getProfile),
244+
245+ rtl::type ().member <Person>().methodStatic <bool >(person::str_getProfile).build (&Person::getProfile),
246+
247+ rtl::type ().member <Person>().methodStatic <std::string, size_t >(person::str_getProfile).build (&Person::getProfile)
248+ });
249+
250+ std::cout << " \n [t4]\t rtl_tests::InitMirror::reflectingPerson() ==> Done.\n " ;
251+ }
252+
253+
254+ void InitMirror::reflectingAnimal ()
255+ {
256+ auto _ = rtl::CxxMirror ({
257+
258+ rtl::type ().record <Animal>(animal::class_).build (),
259+
260+ rtl::type ().member <Animal>().constructor <std::string>().build (),
261+
262+ rtl::type ().member <Animal>().method (animal::str_setFamilyName).build (&Animal::setFamilyName),
263+
264+ rtl::type ().member <Animal>().methodConst (animal::str_getFamilyName).build (&Animal::getFamilyName),
265+
266+ rtl::type ().member <Animal>().method <const std::string&>(animal::str_setAnimalName).build (&Animal::setAnimalName),
267+
268+ rtl::type ().member <Animal>().methodStatic <const std::string&>(animal::str_updateZooKeeper).build (&Animal::updateZooKeeper),
269+
270+ #if defined(__GNUC__) && !defined(__clang__)
271+ /* GCC fails to automatically identify the correct overloaded functor to pick. (non-const-lvalue-ref & rvalue as argument)
272+ we need to explicitly cast the functor like, static_cast<void(Animal::*)(std::string&)>(&Animal::setAnimalName).
273+ */ rtl::type ().member <Animal>()
274+ .method <std::string&>(animal::str_setAnimalName)
275+ .build (static_cast <void (Animal::*)(std::string&)>(&Animal::setAnimalName)), // overloaded method, taking non-const lvalue reference as argument.
276+
277+ rtl::type ().member <Animal>()
278+ .method <std::string&&>(animal::str_setAnimalName)
279+ .build (static_cast <void (Animal::*)(std::string&&)>(&Animal::setAnimalName)), // overloaded method, taking rvalue reference as argument.
280+
281+ rtl::type ().member <Animal>()
282+ .methodStatic <std::string&>(animal::str_updateZooKeeper)
283+ .build (static_cast <std::string (*)(std::string&)>(&Animal::updateZooKeeper)), // static method, taking non-const lvalue reference as argument.
284+
285+ rtl::type ().member <Animal>()
286+ .methodStatic <std::string&&>(animal::str_updateZooKeeper)
287+ .build (static_cast <std::string (*)(std::string&&)>(&Animal::updateZooKeeper)), // static method, taking rvalue reference as argument.
288+ #else
289+ rtl::type ().member <Animal>()
290+ .method <std::string&>(animal::str_setAnimalName)
291+ .build (&Animal::setAnimalName),
292+
293+ rtl::type ().member <Animal>()
294+ .method <std::string&&>(animal::str_setAnimalName)
295+ .build (&Animal::setAnimalName),
296+
297+ rtl::type ().member <Animal>()
298+ .methodStatic <std::string&>(animal::str_updateZooKeeper)
299+ .build (&Animal::updateZooKeeper),
300+
301+ rtl::type ().member <Animal>()
302+ .methodStatic <std::string&&>(animal::str_updateZooKeeper)
303+ .build (&Animal::updateZooKeeper)
304+ #endif
305+ });
306+
307+ std::cout << " \n [t3]\t rtl_tests::InitMirror::reflectingAnimal() ==> Done.\n " ;
308+ }
309+ }
0 commit comments