|
15 | 15 |
|
16 | 16 | namespace rtl |
17 | 17 | { |
18 | | -/* @Constructor: CxxMirror |
19 | | - @params: 'const std::vector<Function>&' |
20 | | - * accepts vector of 'Function' objects, which are hash-key to lookup a functor. |
21 | | - * the only constructor to construct 'CxxMirror' object. |
22 | | - * Syntax for constructing - CxxMirror({ type().function("func_name").build(), ..., ... }) |
23 | | - * '.build()' function will return a 'Function' object, and passed to std::vector initializer list. |
24 | | - * the vector is simply forwarded to the base class constructor. |
25 | | -*/ CxxMirror::CxxMirror(const std::vector<Function>& pFunctions) : detail::CxxReflection(pFunctions) |
| 18 | + CxxMirror::CxxMirror(const std::vector<Function>& pFunctions) : detail::CxxReflection(pFunctions) |
26 | 19 | { |
27 | 20 | rtl::detail::ReflectedConversions::init(); |
28 | 21 | } |
29 | 22 |
|
30 | | -/* @method: getRecord |
31 | | - @param: const std::string& (name of the class/struct) |
32 | | - @return: std::optional<Record> |
33 | | - * if the class/struct isn't found by the given name, std::nullopt is returned. |
34 | | - * every class/struct's is grouped under a namespace. |
35 | | - * if no namespace is specified while registration, NAMESPACE_GLOBAL is used. |
36 | | -*/ std::optional<Record> CxxMirror::getRecord(const std::string& pRecord) const |
| 23 | + /** |
| 24 | + * @method getRecord |
| 25 | + * |
| 26 | + * @param pRecordName The name of the class or struct to look up. |
| 27 | + * @return std::optional<rtl::Record> |
| 28 | + * Returns a valid Record if the type is found by name in default namespace group; otherwise, std::nullopt. |
| 29 | + * |
| 30 | + * All registered classes and structs are grouped under a namespace. |
| 31 | + * If no namespace is specified during registration, NAMESPACE_GLOBAL(the default) is used. */ |
| 32 | + std::optional<Record> CxxMirror::getRecord(const std::string& pRecordName) const |
37 | 33 | { |
38 | | - return getRecord(std::string(detail::NAMESPACE_GLOBAL), pRecord); |
| 34 | + return getRecord(std::string(detail::NAMESPACE_GLOBAL), pRecordName); |
39 | 35 | } |
40 | 36 |
|
41 | | -/* @method: getFunction |
42 | | - @param: const std::string& (name of the non-member function) |
43 | | - @return: std::optional<Function> |
44 | | - * if the function isn't found by the given name, std::nullopt is returned. |
45 | | - * every function is grouped under a namespace. |
46 | | - * if no namespace is specified while registration, NAMESPACE_GLOBAL is used. |
47 | | -*/ std::optional<Function> CxxMirror::getFunction(const std::string& pFunction) const |
| 37 | + /** |
| 38 | + * @method getFunction |
| 39 | + * |
| 40 | + * @param pFunctionName The name of the non-member function to look up. |
| 41 | + * @return std::optional<rtl::Function> |
| 42 | + * Returns a valid Function if found by name in default namespace group; otherwise, std::nullopt. |
| 43 | + * |
| 44 | + * All registered non-member functions are grouped under a namespace. |
| 45 | + * If no namespace is specified during registration, NAMESPACE_GLOBAL(the default) is used. */ |
| 46 | + std::optional<Function> CxxMirror::getFunction(const std::string& pFunctionName) const |
48 | 47 | { |
49 | | - return getFunction(std::string(detail::NAMESPACE_GLOBAL), pFunction); |
| 48 | + return getFunction(std::string(detail::NAMESPACE_GLOBAL), pFunctionName); |
50 | 49 | } |
51 | 50 |
|
52 | | - std::optional<Record> CxxMirror::getRecord(const std::size_t pRecordId) const |
| 51 | + /** |
| 52 | + * @method getRecord |
| 53 | + * |
| 54 | + * @param pRecordId The RTL-specific unique type identifier. |
| 55 | + * @return std::optional<rtl::Record> |
| 56 | + * Returns a valid Record if the type is found; otherwise, std::nullopt. |
| 57 | + * |
| 58 | + * Every registered type `T` is assigned a unique integer type ID, which can be |
| 59 | + * obtained via `rtl::traits::uid<T>::value` and cached for efficient lookup. |
| 60 | + * |
| 61 | + * The primary benefit of using a type ID is that it avoids the need to provide |
| 62 | + * the namespace and type name as strings during lookup. */ |
| 63 | + std::optional<Record> CxxMirror::getRecord(const traits::uid_t pRecordId) const |
53 | 64 | { |
54 | 65 | const auto& recordMap = getRecordIdMap(); |
55 | 66 | const auto& itr = recordMap.find(pRecordId); |
56 | 67 | return (itr == recordMap.end() ? std::nullopt : std::make_optional(itr->second)); |
57 | 68 | } |
58 | 69 |
|
59 | | -/* @method: getRecord |
60 | | - @param: std::string (namespace name), std::string (class/struct name) |
61 | | - @return: std::optional<Record> |
62 | | - * retrieves the class/struct (as Record) registered under the given namespace. |
63 | | - * if the class/struct isn't found by the given name, std::nullopt is returned. |
64 | | -*/ std::optional<Record> CxxMirror::getRecord(const std::string& pNameSpace, const std::string& pRecord) const |
| 70 | + /** |
| 71 | + * @method getRecord |
| 72 | + * |
| 73 | + * @param pNameSpaceName The namespace under which the type was registered. |
| 74 | + * @param pRecordName The name of the type to look up. |
| 75 | + * @return std::optional<Record> |
| 76 | + * Returns a valid Record if the type is found by name in the given namespace group; otherwise, std::nullopt. |
| 77 | + * |
| 78 | + * Retrieves the class or struct registered under the specified namespace. */ |
| 79 | + std::optional<Record> CxxMirror::getRecord(const std::string& pNameSpaceName, const std::string& pRecordName) const |
65 | 80 | { |
66 | 81 | const auto& nsRecordMap = getNamespaceRecordMap(); |
67 | | - const auto& itr = nsRecordMap.find(pNameSpace); |
| 82 | + const auto& itr = nsRecordMap.find(pNameSpaceName); |
68 | 83 | if (itr != nsRecordMap.end()) |
69 | 84 | { |
70 | 85 | const auto& recordMap = itr->second; |
71 | | - const auto& itr0 = recordMap.find(pRecord); |
| 86 | + const auto& itr0 = recordMap.find(pRecordName); |
72 | 87 | if (itr0 != recordMap.end()) { |
73 | 88 | return std::make_optional(itr0->second); |
74 | 89 | } |
75 | 90 | } |
76 | 91 | return std::nullopt; |
77 | 92 | } |
78 | 93 |
|
79 | | -/* @method: getFunction |
80 | | - @param: namespace name (std::string), non-mermber function name (std::string) |
81 | | - @return: std::optional<Function> |
82 | | - * retrieves the function (as 'Function' object) registered under the given namespace. |
83 | | - * if the function isn't found by the given name, std::nullopt is returned. |
84 | | -*/ std::optional<Function> CxxMirror::getFunction(const std::string& pNameSpace, const std::string& pFunction) const |
| 94 | + /** |
| 95 | + * @method getFunction |
| 96 | + * |
| 97 | + * @param pNameSpaceName The namespace under which the function was registered. |
| 98 | + * @param pFunctionName The name of the function to look up. |
| 99 | + * @return std::optional<Function> |
| 100 | + * Returns a valid Function if found by name in the given namespace group; otherwise, std::nullopt. |
| 101 | + * |
| 102 | + * Retrieves the non-member function registered under the specified namespace. */ |
| 103 | + std::optional<Function> CxxMirror::getFunction(const std::string& pNameSpaceName, const std::string& pFunctionName) const |
85 | 104 | { |
86 | 105 | const auto& nsFunctionMap = getNamespaceFunctionsMap(); |
87 | | - const auto& itr = nsFunctionMap.find(pNameSpace); |
| 106 | + const auto& itr = nsFunctionMap.find(pNameSpaceName); |
88 | 107 | if (itr != nsFunctionMap.end()) |
89 | 108 | { |
90 | 109 | const auto& functionMap = itr->second; |
91 | | - const auto& itr0 = functionMap.find(pFunction); |
| 110 | + const auto& itr0 = functionMap.find(pFunctionName); |
92 | 111 | if (itr0 != functionMap.end()) { |
93 | 112 | return std::make_optional(itr0->second); |
94 | 113 | } |
|
0 commit comments