Skip to content

Commit 9caa6b9

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 9caa6b9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/util/options.cpp

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

1212
#include "options.h"
1313

14+
#include "json.h"
1415
#include "string2int.h"
1516

1617
void optionst::set_option(const std::string &option,
@@ -86,3 +87,35 @@ const optionst::value_listt &optionst::get_list_option(
8687
else
8788
return it->second;
8889
}
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+
}

src/util/options.h

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

19+
class json_objectt;
20+
1921
class optionst
2022
{
2123
public:
@@ -55,6 +57,9 @@ class optionst
5557
return *this;
5658
}
5759

60+
json_objectt to_json() const;
61+
void output(std::ostream &out) const;
62+
5863
protected:
5964
option_mapt option_map;
6065
const value_listt empty_list;

0 commit comments

Comments
 (0)