-
Notifications
You must be signed in to change notification settings - Fork 0
/
optionmanager.cpp
52 lines (39 loc) · 1.02 KB
/
optionmanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "optionmanager.h"
#include <stdexcept>
OptionManager::OptionManager()
{
}
OptionManager::OptionManager(OptionReader* reader)
{
addReader(reader);
}
void OptionManager::addReader(OptionReader* reader)
{
m_readers.push_back(reader);
}
OptionManager& OptionManager::addOption(Option* option)
{
m_options.push_back(option);
return *this;
}
void OptionManager::readOptions()
{
std::map<std::string, std::string> values;
for (auto& reader : m_readers)
reader.readOptions(values);
/*typedef std::pair<std::string, std::string> string_pair;
foreach (const string_pair& pair, values)
{
std::cout.width(15);
std::cout << pair.first << " : " << pair.second << std::endl;
}*/
auto vend = values.end();
for (auto& option : m_options)
{
auto vit = values.find(option.name());
if (vit != vend)
option << vit->second;
else if (option.mandatory())
throw std::runtime_error("Option not found : " +option.name());
}
}