2 #include <boost/program_options.hpp>
9 virtual bool check(
const boost::program_options::variables_map &vm,
10 bool exit_if_fail)
const = 0;
11 virtual std::string to_string()
const = 0;
15 template <
typename T>
explicit opt(T &&_s) : m_value(_s) {}
17 virtual auto check(
const boost::program_options::variables_map &vm,
18 bool exit_if_fail)
const -> bool;
19 virtual std::string to_string()
const {
return m_value; }
27 and_opt(
const O1 &o1,
const O2 &o2) : m_o1(o1), m_o2(o2) {}
28 virtual bool check(
const boost::program_options::variables_map &vm,
29 bool exit_if_fail)
const {
30 bool v1 = m_o1.check(vm, exit_if_fail);
31 bool v2 = m_o2.check(vm, exit_if_fail);
32 if (exit_if_fail && (!v1 || !v2)) {
33 std::cerr <<
"missing '" << m_o1.to_string() <<
"' and '"
34 << m_o2.to_string() <<
"'" << std::endl;
40 virtual std::string to_string()
const {
41 return m_o1.to_string() +
" && " + m_o2.to_string();
50 or_opt(
const O1 &o1,
const O2 &o2) : m_o1(o1), m_o2(o2) {}
51 virtual bool check(
const boost::program_options::variables_map &vm,
52 bool exit_if_fail)
const {
53 bool v1 = m_o1.check(vm,
false);
54 bool v2 = m_o2.check(vm,
false);
55 if (exit_if_fail && !v1 && !v2) {
56 std::cerr <<
"missing '" << m_o1.to_string() <<
"' or '"
57 << m_o2.to_string() <<
"'." << std::endl;
63 virtual std::string to_string()
const {
64 return m_o1.to_string() +
" || " + m_o2.to_string();
77 inline explicit po(
const boost::program_options::variables_map &vm)
80 template <
typename OT>
81 auto require(
const OT &o) ->
typename std::enable_if<
83 typename std::remove_reference<OT>::type>::value,
87 template <
typename OT>
88 auto require(
const OT &o) ->
typename std::enable_if<
90 typename std::remove_reference<OT>::type>::value,
96 const boost::program_options::variables_map &m_vm;
102 template <
typename O1,
typename O2>
103 auto operator&&(O1 &&lhs, O2 &&rhs) ->
typename std::enable_if<
105 typename std::remove_reference<O1>::type>::value &&
107 typename std::remove_reference<O2>::type>::value,
112 template <
typename O1,
typename O2>
113 auto operator||(
const O1 &lhs,
const O2 &rhs) ->
typename std::enable_if<
114 std::is_base_of<ypc::internal::opt_base, O1>::value &&
115 std::is_base_of<ypc::internal::opt_base, O2>::value,