Skip to content

Commit 00e393e

Browse files
committed
CxxTestRegistration: improvements done.
1 parent 252ad6e commit 00e393e

19 files changed

+559
-499
lines changed

CxxTestRegistration/inc/Registration.h

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,52 @@ namespace rtl {
88

99
namespace test_mirror
1010
{
11-
static void registerPodStdTypes(std::vector<rtl::Function>&);
11+
extern void registerPodStdTypes(std::vector<rtl::Function>&);
1212

13-
static void registerTypeComplex(std::vector<rtl::Function>&);
13+
extern void registerTypeComplex(std::vector<rtl::Function>&);
1414

15-
static void registerTypeDate(std::vector<rtl::Function>&);
15+
extern void registerTypeDate(std::vector<rtl::Function>&);
1616

17-
static void registerTypeEvent(std::vector<rtl::Function>&);
17+
extern void registerTypeEvent(std::vector<rtl::Function>&);
1818

19-
static void registerTypeCalender(std::vector<rtl::Function>&);
19+
extern void registerTypeCalender(std::vector<rtl::Function>&);
2020

21-
static void registerTypePerson(std::vector<rtl::Function>&);
21+
extern void registerTypePerson(std::vector<rtl::Function>&);
2222

23-
static void registerTypeBook(std::vector<rtl::Function>&);
23+
extern void registerTypeBook(std::vector<rtl::Function>&);
2424

25-
static void registerTypeLibrary(std::vector<rtl::Function>&);
25+
extern void registerTypeLibrary(std::vector<rtl::Function>&);
2626

27-
static void registerTypeAnimal(std::vector<rtl::Function>&);
27+
extern void registerTypeAnimal(std::vector<rtl::Function>&);
28+
29+
extern void registerTypeStringFuncs(std::vector<rtl::Function>&);
30+
31+
extern void registerTypeStringMute(std::vector<rtl::Function>&);
32+
33+
extern void registerTypeStringConst(std::vector<rtl::Function>&);
34+
35+
extern void registerTypeStringStatic(std::vector<rtl::Function>&);
36+
37+
//---------------------------------------------------------------------------------
38+
extern void addTypeIdPodStd(std::unordered_map<std::string, std::size_t>&);
39+
40+
extern void addTypeIdDate(std::unordered_map<std::string, std::size_t>&);
41+
42+
extern void addTypeIdEvent(std::unordered_map<std::string, std::size_t>&);
43+
44+
extern void addTypeIdCalender(std::unordered_map<std::string, std::size_t>&);
45+
46+
extern void addTypeIdPerson(std::unordered_map<std::string, std::size_t>&);
47+
48+
extern void addTypeIdBook(std::unordered_map<std::string, std::size_t>&);
49+
50+
extern void addTypeIdLibrary(std::unordered_map<std::string, std::size_t>&);
51+
52+
extern void addTypeIdAnimal(std::unordered_map<std::string, std::size_t>&);
53+
54+
extern void addTypeIdStringMute(std::unordered_map<std::string, std::size_t>&);
55+
56+
extern void addTypeIdStringConst(std::unordered_map<std::string, std::size_t>&);
57+
58+
extern void addTypeIdStringStatic(std::unordered_map<std::string, std::size_t>&);
2859
}

CxxTestRegistration/inc/TestMirrorProvider.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,7 @@ namespace test_mirror
99
struct cxx {
1010

1111
static const rtl::CxxMirror& mirror();
12-
};
13-
}
14-
15-
namespace test_mirror
16-
{
17-
// Optional setup: do this if you prefer to access your registered types by unique 'ID', not by string.
18-
struct reflected_id {
19-
20-
static std::size_t date;
21-
static std::size_t book;
22-
static std::size_t event;
23-
static std::size_t animal;
24-
static std::size_t person;
25-
static std::size_t library;
26-
static std::size_t calender;
27-
static std::size_t string_m;
28-
static std::size_t string_c;
29-
static std::size_t string_s;
30-
31-
static std::size_t char_t;
32-
static std::size_t int_t;
33-
static std::size_t std_string;
34-
static std::size_t std_string_view;
3512

36-
static const std::size_t getRecordIdFor(const std::string& pRecordName);
13+
static const std::size_t reflected_id(const std::string& pRecordName);
3714
};
3815
}

CxxTestRegistration/src/AnimalRegistration.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ using namespace test_utils;
99

