OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SK_COMMAND_LINE_FLAGS_H | 8 #ifndef SK_COMMAND_LINE_FLAGS_H |
9 #define SK_COMMAND_LINE_FLAGS_H | 9 #define SK_COMMAND_LINE_FLAGS_H |
10 | 10 |
11 #include "SkString.h" | 11 #include "SkString.h" |
12 #include "SkTArray.h" | 12 #include "SkTArray.h" |
| 13 #include "SkTDArray.h" |
13 | 14 |
14 /** | 15 /** |
15 * Including this file (and compiling SkCommandLineFlags.cpp) provides command
line | 16 * Including this file (and compiling SkCommandLineFlags.cpp) provides command
line |
16 * parsing. In order to use it, use the following macros in global | 17 * parsing. In order to use it, use the following macros in global |
17 * namespace: | 18 * namespace: |
18 * | 19 * |
19 * DEFINE_bool(name, defaultValue, helpString); | 20 * DEFINE_bool(name, defaultValue, helpString); |
20 * DEFINE_string(name, defaultValue, helpString); | 21 * DEFINE_string(name, defaultValue, helpString); |
21 * DEFINE_int32(name, defaultValue, helpString); | 22 * DEFINE_int32(name, defaultValue, helpString); |
22 * DEFINE_double(name, defaultValue, helpString); | 23 * DEFINE_double(name, defaultValue, helpString); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 * | 84 * |
84 * Inspired by gflags (https://code.google.com/p/gflags/). Is not quite as | 85 * Inspired by gflags (https://code.google.com/p/gflags/). Is not quite as |
85 * robust as gflags, but suits our purposes. For example, allows creating | 86 * robust as gflags, but suits our purposes. For example, allows creating |
86 * a flag -h or -help which will never be used, since SkCommandLineFlags handle
s it. | 87 * a flag -h or -help which will never be used, since SkCommandLineFlags handle
s it. |
87 * SkCommandLineFlags will also allow creating --flag and --noflag. Uses the sa
me input | 88 * SkCommandLineFlags will also allow creating --flag and --noflag. Uses the sa
me input |
88 * format as gflags and creates similarly named variables (i.e. FLAGS_name). | 89 * format as gflags and creates similarly named variables (i.e. FLAGS_name). |
89 * Strings are handled differently (resulting variable will be an array of | 90 * Strings are handled differently (resulting variable will be an array of |
90 * strings) so that a flag can be followed by multiple parameters. | 91 * strings) so that a flag can be followed by multiple parameters. |
91 */ | 92 */ |
92 | 93 |
93 | |
94 class SkFlagInfo; | 94 class SkFlagInfo; |
95 | 95 |
96 class SkCommandLineFlags { | 96 class SkCommandLineFlags { |
97 | 97 |
98 public: | 98 public: |
99 /** | 99 /** |
100 * Call to set the help message to be displayed. Should be called before | 100 * Call to set the help message to be displayed. Should be called before |
101 * Parse. | 101 * Parse. |
102 */ | 102 */ |
103 static void SetUsage(const char* usage); | 103 static void SetUsage(const char* usage); |
104 | 104 |
105 /** | 105 /** |
106 * Call at the beginning of main to parse flags created by DEFINE_x, above. | 106 * Call at the beginning of main to parse flags created by DEFINE_x, above. |
107 * Must only be called once. | 107 * Must only be called once. |
108 */ | 108 */ |
109 static void Parse(int argc, char** argv); | 109 static void Parse(int argc, char** argv); |
110 | 110 |
| 111 /* Takes a list of the form [~][^]match[$] |
| 112 ~ causes a matching test to always be skipped |
| 113 ^ requires the start of the test to match |
| 114 $ requires the end of the test to match |
| 115 ^ and $ requires an exact match |
| 116 If a test does not match any list entry, it is skipped unless some list ent
ry starts with ~ |
| 117 */ |
| 118 static bool ShouldSkip(const SkTDArray<const char*>& strings, const char* na
me); |
| 119 |
111 /** | 120 /** |
112 * Custom class for holding the arguments for a string flag. | 121 * Custom class for holding the arguments for a string flag. |
113 * Publicly only has accessors so the strings cannot be modified. | 122 * Publicly only has accessors so the strings cannot be modified. |
114 */ | 123 */ |
115 class StringArray { | 124 class StringArray { |
116 public: | 125 public: |
117 const char* operator[](int i) const { | 126 const char* operator[](int i) const { |
118 SkASSERT(i >= 0 && i < fStrings.count()); | 127 SkASSERT(i >= 0 && i < fStrings.count()); |
119 return fStrings[i].c_str(); | 128 return fStrings[i].c_str(); |
120 } | 129 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 double* fDoubleValue; | 424 double* fDoubleValue; |
416 double fDefaultDouble; | 425 double fDefaultDouble; |
417 SkCommandLineFlags::StringArray* fStrings; | 426 SkCommandLineFlags::StringArray* fStrings; |
418 // Both for the help string and in case fStrings is empty. | 427 // Both for the help string and in case fStrings is empty. |
419 SkString fDefaultString; | 428 SkString fDefaultString; |
420 | 429 |
421 // In order to keep a linked list. | 430 // In order to keep a linked list. |
422 SkFlagInfo* fNext; | 431 SkFlagInfo* fNext; |
423 }; | 432 }; |
424 #endif // SK_COMMAND_LINE_FLAGS_H | 433 #endif // SK_COMMAND_LINE_FLAGS_H |
OLD | NEW |