00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef PALUDIS_GUARD_ARGS_ARGS_OPTION_HH
00022 #define PALUDIS_GUARD_ARGS_ARGS_OPTION_HH 1
00023
00024 #include <paludis/args/args_visitor.hh>
00025 #include <paludis/util/private_implementation_pattern.hh>
00026 #include <paludis/util/wrapped_forward_iterator-fwd.hh>
00027 #include <paludis/util/type_list.hh>
00028 #include <paludis/util/named_value.hh>
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 namespace paludis
00041 {
00042 namespace n
00043 {
00044 struct description;
00045 struct long_name;
00046 struct short_name;
00047 }
00048
00049 namespace args
00050 {
00051 class ArgsGroup;
00052
00053
00054
00055
00056
00057
00058 class PALUDIS_VISIBLE ArgsOption :
00059 public virtual DeclareAbstractAcceptMethods<ArgsOption, MakeTypeList<
00060 StringArg, AliasArg, SwitchArg, IntegerArg, EnumArg, StringSetArg, StringSequenceArg>::Type>
00061 {
00062 friend class ArgsHandler;
00063
00064 private:
00065 ArgsGroup * const _group;
00066
00067 const std::string _long_name;
00068 const char _short_name;
00069 const std::string _description;
00070
00071 bool _specified;
00072
00073 ArgsOption(const ArgsOption &);
00074 void operator= (const ArgsOption &);
00075
00076 protected:
00077
00078
00079
00080 ArgsOption(ArgsGroup * const, const std::string & long_name,
00081 const char short_name, const std::string & description);
00082
00083
00084
00085
00086 virtual ~ArgsOption();
00087
00088 public:
00089
00090
00091
00092 void remove();
00093
00094
00095
00096
00097 const std::string & long_name() const
00098 {
00099 return _long_name;
00100 }
00101
00102
00103
00104
00105 char short_name() const
00106 {
00107 return _short_name;
00108 }
00109
00110
00111
00112
00113 const std::string & description() const
00114 {
00115 return _description;
00116 }
00117
00118
00119
00120
00121
00122 virtual bool specified() const
00123 {
00124 return _specified;
00125 }
00126
00127
00128
00129
00130 virtual void set_specified(const bool value)
00131 {
00132 _specified = value;
00133 }
00134
00135
00136
00137
00138 ArgsGroup * group()
00139 {
00140 return _group;
00141 }
00142
00143
00144
00145
00146
00147
00148 virtual bool can_be_negated() const = 0;
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00159 };
00160
00161
00162
00163
00164
00165
00166
00167 class PALUDIS_VISIBLE SwitchArg :
00168 public ArgsOption,
00169 public ImplementAcceptMethods<ArgsOption, SwitchArg>
00170 {
00171 private:
00172 bool _can_be_negated;
00173
00174 public:
00175
00176
00177
00178
00179
00180 SwitchArg(ArgsGroup * const group, const std::string & long_name, char short_name,
00181 const std::string & description, const bool can_be_negated);
00182
00183 ~SwitchArg();
00184
00185 virtual bool can_be_negated() const;
00186
00187 virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
00188 };
00189
00190
00191
00192
00193
00194
00195 class PALUDIS_VISIBLE StringArg :
00196 public ArgsOption,
00197 public ImplementAcceptMethods<ArgsOption, StringArg>
00198 {
00199 private:
00200 std::string _argument;
00201 void (* _validator) (const std::string &);
00202
00203 public:
00204
00205
00206
00207 StringArg(ArgsGroup * const, const std::string & long_name,
00208 const char short_name, const std::string & description);
00209
00210
00211
00212
00213 StringArg(ArgsGroup * const, const std::string & long_name,
00214 const char short_name, const std::string & description,
00215 void (* validator) (const std::string &));
00216
00217
00218
00219
00220 const std::string & argument() const { return _argument; }
00221
00222
00223
00224
00225 void set_argument(const std::string & arg);
00226
00227 virtual bool can_be_negated() const;
00228
00229 virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
00230 };
00231
00232
00233
00234
00235
00236
00237
00238 class PALUDIS_VISIBLE StringSetArg :
00239 public ArgsOption,
00240 public ImplementAcceptMethods<ArgsOption, StringSetArg>,
00241 private PrivateImplementationPattern<StringSetArg>
00242 {
00243 private:
00244 void (* _validator) (const std::string &);
00245
00246 public:
00247
00248
00249
00250
00251
00252
00253 class PALUDIS_VISIBLE StringSetArgOptions :
00254 private PrivateImplementationPattern<StringSetArgOptions>
00255 {
00256 friend class StringSetArg;
00257
00258 public:
00259
00260
00261
00262 StringSetArgOptions(const std::string &, const std::string &);
00263
00264
00265
00266
00267 explicit StringSetArgOptions();
00268
00269
00270
00271
00272 StringSetArgOptions(const StringSetArgOptions &);
00273
00274
00275
00276
00277 ~StringSetArgOptions();
00278
00279
00280
00281
00282 StringSetArgOptions & operator() (const std::string &, const std::string &);
00283 };
00284
00285
00286
00287
00288 StringSetArg(ArgsGroup * const, const std::string & long_name,
00289 const char short_name, const std::string & description,
00290 const StringSetArgOptions & options = StringSetArgOptions());
00291
00292 StringSetArg(ArgsGroup * const, const std::string & long_name,
00293 const char short_name, const std::string & description,
00294 const StringSetArgOptions & options,
00295 void (* validator) (const std::string &));
00296
00297 ~StringSetArg();
00298
00299
00300
00301
00302
00303
00304 struct ConstIteratorTag;
00305 typedef WrappedForwardIterator<ConstIteratorTag, const std::string> ConstIterator;
00306
00307 ConstIterator begin_args() const;
00308
00309 ConstIterator end_args() const;
00310
00311
00312
00313
00314
00315
00316 void add_argument(const std::string & arg);
00317
00318
00319
00320
00321 struct AllowedArgConstIteratorTag;
00322 typedef WrappedForwardIterator<AllowedArgConstIteratorTag,
00323 const std::pair<std::string, std::string> > AllowedArgConstIterator;
00324
00325 AllowedArgConstIterator begin_allowed_args() const;
00326
00327 AllowedArgConstIterator end_allowed_args() const;
00328
00329
00330
00331 virtual bool can_be_negated() const;
00332
00333 virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
00334 };
00335
00336
00337
00338
00339
00340
00341
00342
00343 class PALUDIS_VISIBLE StringSequenceArg :
00344 public ArgsOption,
00345 public ImplementAcceptMethods<ArgsOption, StringSequenceArg>,
00346 private PrivateImplementationPattern<StringSequenceArg>
00347 {
00348 public:
00349
00350
00351
00352 StringSequenceArg(ArgsGroup * const, const std::string & long_name,
00353 const char short_name, const std::string & description);
00354
00355 ~StringSequenceArg();
00356
00357
00358
00359
00360
00361
00362 struct ConstIteratorTag;
00363 typedef WrappedForwardIterator<ConstIteratorTag, const std::string> ConstIterator;
00364
00365 ConstIterator begin_args() const;
00366
00367 ConstIterator end_args() const;
00368
00369
00370
00371
00372
00373
00374 void add_argument(const std::string & arg);
00375
00376 virtual bool can_be_negated() const;
00377
00378 virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
00379 };
00380
00381
00382
00383
00384
00385
00386
00387 class PALUDIS_VISIBLE AliasArg :
00388 public ArgsOption,
00389 public ImplementAcceptMethods<ArgsOption, AliasArg>
00390 {
00391 private:
00392 ArgsOption * const _other;
00393 bool _hidden;
00394
00395 public:
00396
00397
00398
00399 AliasArg(ArgsOption * const other, const std::string & new_long_name, bool is_hidden = false);
00400
00401 virtual bool specified() const
00402 {
00403 return _other->specified();
00404 }
00405
00406 virtual void set_specified(const bool value)
00407 {
00408 _other->set_specified(value);
00409 }
00410
00411 virtual bool hidden() const
00412 {
00413 return _hidden;
00414 }
00415
00416 virtual void set_hidden(const bool value)
00417 {
00418 _hidden = value;
00419 }
00420
00421
00422
00423
00424 ArgsOption * other() const
00425 {
00426 return _other;
00427 }
00428
00429 virtual bool can_be_negated() const;
00430
00431 virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
00432 };
00433
00434
00435
00436
00437
00438
00439 class PALUDIS_VISIBLE IntegerArg :
00440 public ArgsOption,
00441 public ImplementAcceptMethods<ArgsOption, IntegerArg>
00442 {
00443 private:
00444 int _argument;
00445
00446 public:
00447
00448
00449
00450 IntegerArg(ArgsGroup * const, const std::string & long_name,
00451 const char short_name, const std::string & description);
00452
00453
00454
00455 int argument() const { return _argument; }
00456
00457
00458
00459
00460 void set_argument(const int arg) { _argument = arg; }
00461
00462 virtual bool can_be_negated() const;
00463
00464 virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
00465 };
00466
00467
00468
00469
00470
00471
00472
00473 struct AllowedEnumArg
00474 {
00475 NamedValue<n::description, std::string> description;
00476 NamedValue<n::long_name, std::string> long_name;
00477
00478
00479 NamedValue<n::short_name, char> short_name;
00480 };
00481
00482
00483
00484
00485
00486
00487
00488 class PALUDIS_VISIBLE EnumArg :
00489 public ArgsOption,
00490 public ImplementAcceptMethods<ArgsOption, EnumArg>,
00491 private PrivateImplementationPattern<EnumArg>
00492 {
00493 private:
00494 std::string _argument;
00495 std::string _default_arg;
00496
00497 public:
00498
00499
00500
00501
00502
00503
00504 class PALUDIS_VISIBLE EnumArgOptions :
00505 private PrivateImplementationPattern<EnumArgOptions>
00506 {
00507 friend class EnumArg;
00508
00509 public:
00510
00511
00512
00513 EnumArgOptions(const std::string &, const std::string &);
00514
00515
00516
00517
00518
00519
00520 EnumArgOptions(const std::string &, const char, const std::string &);
00521
00522
00523
00524
00525 ~EnumArgOptions();
00526
00527
00528
00529
00530 EnumArgOptions & operator() (const std::string &, const std::string &);
00531
00532
00533
00534
00535
00536
00537 EnumArgOptions & operator() (const std::string &, const char, const std::string &);
00538 };
00539
00540
00541
00542
00543 EnumArg(ArgsGroup * const group, const std::string & long_name,
00544 const char short_name, const std::string & description,
00545 const EnumArgOptions & opts, const std::string & default_arg);
00546
00547 ~EnumArg();
00548
00549
00550
00551
00552 const std::string & argument() const
00553 {
00554 return _argument;
00555 }
00556
00557
00558
00559
00560
00561 void set_argument(const std::string & arg);
00562
00563
00564
00565
00566
00567 void set_default_arg(const std::string & arg);
00568
00569
00570
00571
00572
00573 const std::string & default_arg() const
00574 {
00575 return _default_arg;
00576 }
00577
00578
00579
00580
00581 struct AllowedArgConstIteratorTag;
00582 typedef WrappedForwardIterator<AllowedArgConstIteratorTag,
00583 const AllowedEnumArg> AllowedArgConstIterator;
00584
00585 AllowedArgConstIterator begin_allowed_args() const;
00586
00587 AllowedArgConstIterator end_allowed_args() const;
00588
00589
00590
00591 virtual bool can_be_negated() const;
00592
00593 virtual const std::string forwardable_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
00594 };
00595 }
00596 }
00597
00598 #endif