21
21
// SOFTWARE.
22
22
23
23
#include < algorithm>
24
+ #include < any>
24
25
#include < limits>
25
26
#include < map>
26
27
#include < string>
27
28
#include < tuple>
28
29
#include < typeindex>
29
- #include < unordered_map>
30
- #include < unordered_set>
31
30
32
31
#include < daw/daw_bounded_hash_set.h>
32
+ #include < daw/daw_ordered_map.h>
33
33
#include < daw/daw_string_view.h>
34
-
35
- #include " json_to_cpp.h"
36
34
#include < daw/json/daw_json_parser.h>
37
35
#include < daw/json/daw_json_parser_v2.h>
38
36
#include < daw/json/daw_json_value_t.h>
39
37
38
+ #include " json_to_cpp.h"
39
+
40
40
namespace daw {
41
41
namespace json_to_cpp {
42
42
std::ostream &config_t ::header_file( ) {
@@ -57,99 +57,23 @@ namespace daw {
57
57
namespace {
58
58
// / Add a "json_" prefix to C++ keywords
59
59
std::string replace_keywords ( std::string name ) {
60
+ // These identifiers cannot be used in c++, we will prefix them to keep
61
+ // them from colliding with keywords
62
+ // clang-format off
60
63
static constexpr auto keywords =
61
- daw::make_bounded_hash_set<daw::string_view>( {" alignas" ,
62
- " alignof" ,
63
- " and" ,
64
- " and_eq" ,
65
- " asm" ,
66
- " atomic_cancel" ,
67
- " atomic_commit" ,
68
- " atomic_noexcept" ,
69
- " auto" ,
70
- " bitand" ,
71
- " bitor" ,
72
- " bool" ,
73
- " break" ,
74
- " case" ,
75
- " catch" ,
76
- " char" ,
77
- " char16_t" ,
78
- " char32_t" ,
79
- " class" ,
80
- " compl" ,
81
- " concept" ,
82
- " const" ,
83
- " constexpr" ,
84
- " const_cast" ,
85
- " continue" ,
86
- " decltype" ,
87
- " default" ,
88
- " delete" ,
89
- " do" ,
90
- " double" ,
91
- " dynamic_cast" ,
92
- " else" ,
93
- " enum" ,
94
- " explicit" ,
95
- " export" ,
96
- " extern" ,
97
- " false" ,
98
- " float" ,
99
- " for" ,
100
- " friend" ,
101
- " goto" ,
102
- " if" ,
103
- " import" ,
104
- " inline" ,
105
- " int" ,
106
- " long" ,
107
- " module" ,
108
- " mutable" ,
109
- " namespace" ,
110
- " new" ,
111
- " noexcept" ,
112
- " not" ,
113
- " not_eq" ,
114
- " nullptr" ,
115
- " operator" ,
116
- " or" ,
117
- " or_eq" ,
118
- " private" ,
119
- " protected" ,
120
- " public" ,
121
- " register" ,
122
- " reinterpret_cast" ,
123
- " requires" ,
124
- " return" ,
125
- " short" ,
126
- " signed" ,
127
- " sizeof" ,
128
- " static" ,
129
- " static_assert" ,
130
- " static_cast" ,
131
- " struct" ,
132
- " switch" ,
133
- " synchronized" ,
134
- " template" ,
135
- " this" ,
136
- " thread_local" ,
137
- " throw" ,
138
- " true" ,
139
- " try" ,
140
- " typedef" ,
141
- " typeid" ,
142
- " typename" ,
143
- " union" ,
144
- " unsigned" ,
145
- " using" ,
146
- " virtual" ,
147
- " void" ,
148
- " volatile" ,
149
- " wchar_t" ,
150
- " while" ,
151
- " xor" ,
152
- " xor_eq" } );
64
+ daw::make_bounded_hash_set<daw::string_view>( {
65
+ " alignas" , " alignof" , " and" , " and_eq" , " asm" , " atomic_cancel" , " atomic_commit" ,
66
+ " atomic_noexcept" , " auto" , " bitand" , " bitor" , " bool" , " break" , " case" , " catch" ,
67
+ " char" , " char16_t" , " char32_t" , " class" , " compl" , " concept" , " const" , " constexpr" ,
68
+ " const_cast" , " continue" , " decltype" , " default" , " delete" , " do" , " double" , " dynamic_cast" ,
69
+ " else" , " enum" , " explicit" , " export" , " extern" , " false" , " float" , " for" , " friend" ,
70
+ " goto" , " if" , " import" , " inline" , " int" , " long" , " module" , " mutable" , " namespace" ,
71
+ " new" , " noexcept" , " not" , " not_eq" , " nullptr" , " operator" , " or" , " or_eq" , " private" ,
72
+ " protected" , " public" , " register" , " reinterpret_cast" , " requires" , " return" , " short" ,
73
+ " signed" , " sizeof" , " static" , " static_assert" , " static_cast" , " struct" , " switch" , " synchronized" ,
74
+ " template" , " this" , " thread_local" , " throw" , " true" , " try" , " typedef" , " typeid" , " typename" ,
75
+ " union" , " unsigned" , " using" , " virtual" , " void" , " volatile" , " wchar_t" , " while" , " xor" , " xor_eq" } );
76
+ // clang-format on
153
77
154
78
if ( keywords.count ( {name.data ( ), name.size ( )} ) > 0 ) {
155
79
std::string const prefix = " _json" ;
@@ -167,8 +91,8 @@ namespace daw {
167
91
168
92
std::string name ( ) const noexcept ;
169
93
std::string json_name ( std::string member_name ) const noexcept ;
170
- std::map <std::string, ti_value> const &children ( ) const ;
171
- std::map <std::string, ti_value> &children ( );
94
+ daw::ordered_map <std::string, ti_value> const &children ( ) const ;
95
+ daw::ordered_map <std::string, ti_value> &children ( );
172
96
bool &is_optional ( ) noexcept ;
173
97
bool const &is_optional ( ) const noexcept ;
174
98
@@ -224,7 +148,7 @@ namespace daw {
224
148
}
225
149
226
150
struct type_info_t {
227
- std::map <std::string, ti_value> children{};
151
+ daw::ordered_map <std::string, ti_value> children{};
228
152
bool is_optional = false ;
229
153
230
154
type_info_t ( ) = default ;
@@ -260,11 +184,12 @@ namespace daw {
260
184
return value->type ( );
261
185
}
262
186
263
- std::map<std::string, ti_value> const &ti_value::children ( ) const {
187
+ daw::ordered_map<std::string, ti_value> const &
188
+ ti_value::children ( ) const {
264
189
return value->children ;
265
190
}
266
191
267
- std::map <std::string, ti_value> &ti_value::children ( ) {
192
+ daw::ordered_map <std::string, ti_value> &ti_value::children ( ) {
268
193
return value->children ;
269
194
}
270
195
0 commit comments