4
4
#include < algorithm>
5
5
#include < atomic>
6
6
#include < functional>
7
- #include < limits >
7
+ #include < iostream >
8
8
#include < map>
9
9
#include < optional>
10
10
#include < queue>
@@ -28,7 +28,7 @@ class AutoWired {
28
28
bool need_init{false };
29
29
bool need_de_init{false };
30
30
bool need_auto_wired{false };
31
- int32_t order{std::numeric_limits< int32_t >:: max () };
31
+ int32_t order{0 };
32
32
33
33
public:
34
34
static auto WithCustomName (const std::string& custom_name) {
@@ -85,8 +85,7 @@ class AutoWired {
85
85
}
86
86
};
87
87
88
- inline const static RegisterOptions default_register_options{
89
- " " , false , false , false , std::numeric_limits<int32_t >::max ()};
88
+ inline const static RegisterOptions default_register_options{" " , false , false , false , 0 };
90
89
using RegisterOptionsSetFunction = std::function<void (RegisterOptions&)>;
91
90
92
91
public:
@@ -120,7 +119,7 @@ class AutoWired {
120
119
121
120
template <typename T>
122
121
void Wired (T** t_ptr, std::string_view custom_name = " " ) {
123
- auto name = Utility::GetClassTypeName <T>(custom_name);
122
+ auto name = Utility::GetPrettyClassTypeName <T>(custom_name);
124
123
125
124
// if target class not present, core dump will be.
126
125
*t_ptr = static_cast <T*>(class_.at (name).instance );
@@ -132,7 +131,7 @@ class AutoWired {
132
131
133
132
template <typename T>
134
133
T* GetClass (std::string_view custom_name = " " ) {
135
- auto name = Utility::GetClassTypeName <T>(custom_name);
134
+ auto name = Utility::GetPrettyClassTypeName <T>(custom_name);
136
135
137
136
if (!class_.count (name)) {
138
137
if constexpr (internal::has_get_auto_wired_register_options_v<T>) {
@@ -147,15 +146,15 @@ class AutoWired {
147
146
148
147
template <typename T>
149
148
T* GetClassMust (std::string_view custom_name = " " ) {
150
- auto name = Utility::GetClassTypeName <T>(custom_name);
149
+ auto name = Utility::GetPrettyClassTypeName <T>(custom_name);
151
150
152
151
// if target class not present, core dump will be.
153
152
return static_cast <T*>(class_.at (name).instance );
154
153
}
155
154
156
155
template <typename T>
157
156
T* GetClassOrNullPtr (std::string_view custom_name = " " ) {
158
- auto name = Utility::GetClassTypeName <T>(custom_name);
157
+ auto name = Utility::GetPrettyClassTypeName <T>(custom_name);
159
158
160
159
if (class_.count (name) == 0 ) {
161
160
return nullptr ;
@@ -178,9 +177,10 @@ class AutoWired {
178
177
179
178
template <typename Anc, typename Des>
180
179
void AddClassRelations (const std::string& anc_custom_name = " " , const std::string& des_custom_name = " " ) {
181
- auto left_name = Utility::GetClassTypeName<Anc>(anc_custom_name);
182
- auto right_name = Utility::GetClassTypeName<Des>(des_custom_name);
183
- AddClassRelations (left_name, right_name);
180
+ auto anc_name = Utility::GetPrettyClassTypeName<Anc>(anc_custom_name);
181
+ auto des_name = Utility::GetPrettyClassTypeName<Des>(des_custom_name);
182
+
183
+ AddClassRelations (anc_name, des_name);
184
184
}
185
185
186
186
// Ancestors -> Descendants
@@ -189,17 +189,17 @@ class AutoWired {
189
189
// This is most likely the case where `des` depends on some `anc`,
190
190
// but `des` does not have a successor dependency and is padded
191
191
// directly into the `AutoWired` instance construct
192
- if (class_.count (anc) == 0 || class_.count (des) == 0 ) {
193
- return ;
194
- }
192
+ // if (class_.count(anc) == 0 || class_.count(des) == 0) {
193
+ // return;
194
+ // }
195
195
196
196
graph_[anc].push_back (des);
197
197
++degree_[des];
198
198
}
199
199
200
200
template <typename Pre, typename After>
201
201
AutoWired& UseMocker (After* a, const std::string& custom_name = " " ) {
202
- auto name = Utility::GetClassTypeName <Pre>(custom_name);
202
+ auto name = Utility::GetPrettyClassTypeName <Pre>(custom_name);
203
203
registerImpl<Pre>(dynamic_cast <Pre*>(a));
204
204
return *this ;
205
205
}
@@ -232,7 +232,7 @@ class AutoWired {
232
232
233
233
auto [has_loop, topological_order] = GetTopologicalOrder ();
234
234
if (has_loop) {
235
- throw std::runtime_error (" Dependencies has loop, please initialize manually" );
235
+ throw std::runtime_error (" Dependencies has loop, please init manually" );
236
236
}
237
237
238
238
for (auto & name : topological_order) {
@@ -304,7 +304,7 @@ class AutoWired {
304
304
private:
305
305
template <typename T>
306
306
void registerImpl (T* t_ptr, RegisterOptions options = default_register_options) {
307
- auto name = Utility::GetClassTypeName <T>(options.custom_name );
307
+ auto name = Utility::GetPrettyClassTypeName <T>(options.custom_name );
308
308
if (class_.count (name)) {
309
309
return ;
310
310
}
0 commit comments