forked from heavywatal/cxxwtl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetopt.hpp
More file actions
64 lines (58 loc) · 1.95 KB
/
getopt.hpp
File metadata and controls
64 lines (58 loc) · 1.95 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include <ostream>
#include <sstream>
#include <boost/program_options.hpp>
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////
namespace wtl {
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////
inline std::ostream&
ost_any(std::ostream& ost, const boost::any& value) {
if (value.type() == typeid(int)) {
ost << boost::any_cast<int>(value);
}
else if (value.type() == typeid(unsigned int)) {
ost << boost::any_cast<unsigned int>(value);
}
else if (value.type() == typeid(ptrdiff_t)) {
ost << boost::any_cast<ptrdiff_t>(value);
}
else if (value.type() == typeid(size_t)) {
ost << boost::any_cast<size_t>(value);
}
else if (value.type() == typeid(double)) {
ost << boost::any_cast<double>(value);
}
else if (value.type() == typeid(bool)) {
ost << boost::any_cast<bool>(value);
}
else if (value.type() == typeid(std::string)) {
ost << boost::any_cast<std::string>(value);
}
else {
ost << boost::any_cast<unsigned long>(value);
}
return ost;
}
inline std::ostream&
flags_into_stream(std::ostream& ost,
const boost::program_options::variables_map& vm) {
for (const auto& pair: vm) {
boost::any value = pair.second.value();
if (value.type() == typeid(std::string)
&& boost::any_cast<std::string>(value).empty()) {
ost << '#';
}
ost_any(ost << pair.first << " = ", value) << "\n";
}
return ost;
}
inline std::string
flags_into_string(const boost::program_options::variables_map& vm) {
std::ostringstream oss;
oss.precision(std::numeric_limits<double>::max_digits10);
flags_into_stream(oss, vm);
return oss.str();
}
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////
} // namespace wtl
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////