// license:GPL-2.0+ // copyright-holders:Couriersud /* * poptions.cpp * */ #include "poptions.h" #include "pexception.h" #include "ptypes.h" namespace plib { /*************************************************************************** Options ***************************************************************************/ option_base::option_base(options &parent, const pstring &help) : m_help(help) { parent.register_option(this); } option::option(options &parent, const pstring &ashort, const pstring &along, const pstring &help, bool has_argument) : option_base(parent, help), m_short(ashort), m_long(along), m_has_argument(has_argument), m_specified(false) { } int option_str::parse(const pstring &argument) { m_val = argument; return 0; } int option_bool::parse(const pstring &argument) { unused_var(argument); m_val = true; return 0; } int option_vec::parse(const pstring &argument) { bool err = false; m_val.push_back(argument); return (err ? 1 : 0); } options::options() : m_other_args(nullptr) { } options::options(option **o) : m_other_args(nullptr) { int i=0; while (o[i] != nullptr) { register_option(o[i]); i++; } } void options::register_option(option_base *opt) { m_opts.push_back(opt); } void options::check_consistency() { for (auto &opt : m_opts) { auto *o = dynamic_cast