8 #include <ail/file.hpp>
9 #include <ail/string.hpp>
10 #include <ail/exception.hpp>
20 configuration(std::string
const & file_name
);
22 bool load(std::string
const & new_file_name
);
24 std::string
string(std::string
const & variable_name
);
25 std::string
string(std::string
const & variable_name
, std::string
const & default_value
);
27 template <typename number_type
>
28 bool read_number(std::string
const & variable_name
, number_type
& output
)
30 std::map
<std::string
, std::string
>::iterator search
= values
.find(variable_name
);
31 if(search
== values
.end())
38 output
= ail::string_to_number
<number_type
>(search
->second
);
40 catch(std::exception
const &)
42 std::cout
<< "Unable to find string value \"" << variable_name
<< "\" in \"" << file_name
<< "\"" << std::endl
;
43 throw exception("Failed to parse numeric value for a variable");
49 template <typename number_type
>
50 number_type
number(std::string
const & variable_name
)
53 bool success
= read_number
<number_type
>(variable_name
, output
);
56 std::cout
<< "Unable to find string value \"" << variable_name
<< "\" in \"" << file_name
<< "\"" << std::endl
;
57 throw exception("Missing value for a required variable");
62 template <typename number_type
>
63 number_type
number(std::string
const & variable_name
, number_type default_value
)
70 success
= read_number
<number_type
>(variable_name
, output
);
72 catch(std::exception
const &)
87 bool read_string(std::string
const & variable_name
, std::string
& output
);
89 std::string file_name
;
90 std::map
<std::string
, std::string
> values
;