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" | |
14 | 13 |
15 /** | 14 /** |
16 * Including this file (and compiling SkCommandLineFlags.cpp) provides command
line | 15 * Including this file (and compiling SkCommandLineFlags.cpp) provides command
line |
17 * parsing. In order to use it, use the following macros in global | 16 * parsing. In order to use it, use the following macros in global |
18 * namespace: | 17 * namespace: |
19 * | 18 * |
20 * DEFINE_bool(name, defaultValue, helpString); | 19 * DEFINE_bool(name, defaultValue, helpString); |
21 * DEFINE_string(name, defaultValue, helpString); | 20 * DEFINE_string(name, defaultValue, helpString); |
22 * DEFINE_int32(name, defaultValue, helpString); | 21 * DEFINE_int32(name, defaultValue, helpString); |
23 * DEFINE_double(name, defaultValue, helpString); | 22 * DEFINE_double(name, defaultValue, helpString); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 * | 83 * |
85 * Inspired by gflags (https://code.google.com/p/gflags/). Is not quite as | 84 * Inspired by gflags (https://code.google.com/p/gflags/). Is not quite as |
86 * robust as gflags, but suits our purposes. For example, allows creating | 85 * robust as gflags, but suits our purposes. For example, allows creating |
87 * a flag -h or -help which will never be used, since SkCommandLineFlags handle
s it. | 86 * a flag -h or -help which will never be used, since SkCommandLineFlags handle
s it. |
88 * SkCommandLineFlags will also allow creating --flag and --noflag. Uses the sa
me input | 87 * SkCommandLineFlags will also allow creating --flag and --noflag. Uses the sa
me input |
89 * format as gflags and creates similarly named variables (i.e. FLAGS_name). | 88 * format as gflags and creates similarly named variables (i.e. FLAGS_name). |
90 * Strings are handled differently (resulting variable will be an array of | 89 * Strings are handled differently (resulting variable will be an array of |
91 * strings) so that a flag can be followed by multiple parameters. | 90 * strings) so that a flag can be followed by multiple parameters. |
92 */ | 91 */ |
93 | 92 |
| 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 | |
120 /** | 111 /** |
121 * Custom class for holding the arguments for a string flag. | 112 * Custom class for holding the arguments for a string flag. |
122 * Publicly only has accessors so the strings cannot be modified. | 113 * Publicly only has accessors so the strings cannot be modified. |
123 */ | 114 */ |
124 class StringArray { | 115 class StringArray { |
125 public: | 116 public: |
126 const char* operator[](int i) const { | 117 const char* operator[](int i) const { |
127 SkASSERT(i >= 0 && i < fStrings.count()); | 118 SkASSERT(i >= 0 && i < fStrings.count()); |
128 return fStrings[i].c_str(); | 119 return fStrings[i].c_str(); |
129 } | 120 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 double* fDoubleValue; | 415 double* fDoubleValue; |
425 double fDefaultDouble; | 416 double fDefaultDouble; |
426 SkCommandLineFlags::StringArray* fStrings; | 417 SkCommandLineFlags::StringArray* fStrings; |
427 // Both for the help string and in case fStrings is empty. | 418 // Both for the help string and in case fStrings is empty. |
428 SkString fDefaultString; | 419 SkString fDefaultString; |
429 | 420 |
430 // In order to keep a linked list. | 421 // In order to keep a linked list. |
431 SkFlagInfo* fNext; | 422 SkFlagInfo* fNext; |
432 }; | 423 }; |
433 #endif // SK_COMMAND_LINE_FLAGS_H | 424 #endif // SK_COMMAND_LINE_FLAGS_H |
OLD | NEW |