2121// SOFTWARE.
2222
2323#include < algorithm>
24+ #include < any>
2425#include < limits>
2526#include < map>
2627#include < string>
2728#include < tuple>
2829#include < typeindex>
29- #include < unordered_map>
30- #include < unordered_set>
3130
3231#include < daw/daw_bounded_hash_set.h>
32+ #include < daw/daw_ordered_map.h>
3333#include < daw/daw_string_view.h>
34-
35- #include " json_to_cpp.h"
3634#include < daw/json/daw_json_parser.h>
3735#include < daw/json/daw_json_parser_v2.h>
3836#include < daw/json/daw_json_value_t.h>
3937
38+ #include " json_to_cpp.h"
39+
4040namespace daw {
4141 namespace json_to_cpp {
4242 std::ostream &config_t ::header_file( ) {
@@ -57,99 +57,23 @@ namespace daw {
5757 namespace {
5858 // / Add a "json_" prefix to C++ keywords
5959 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
6063 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
15377
15478 if ( keywords.count ( {name.data ( ), name.size ( )} ) > 0 ) {
15579 std::string const prefix = " _json" ;
@@ -167,8 +91,8 @@ namespace daw {
16791
16892 std::string name ( ) const noexcept ;
16993 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 ( );
17296 bool &is_optional ( ) noexcept ;
17397 bool const &is_optional ( ) const noexcept ;
17498
@@ -224,7 +148,7 @@ namespace daw {
224148 }
225149
226150 struct type_info_t {
227- std::map <std::string, ti_value> children{};
151+ daw::ordered_map <std::string, ti_value> children{};
228152 bool is_optional = false ;
229153
230154 type_info_t ( ) = default ;
@@ -260,11 +184,12 @@ namespace daw {
260184 return value->type ( );
261185 }
262186
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 {
264189 return value->children ;
265190 }
266191
267- std::map <std::string, ti_value> &ti_value::children ( ) {
192+ daw::ordered_map <std::string, ti_value> &ti_value::children ( ) {
268193 return value->children ;
269194 }
270195
0 commit comments