Thu, 24 Jul 2014 16:54:45 +0300
- now works properly (still debugging --help)
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | Copyright 2014 Teemu Piippo |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | are met: |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | derived from this software without specific prior written permission. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | */ |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #pragma once |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "main.h" |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include <typeinfo> |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include <type_traits> |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include <cstring> |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | // _________________________________________________________________________________________________ |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | // |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | class CommandLineOption |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | private: |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | char _shortform; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | String _longform; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | String _description; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | std::type_info const* _type; |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
44 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
45 | union PointerUnion |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
46 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
47 | int* asInt; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
48 | long* asLong; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
49 | char* asChar; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
50 | bool* asBool; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
51 | String* asString; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
52 | double* asDouble; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
53 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
54 | PointerUnion (int* a) : asInt (a) {} |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
55 | PointerUnion (bool* a) : asBool (a) {} |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
56 | PointerUnion (String* a) : asString (a) {} |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
57 | PointerUnion (double* a) : asDouble (a) {} |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
58 | PointerUnion (long* a) : asLong (a) {} |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
59 | PointerUnion (char* a) : asChar (a) {} |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
60 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
61 | void setValue (int const& a) { *asInt = a; } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
62 | void setValue (bool const& a) { *asBool = a; } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
63 | void setValue (String const& a) { *asString = a; } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
64 | void setValue (double const& a) { *asDouble = a; } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
65 | void setValue (long const& a) { *asLong = a; } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
66 | void setValue (char const& a) { *asChar = a; } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
67 | } _ptr; |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | public: |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | template<typename T> |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | CommandLineOption (T& data, char shortform, const char* longform, const char* description) : |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | _shortform (shortform), |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | _longform (longform), |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | _description (description), |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | _type (&typeid (T)), |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | _ptr (&data) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | static_assert (std::is_same<T, int>::value |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | or std::is_same<T, bool>::value |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | or std::is_same<T, String>::value |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | or std::is_same<T, double>::value |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | or std::is_enum<T>::value, |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | "value to CommandLineOption must be either int, bool, String or double"); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | if (shortform == '\0' and not std::strlen (longform)) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | error ("commandline option left without short-form or long-form name"); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | virtual ~CommandLineOption() {} |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | inline String describe() const |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | return std::strlen (_longform) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | ? (String ("--") + _longform) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | : String ({'-', _shortform, '\0'}); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | inline String const& longform() const |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | return _longform; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | inline String const& description() const |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | return _description; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | inline char shortform() const |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | return _shortform; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
113 | inline PointerUnion& pointer() |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | return _ptr; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | template<typename T> |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | inline bool isOfType() const |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | return &typeid(T) == _type; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | virtual void handleValue (String const& a); |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
125 | virtual String describeArgument() const; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
126 | virtual String describeExtra() const { return ""; } |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | }; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
129 | // _________________________________________________________________________________________________ |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
130 | // |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | template<typename T> |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | class EnumeratedCommandLineOption : public CommandLineOption |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | StringList _values; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | public: |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
137 | using ValueType = typename std::underlying_type<T>::type; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
138 | |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | EnumeratedCommandLineOption (T& data, char shortform, const char* longform, |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | const char* description) : |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
141 | CommandLineOption (reinterpret_cast<ValueType&> (data), shortform, |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
142 | longform, description) |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | { |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
144 | // Store values |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | for (int i = 0; i < int (T::NumValues); ++i) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | String value = MakeFormatArgument (T (i)).toLowercase(); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | int pos; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | if ((pos = value.firstIndexOf ("::")) != -1) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | value = value.mid (pos + 2); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | _values << value; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | virtual void handleValue (String const& value) override |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | String const lowvalue (value.toLowercase()); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
161 | for (ValueType i = 0; i < _values.size(); ++i) |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | { |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
163 | if (_values[i] == lowvalue) |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | { |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
165 | pointer().setValue (i); |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | return; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | error ("bad value passed to %1 (%2), valid values are: %3", describe(), value, _values); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | } |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
172 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
173 | virtual String describeArgument() const |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
174 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
175 | return "ENUM"; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
176 | } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
177 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
178 | StringList const& validValues() const |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
179 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
180 | return _values; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
181 | } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
182 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
183 | virtual String describeExtra() const |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
184 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
185 | return format ("Valid values for %1: %2", describe(), validValues()); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
186 | } |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
187 | }; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
188 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
189 | // _________________________________________________________________________________________________ |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
190 | // |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | class CommandLine |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | List<CommandLineOption*> _options; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | DELETE_COPY (CommandLine) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | public: |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | CommandLine() = default; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | ~CommandLine(); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | template<typename Enum> |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | void addEnumeratedOption (Enum& e, char shortform, const char* longform, |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | const char* description); |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
202 | String describeOptions() const; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
203 | StringList process (const int argc, char* argv[]); |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | template<typename... Args> |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
206 | void addOption (Args&&... args) |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | { |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
208 | _options << new CommandLineOption (args...); |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | }; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | // _________________________________________________________________________________________________ |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | // |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | template<typename Enum> |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | void CommandLine::addEnumeratedOption (Enum& e, char shortform, const char* longform, |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | const char* description) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | { |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
218 | static_assert(std::is_enum<Enum>::value, "addEnumeratedOption requires a named enumerator"); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
219 | _options << new EnumeratedCommandLineOption<Enum> (e, shortform, longform, |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | description); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | } |