Skip to content

Commit 4a1e64c

Browse files
Functions for outputting options
This can be used to output the options set at the beginning of an analysis in order to understand the settings.
1 parent f1489fd commit 4a1e64c

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/util/options.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "options.h"
1313

14+
#include "json.h"
1415
#include "string2int.h"
16+
#include "xml.h"
1517

1618
void optionst::set_option(const std::string &option,
1719
const std::string &value)
@@ -86,3 +88,52 @@ const optionst::value_listt &optionst::get_list_option(
8688
else
8789
return it->second;
8890
}
91+
92+
/// Returns the options as JSON key value pairs
93+
json_objectt optionst::to_json() const
94+
{
95+
json_objectt json_options;
96+
for(const auto &option_pair : option_map)
97+
{
98+
json_arrayt &values = json_options[option_pair.first].make_array();
99+
for(const auto &value : option_pair.second)
100+
values.push_back(json_stringt(value));
101+
}
102+
return json_options;
103+
}
104+
105+
/// Returns the options in XML format
106+
xmlt optionst::to_xml() const
107+
{
108+
xmlt xml_options("options");
109+
for(const auto &option_pair : option_map)
110+
{
111+
xmlt &xml_option = xml_options.new_element("option");
112+
xml_option.set_attribute("name", option_pair.first);
113+
for(const auto &value : option_pair.second)
114+
{
115+
xmlt &xml_value = xml_option.new_element("value");
116+
xml_value.data = value;
117+
}
118+
}
119+
return xml_options;
120+
}
121+
122+
/// Outputs the options to `out`
123+
void optionst::output(std::ostream &out) const
124+
{
125+
for(const auto &option_pair : option_map)
126+
{
127+
out << option_pair.first << ": ";
128+
bool first = true;
129+
for(const auto &value : option_pair.second)
130+
{
131+
if(first)
132+
first = false;
133+
else
134+
out << ", ";
135+
out << '"' << value << '"';
136+
}
137+
out << "\n";
138+
}
139+
}

src/util/options.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Author: Daniel Kroening, [email protected]
1616
#include <map>
1717
#include <list>
1818

19+
class json_objectt;
20+
class xmlt;
21+
1922
class optionst
2023
{
2124
public:
@@ -55,6 +58,10 @@ class optionst
5558
return *this;
5659
}
5760

61+
json_objectt to_json() const;
62+
xmlt to_xml() const;
63+
void output(std::ostream &out) const;
64+
5865
protected:
5966
option_mapt option_map;
6067
const value_listt empty_list;

0 commit comments

Comments
 (0)