16 BadTaskConfig(
const std::string &msg =
"cannot read config file") :
19 const char *what()
const noexcept
override;
56 void add(
const std::string &key,
const std::string &val);
59 void set(
const std::string &key,
const std::string &val) {
60 the_config.erase(key);
65 void erase(
const std::string &key) {
66 the_config.erase(key);
70 void setDefault(
const std::string &key,
const std::string &val) {
71 if (the_config.find(key) == the_config.end())
76 void addLine(
const std::string &line);
79 std::multimap<std::string, std::string>::iterator
begin() {
80 return the_config.begin();
84 std::multimap<std::string, std::string>::iterator
end() {
85 return the_config.end();
89 std::multimap<std::string, std::string>::const_iterator
begin()
const {
90 return the_config.begin();
94 std::multimap<std::string, std::string>::const_iterator
end()
const {
95 return the_config.end();
105 const std::multimap<std::string, std::string> &
cfg()
const {
110 std::string
value(
const std::string &key)
const;
113 bool hasKey(
const std::string &key)
const {
114 return the_config.find(key) != the_config.end();
118 std::pair<std::multimap<std::string, std::string>::const_iterator,
119 std::multimap<std::string, std::string>::const_iterator>
120 range(
const std::string &key)
const {
121 return the_config.equal_range(key);
129 void openlog(std::ofstream &logger,
bool append =
false)
const;
136 std::set<std::string>
137 parseList(
const std::string &category =
"whitelist")
const;
144 std::map<std::string, std::string>
145 parseKeyVal(
const std::string &category =
"user")
const;
157 void _load(std::istream &cfg_stream);
158 std::multimap<std::string, std::string> the_config;
161 std::ostream &operator<<(std::ostream &out,
const TaskConfig &tc);
Exception thrown on syntax errors in task config.
Definition: taskconfig.h:14
Read configuration from file or string.
Definition: taskconfig.h:44
bool hasKey(const std::string &key) const
Return true if key exists, otherwise false:
Definition: taskconfig.h:113
void erase(const std::string &key)
Remove value(s) of a directive.
Definition: taskconfig.h:65
std::string value(const std::string &key) const
Return value of last occurence of key, or empty string.
Definition: taskconfig.cpp:31
std::multimap< std::string, std::string >::iterator begin()
Start iterator to loop over the config.
Definition: taskconfig.h:79
void setDefault(const std::string &key, const std::string &val)
Set value of a directive unless already set.
Definition: taskconfig.h:70
bool saveJsonToFile(const std::string &filename)
Store contents as a JSON object. Return false on failure.
Definition: taskconfig.cpp:153
std::multimap< std::string, std::string >::iterator end()
End iterator to loop over the config.
Definition: taskconfig.h:84
std::set< std::string > parseList(const std::string &category="whitelist") const
Split config value into non-blank strings.
Definition: taskconfig.cpp:99
std::pair< std::multimap< std::string, std::string >::const_iterator, std::multimap< std::string, std::string >::const_iterator > range(const std::string &key) const
Return a range of the key/value paris for the given key.
Definition: taskconfig.h:120
void add(const std::string &key, const std::string &val)
Add a directive to the config.
Definition: taskconfig.cpp:52
static TaskConfig load(const std::string &filename)
Read config from file.
Definition: taskconfig.cpp:26
std::multimap< std::string, std::string >::const_iterator end() const
End const iterator to loop over the config.
Definition: taskconfig.h:94
void addLine(const std::string &line)
Incrementally add to the config.
Definition: taskconfig.cpp:56
const std::multimap< std::string, std::string > & cfg() const
Return the parsed configuration.
Definition: taskconfig.h:105
TaskConfig()
Empty configuration.
Definition: taskconfig.h:47
void set(const std::string &key, const std::string &val)
Replace value(s) of a directive with a new one.
Definition: taskconfig.h:59
void parseArgs(int &argc, char **&argv)
Parse command line arguments starting with "--":
Definition: taskconfig.cpp:111
void workerAttributes(const std::set< std::string > &attrs)
Make a set of directives available to worker processes.
Definition: taskconfig.cpp:72
std::map< std::string, std::string > parseKeyVal(const std::string &category="user") const
Definition: taskconfig.cpp:138
static TaskConfig loadJsonFromFile(const std::string &filename)
Load key/value pairs from JSON object.
Definition: taskconfig.cpp:171
void openlog(std::ofstream &logger, bool append=false) const
Log to the file specified by the logfile directive.
Definition: taskconfig.cpp:39
std::multimap< std::string, std::string >::const_iterator begin() const
Start const iterator to loop over the config.
Definition: taskconfig.h:89