1 |
nikolas |
1.1 |
#include "Options.h" |
2 |
|
|
|
3 |
|
|
namespace FCUtils { |
4 |
|
|
|
5 |
|
|
Options * Options::instance_=0; |
6 |
|
|
|
7 |
|
|
Options::Options() { |
8 |
|
|
// Set the error Option waiting for exceptions inplementation |
9 |
|
|
}; |
10 |
|
|
|
11 |
|
|
Options * Options::Get(){ |
12 |
|
|
if(instance_==0) instance_=new Options(); |
13 |
|
|
return instance_; |
14 |
|
|
}; |
15 |
|
|
|
16 |
|
|
bool Options::IsOptionDef(string const &name) { |
17 |
|
|
return (GetOption(name).name!="error"); |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
// Option const & Options::GetOption(string const &name){ |
21 |
|
|
// OptMap::const_iterator it= options_.find(ToLower(name)); |
22 |
|
|
Option & Options::GetOption(string const &name){ |
23 |
|
|
OptMap::iterator it= options_.find(ToLower(name)); |
24 |
|
|
if(it== options_.end()) { |
25 |
|
|
cout << endl << |
26 |
|
|
" --->>> Error in Options::GetOption , no option : " |
27 |
|
|
+name+" found !!!! " << endl; |
28 |
|
|
Help(); |
29 |
|
|
exit(-1); |
30 |
|
|
} |
31 |
|
|
return it->second; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
bool Options::UpdateOption( const string &name, const string &val){ |
35 |
|
|
switch(IsOptionDef(name)){ |
36 |
|
|
case true: |
37 |
|
|
options_[ToLower(name)].val=val; |
38 |
|
|
return true; |
39 |
|
|
default: |
40 |
|
|
return false; |
41 |
|
|
} |
42 |
|
|
return false; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
void Options::Help() const { |
46 |
|
|
cout << endl << " Usage : " << endl; |
47 |
|
|
for( OptMap::const_iterator i=options_.begin(); i!=options_.end(); ++i) |
48 |
|
|
i->second.Help(); |
49 |
|
|
cout << endl << endl; |
50 |
|
|
} |
51 |
|
|
void Options::Print() const { |
52 |
|
|
for( OptMap::const_iterator i=options_.begin(); i!=options_.end(); ++i) |
53 |
|
|
i->second.Print(); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
}; // namespace FCUtils |