12#include <boost/program_options.hpp>
14#include "sparta/sparta.hpp"
16namespace po = boost::program_options;
24template <
typename ArgT>
36 typedef po::typed_value<ArgT>
base_t;
42 po::typed_value<ArgT>(val),
52 po::typed_value<ArgT>(val),
63 virtual std::string
name()
const override {
return my_name_; }
71 named_value_type* max(
unsigned max)
77 named_value_type* multitoken()
86 virtual unsigned min_tokens()
const override {
return min_; }
91 virtual unsigned max_tokens()
const override {
return max_; }
97 virtual void xparse(boost::any& value_store,
98 const std::vector<std::basic_string<char>>& new_tokens)
const override;
105 const std::vector<std::basic_string<char>>& new_tokens)
const {
106 po::typed_value<ArgT>::xparse(value_store, new_tokens);
113template <
typename ArgT>
124 boost::any& value_store,
125 const std::vector<std::basic_string<char>>& new_tokens) {
132 const std::vector<std::basic_string<char>>& new_tokens)
const {
145 boost::any& value_store,
146 const std::vector<std::basic_string<char>>& new_tokens) {
149 uint64_t val = utils::smartLexicalCast<uint64_t>(new_tokens.at(0), end_pos);
162 boost::any& value_store,
163 const std::vector<std::basic_string<char>>& new_tokens) {
166 int64_t val = utils::smartLexicalCast<int64_t>(new_tokens.at(0), end_pos);
179 boost::any& value_store,
180 const std::vector<std::basic_string<char>>& new_tokens) {
183 uint32_t val = utils::smartLexicalCast<uint32_t>(new_tokens.at(0), end_pos);
196 boost::any& value_store,
197 const std::vector<std::basic_string<char>>& new_tokens) {
200 int32_t val = utils::smartLexicalCast<int32_t>(new_tokens.at(0), end_pos);
213 boost::any& value_store,
214 const std::vector<std::basic_string<char>>& new_tokens) {
217 uint16_t val = utils::smartLexicalCast<uint16_t>(new_tokens.at(0), end_pos);
230 boost::any& value_store,
231 const std::vector<std::basic_string<char>>& new_tokens) {
234 int16_t val = utils::smartLexicalCast<int16_t>(new_tokens.at(0), end_pos);
247 boost::any& value_store,
248 const std::vector<std::basic_string<char>>& new_tokens) {
251 uint8_t val = utils::smartLexicalCast<uint8_t>(new_tokens.at(0), end_pos);
264 boost::any& value_store,
265 const std::vector<std::basic_string<char>>& new_tokens) {
268 int8_t val = utils::smartLexicalCast<int8_t>(new_tokens.at(0), end_pos);
279template <
typename ArgT>
284template <
typename ArgT>
285inline named_value_type<ArgT>*
named_value(std::string
const& name,
unsigned min,
unsigned max, ArgT* val=
nullptr) {
286 return new named_value_type<ArgT>(name, val, min, max);
297 typedef uint32_t level_t;
299 static const level_t VERBOSE = 0;
300 static const level_t BRIEF = 1;
317 template <
typename ...Args>
319 const char* verbose_desc,
322 opts_.add_option_with_desc_level_(0, name, verbose_desc, args...);
331 template <
typename ...Args>
333 const boost::program_options::value_semantic* s,
334 const char* verbose_desc,
337 opts_.add_option_with_desc_level_(0, name, s, verbose_desc, args...);
371 descs_.emplace_back(
new po::options_description(name_, w, hw));
372 descs_.emplace_back(
new po::options_description(name_, w, hw));
387 if(level < descs_.size()){
388 return *descs_.at(level);
391 return *descs_.at(descs_.size() - 1);
402 return *descs_.at(level);
409 return *descs_.at(VERBOSE);
417 return descs_.size();
424 template <
typename ...Args>
426 const char* verbose_desc,
429 add_option_with_desc_level_(0, name, verbose_desc, args...);
460 template <
typename ...Args>
462 const boost::program_options::value_semantic* s,
463 const char* verbose_desc,
466 add_option_with_desc_level_(0, name, s, verbose_desc, args...);
494 void add_option_with_desc_level_(
size_t level,
505 template <
typename ...Args>
506 void add_option_with_desc_level_(
size_t level,
509 const Args& ...args) {
510 while(descs_.size() <= level){
511 descs_.emplace_back(
new po::options_description(name_));
514 descs_.at(level)->add_options()
518 add_option_with_desc_level_(level+1, name, args...);
539 template <
typename ...Args>
540 void add_option_with_desc_level_(
size_t level,
542 const boost::program_options::value_semantic* s,
544 const Args& ...args) {
545 while(descs_.size() <= level){
546 descs_.emplace_back(
new po::options_description(name_));
549 descs_.at(level)->add_options()
558 add_option_with_desc_level_(level+1, name, args...);
570 const std::string name_;
575 std::vector<std::unique_ptr<po::options_description>> descs_;
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Helper class for chained calls to add_options.
OptAdder operator()(const char *name, const boost::program_options::value_semantic *s, const char *verbose_desc, const Args &...args)
Acts like calling MultiDetailOptions::add_options on the object that created this OptAdder.
OptAdder & operator()(const char *name, const char *verbose_desc, const Args &...args)
Acts like calling MultiDetailOptions::add_options on the object that created this OptAdder.
Class for containing multiple levels of boost program options.
friend class OptAdded
Allow access to private adding methods.
const po::options_description & getVerboseOptions() const noexcept
Gets the description object for the VERBOSE level.
const po::options_description & getOptionsLevel(level_t level) const
Gets the description object for a particular level. Only VERBOSE and BRIEF levels are guaranteed to e...
MultiDetailOptions(const MultiDetailOptions &)=delete
Not copy-constructable.
size_t getNumLevels() const
Returns the number of levels that have an options description which can be retrieved through getLevel...
MultiDetailOptions(const std::string &name, uint32_t w=80, uint32_t hw=40)
Construction with group nam.
MultiDetailOptions & operator=(const MultiDetailOptions &)=delete
Not assignable.
OptAdder & add_options(const char *name, const char *verbose_desc, const Args &...args)
Add an option with NO value semantic and any number of descriptions. See the other add_options signat...
OptAdder & add_options()
Empty add_options shell allowing the start of chained calls (exists solely to mimic boost's syntax)
const po::options_description & getOptionsLevelUpTo(level_t level) const
Gets the description object for a particular level if that level exists. If that level does not exist...
OptAdder & add_options(const char *name, const boost::program_options::value_semantic *s, const char *verbose_desc, const Args &...args)
Add an option with a value semantic and any number of descriptions.
MultiDetailOptions()=delete
Not default-constructable.
Parser helper for named_value_type.
static void parse_(const named_value_type< ArgT > &nvt, boost::any &value_store, const std::vector< std::basic_string< char > > &new_tokens)
Default implementation of parse_ - overridden in class template specializations.
Helper class for populating boost program options.
virtual std::string name() const override
boost semantic for getting name of this option
named_value_type(std::string const &name, ArgT *val)
Constructor.
named_value_type(std::string const &name, ArgT *val, unsigned min, unsigned max)
Constructor with min and max extents.
po::typed_value< ArgT > base_t
Type of base class.
virtual void xparse(boost::any &value_store, const std::vector< std::basic_string< char > > &new_tokens) const override
Override parser.
virtual unsigned max_tokens() const override
boost semantic for specifying max tokens
void xparse_base_(boost::any &value_store, const std::vector< std::basic_string< char > > &new_tokens) const
Call xparse on base class. This is available to named_value_parser for invoking the default parser wh...
virtual unsigned min_tokens() const override
boost semantic for specifying min tokens
named_value_type< ArgT > * named_value(std::string const &name, ArgT *val=nullptr)
Helper function for generating new named_value_type structs in the boost style.
Macros for handling exponential backoff.