1010
namespace test_mirror
1111
{
12+
void addTypeIdAnimal(std::unordered_map<std::string, std::size_t>& id)
13+
{
14+
id.insert(std::make_pair(animal::class_, rtl::detail::TypeId<Animal>::get()));
15+
}
16+
1217
void registerTypeAnimal(std::vector<rtl::Function>& fns)
1318
{
1419
// class 'Animal', methods & constructors.

CxxTestRegistration/src/BookRegistration.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ using namespace test_utils;
99

1010
namespace test_mirror
1111
{
12+
void addTypeIdBook(std::unordered_map<std::string, std::size_t>& id)
13+
{
14+
id.insert(std::make_pair(book::class_, rtl::detail::TypeId<Book>::get()));
15+
}
16+
1217
void registerTypeBook(std::vector<rtl::Function>& fns)
1318
{
1419
// class 'Book', methods & constructors.

CxxTestRegistration/src/CalenderRegistration.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ using namespace test_utils;
1010

1111
namespace test_mirror
1212
{
13+
void addTypeIdCalender(std::unordered_map<std::string, std::size_t>& id)
14+
{
15+
id.insert(std::make_pair(calender::struct_, rtl::detail::TypeId<nsdate::Calender>::get()));
16+
}
17+
1318
void registerTypeCalender(std::vector<rtl::Function>& fns)
1419
{
1520
// Registring static-method, 'methodStatic()' function must be used. compiler error otherwise.

CxxTestRegistration/src/ComplexRegistration.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace test_mirror
1515
fns.push_back(rtl::type().function(str_getComplexNumAsString)
1616
.build(getComplexNumAsString));
1717

18-
/* Grouping functions under a namespace, which is optional. they can be registered without it as well.
19-
but if registered under namspace, then to retrieve it from CxxMirror object, namespace name must be passed,
20-
e.g. cxx::mirror().getFunction("namespace_name", "function_name") & cxx::mirror().getRecord("namespace_name", "record_name") */
18+
/* Grouping functions under a namespace, which is optional. they can be registered without it as well.
19+
but if registered under namspace, then to retrieve it from CxxMirror object, namespace name must be passed,
20+
e.g. cxx::mirror().getFunction("namespace_name", "function_name") & cxx::mirror().getRecord("namespace_name", "record_name") */
2121
fns.push_back(rtl::type().ns(str_complex)
2222
.function(str_setReal)
2323
.build(complex::setReal));

CxxTestRegistration/src/DateRegistration.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ using namespace test_utils;
99

1010
namespace test_mirror
1111
{
12+
void addTypeIdDate(std::unordered_map<std::string, std::size_t>& id)
13+
{
14+
id.insert(std::make_pair(date::struct_, rtl::detail::TypeId<nsdate::Date>::get()));
15+
}
16+
1217
void registerTypeDate(std::vector<rtl::Function>& fns)
1318
{
1419
// Constructors registration, class/struct name and type must be passed 'record<TYPE>("NAME")'.

CxxTestRegistration/src/EventRegistration.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ using namespace test_utils;
99

1010
namespace test_mirror
1111
{
12+
void addTypeIdEvent(std::unordered_map<std::string, std::size_t>& id)
13+
{
14+
id.insert(std::make_pair(event::struct_, rtl::detail::TypeId<nsdate::Event>::get()));
15+
}
16+
1217
void registerTypeEvent(std::vector<rtl::Function>& fns)
1318
{
1419
// Registering 'Event' for reflection; instance creation via reflection fails since its default constructor is private or deleted.

CxxTestRegistration/src/LibraryRegistration.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ using namespace test_utils;
1010

1111
namespace test_mirror
1212
{
13+
void addTypeIdLibrary(std::unordered_map<std::string, std::size_t>& id)
14+
{
15+
id.insert(std::make_pair(library::class_, rtl::detail::TypeId<Library>::get()));
16+
}
17+
1318
void registerTypeLibrary(std::vector<rtl::Function>& fns)
1419
{
1520
// Registering Library's constructor. Stack allocation (rtl::alloc::Stack) will fail since its copy constructor is deleted

CxxTestRegistration/src/PersonRegistration.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ using namespace test_utils;
99

1010
namespace test_mirror
1111
{
12+
void addTypeIdPerson(std::unordered_map<std::string, std::size_t>& id)
13+
{
14+
id.insert(std::make_pair(person::class_, rtl::detail::TypeId<Person>::get()));
15+
}
16+
1217
void registerTypePerson(std::vector<rtl::Function>& fns)
1318
{
1419
// class 'Person', methods & constructors.

0 commit comments

Comments
 (0)