22 #ifndef PROGRAM_OPTIONS_TYPED_VALUE_H_INCLUDED
23 #define PROGRAM_OPTIONS_TYPED_VALUE_H_INCLUDED
25 #pragma warning (disable : 4786)
26 #pragma warning (disable : 4503)
27 #pragma warning (disable : 4200)
34 namespace ProgramOptions {
namespace detail {
36 struct Parser {
typedef bool (*
type)(
const std::string&, T&); };
43 typedef std::vector<std::pair<const char*, int> >
base_type;
44 using base_type::size;
45 using base_type::empty;
46 void add(
const char* strVal,
int eVal){ push_back(value_type(strVal, eVal)); }
47 const int*
get(
const char* strVal)
const {
48 for (const_iterator it =
begin(),
end = this->
end(); it !=
end; ++it) {
49 if (strcasecmp(strVal, it->first) == 0) {
return &it->second; }
64 static bool parse(
const std::string& value, U&
out){
66 if (
const int*
x = m.
get(value.c_str())) { out =
static_cast<U
>(*x);
return true; }
86 bool doParse(
const std::string&,
const std::string& value) {
98 static T*
create() {
return new T(); }
116 bool doParse(
const std::string& name,
const std::string& value) {
119 std::auto_ptr<T> holder;
124 holder.reset(
value_.create());
127 ret = this->
parser_(value, *pv);
151 bool doParse(
const std::string& name,
const std::string& value) {
160 #define LIT_TO_STRING_X(lit) #lit
161 #define LIT_TO_STRING(lit) LIT_TO_STRING_X(lit)
166 if (v.empty()) {
return (b =
true); }
171 return store_true(v, temp) && ((b = !temp),
true);
215 template <
class T,
class ParamT>
219 template <
class T,
class ParamT>
221 return notify<T>(p0, nf, parser)->
storeTo(obj);
223 template <
class ParamT>
246 template <
class ParamT>
bool notify(const std::string &name, ParamT val) const
Definition: notifier.h:47
parser_t parser() const
Definition: typed_value.h:175
StoredValue(T &var, parser_type p)
Definition: typed_value.h:80
detail::Parser< T >::type parser_type
Definition: typed_value.h:103
parser_type parser_
Definition: typed_value.h:91
CustomValue(const notifier_type &n)
Definition: typed_value.h:148
this_type & operator()(const char *strVal, T eVal)
Definition: typed_value.h:59
ValueMapping< T > & values()
Definition: typed_value.h:72
NotifiedValue< T > * notify(ParamT *p0, typename detail::Notify< const T *, ParamT >::type nf, typename detail::Parser< T >::type parser=&string_cast< T >)
Definition: typed_value.h:216
bool doParse(const std::string &name, const std::string &value)
Definition: typed_value.h:151
detail::Notifier< const std::string & > notifier_type
Definition: typed_value.h:147
union ProgramOptions::NotifiedValue::@50 value_
FlagAction(Action a)
Definition: typed_value.h:174
NotifiedValue< T > * storeNotify(T &obj, ParamT *p0, typename detail::Notify< const T *, ParamT >::type nf, typename detail::Parser< T >::type parser=&string_cast< T >)
Definition: typed_value.h:220
static ValueMapping & instance()
Definition: typed_value.h:60
Manages the value of an option and defines how it is parsed from a string.
Definition: value.h:53
std::vector< std::pair< const char *, int > > base_type
Definition: typed_value.h:43
Definition: typed_value.h:42
ValueMapping this_type
Definition: typed_value.h:56
tuple a
Definition: pyclingo.py:6
detail::Parser< T >::type parser_type
Definition: typed_value.h:79
bool(* type)(const std::string &, T &)
Definition: typed_value.h:36
bool doParse(const std::string &name, const std::string &value)
Definition: typed_value.h:116
Definition: typed_value.h:173
Definition: typed_value.h:173
notifier_type notify_
Definition: typed_value.h:155
Definition: typed_value.h:163
StoredValue< T > * storeTo(T &v, typename detail::Parser< T >::type p=&string_cast< T >)
Definition: typed_value.h:190
Action
Definition: typed_value.h:173
T * address_
Definition: typed_value.h:90
bool doParse(const std::string &, const std::string &value)
Definition: typed_value.h:86
tuple b
Definition: pyclingo.py:47
parser_type parser_
Definition: typed_value.h:139
bool hasProperty(Property f) const
Definition: value.h:191
static bool parse(const std::string &value, U &out)
Definition: typed_value.h:64
detail::Notifier< const T * > notifier_type
Definition: typed_value.h:104
Definition: typed_value.h:97
detail::Parser< bool >::type parser_t
Definition: typed_value.h:164
tuple p
Definition: server.py:49
static bool store_false(const std::string &v, bool &b)
Definition: typed_value.h:169
notifier_type notify_
Definition: typed_value.h:140
T * address
Definition: typed_value.h:136
Definition: typed_value.h:145
void add(const char *strVal, int eVal)
Definition: typed_value.h:46
enum ProgramOptions::FlagAction::Action act
int x
Definition: utility.cc:65
Gringo::IntervalSet< T >::const_iterator begin(Gringo::IntervalSet< T > const &x)
Definition: intervals.hh:311
Definition: notifier.h:54
Definition: typed_value.h:55
NotifiedValue< T > * storeTo(T &obj)
Definition: typed_value.h:111
Definition: typed_value.h:101
Value var
Definition: output.cc:70
const int * get(const char *strVal) const
Definition: typed_value.h:47
bool string_cast(const char *arg, T &to)
Definition: string_convert.h:203
Definition: typed_value.h:36
NotifiedValue< bool > * flag(ValueMap &map, FlagAction a=store_true)
Definition: mapped_value.h:88
NotifiedValue(T *(*cf)(), const notifier_type &n, parser_type p)
Definition: typed_value.h:105
Definition: typed_value.h:77
void setProperty(Property f)
Definition: value.h:189
LparseOutputter & out
Definition: output.cc:685
ValueMappingBase base_type
Definition: typed_value.h:57
static bool store_true(const std::string &v, bool &b)
Definition: typed_value.h:165
static T * create()
Definition: typed_value.h:98
int end
Definition: literals.cc:62