Aktualizr
C++ SOTA Client
|
7 #ifndef PROGRAM_OPTIONS_ACCUMULATOR_HPP
8 #define PROGRAM_OPTIONS_ACCUMULATOR_HPP
14 #include <boost/any.hpp>
15 #include <boost/program_options/value_semantic.hpp>
21 explicit accumulator_type(T* store) : _store(store), _interval(1), _default(0) {}
44 virtual std::string name()
const {
return std::string(); }
48 virtual unsigned max_tokens()
const {
return 0; }
50 virtual bool adjacent_tokens_only()
const {
return false; }
61 virtual void parse(boost::any& value_store,
const std::vector<std::string>&,
bool )
const {
62 if (value_store.empty()) {
65 boost::any_cast<T&>(value_store) += _interval;
70 value_store = _default;
75 virtual void notify(
const boost::any& value_store)
const {
76 const auto* val = boost::any_cast<T>(&value_store);
89 std::function<void(
const T&)> _notifier;
accumulator_type * notifier(std::function< void(const T &)> f)
Set the notifier function.
virtual bool is_required() const
Requiring one or more appearances is unlikely.
virtual bool is_composing() const
Accumulating from different sources is silly.
virtual void parse(boost::any &value_store, const std::vector< std::string > &, bool) const
Every appearance of the option simply increments the value.
An accumulating option value to handle multiple incrementing options.
virtual void notify(const boost::any &value_store) const
Notify the user function with the value of the value store.
virtual bool apply_default(boost::any &value_store) const
If the option doesn't appear, this is the default value.
accumulator_type * implicit_value(const T &t)
Set the implicit value for this option.
virtual unsigned min_tokens() const
There are no tokens for an accumulator_type.
accumulator_type * default_value(const T &t)
Set the default value for this option.