File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 11
11
12
12
#include " options.h"
13
13
14
+ #include " json.h"
14
15
#include " string2int.h"
15
16
16
17
void optionst::set_option (const std::string &option,
@@ -86,3 +87,35 @@ const optionst::value_listt &optionst::get_list_option(
86
87
else
87
88
return it->second ;
88
89
}
90
+
91
+ // / Returns the options as JSON key value pairs
92
+ json_objectt optionst::to_json () const
93
+ {
94
+ json_objectt json_options;
95
+ for (const auto &option_pair : option_map)
96
+ {
97
+ json_arrayt &values = json_options[option_pair.first ].make_array ();
98
+ for (const auto &value : option_pair.second )
99
+ values.push_back (json_stringt (value));
100
+ }
101
+ return json_options;
102
+ }
103
+
104
+ // / Outputs the options to `out`
105
+ void optionst::output (std::ostream &out) const
106
+ {
107
+ for (const auto &option_pair : option_map)
108
+ {
109
+ out << option_pair.first << " : " ;
110
+ bool first = true ;
111
+ for (const auto &value : option_pair.second )
112
+ {
113
+ if (first)
114
+ first = false ;
115
+ else
116
+ out << " , " ;
117
+ out << ' "' << value << ' "' ;
118
+ }
119
+ out << " \n " ;
120
+ }
121
+ }
Original file line number Diff line number Diff line change 16
16
#include < map>
17
17
#include < list>
18
18
19
+ class json_objectt ;
20
+
19
21
class optionst
20
22
{
21
23
public:
@@ -55,6 +57,9 @@ class optionst
55
57
return *this ;
56
58
}
57
59
60
+ json_objectt to_json () const ;
61
+ void output (std::ostream &out) const ;
62
+
58
63
protected:
59
64
option_mapt option_map;
60
65
const value_listt empty_list;
You can’t perform that action at this time.
0 commit comments