blob: 4a22c3f4bfa273e53e4f9e0ac3feaac54980d8d0 [file] [log] [blame]
scroggo@google.com161e1ba2013-03-04 16:41:06 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
scroggo@google.comd9ba9a02013-03-21 19:43:15 +00008#ifndef SK_COMMAND_LINE_FLAGS_H
9#define SK_COMMAND_LINE_FLAGS_H
scroggo@google.com161e1ba2013-03-04 16:41:06 +000010
bungemanbf521ff2016-02-17 13:13:44 -080011#include "../private/SkTArray.h"
bungemana7e9f052016-02-18 08:53:33 -080012#include "../private/SkTDArray.h"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000013#include "SkString.h"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000014
15/**
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000016 * Including this file (and compiling SkCommandLineFlags.cpp) provides command line
scroggo@google.com161e1ba2013-03-04 16:41:06 +000017 * parsing. In order to use it, use the following macros in global
18 * namespace:
19 *
20 * DEFINE_bool(name, defaultValue, helpString);
21 * DEFINE_string(name, defaultValue, helpString);
22 * DEFINE_int32(name, defaultValue, helpString);
23 * DEFINE_double(name, defaultValue, helpString);
24 *
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000025 * Then, in main, call SkCommandLineFlags::SetUsage() to describe usage and call
26 * SkCommandLineFlags::Parse() to parse the flags. Henceforth, each flag can
scroggo@google.com161e1ba2013-03-04 16:41:06 +000027 * be referenced using
28 *
29 * FLAGS_name
30 *
31 * For example, the line
32 *
33 * DEFINE_bool(boolean, false, "The variable boolean does such and such");
34 *
35 * will create the following variable:
36 *
37 * bool FLAGS_boolean;
38 *
39 * which will initially be set to false, and can be set to true by using the
40 * flag "--boolean" on the commandline. "--noboolean" will set FLAGS_boolean
scroggo@google.com5dc4ca12013-03-21 13:10:59 +000041 * to false. FLAGS_boolean can also be set using "--boolean=true" or
42 * "--boolean true" (where "true" can be replaced by "false", "TRUE", "FALSE",
43 * "1" or "0").
44 *
scroggo@google.com5dc4ca12013-03-21 13:10:59 +000045 * The helpString will be printed if the help flag (-h or -help) is used.
scroggo@google.com161e1ba2013-03-04 16:41:06 +000046 *
47 * Similarly, the line
48 *
49 * DEFINE_int32(integer, .., ..);
50 *
51 * will create
52 *
53 * int32_t FLAGS_integer;
54 *
55 * and
56 *
57 * DEFINE_double(real, .., ..);
58 *
59 * will create
60 *
61 * double FLAGS_real;
62 *
63 * These flags can be set by specifying, for example, "--integer 7" and
64 * "--real 3.14" on the command line.
65 *
66 * Unlike the others, the line
67 *
68 * DEFINE_string(args, .., ..);
69 *
70 * creates an array:
71 *
scroggo@google.comb7dbf632013-04-23 15:38:09 +000072 * SkCommandLineFlags::StringArray FLAGS_args;
scroggo@google.com161e1ba2013-03-04 16:41:06 +000073 *
74 * If the default value is the empty string, FLAGS_args will default to a size
75 * of zero. Otherwise it will default to a size of 1 with the default string
76 * as its value. All strings that follow the flag on the command line (until
77 * a string that begins with '-') will be entries in the array.
78 *
kkinnunen3e980c32015-12-23 01:33:00 -080079 * DEFINE_extended_string(args, .., .., extendedHelpString);
80 *
81 * creates a similar string array flag as DEFINE_string. The flag will have extended help text
82 * (extendedHelpString) that can the user can see with '--help <args>' flag.
83 *
scroggo@google.com161e1ba2013-03-04 16:41:06 +000084 * Any flag can be referenced from another file after using the following:
85 *
86 * DECLARE_x(name);
87 *
88 * (where 'x' is the type specified in the DEFINE).
89 *
90 * Inspired by gflags (https://code.google.com/p/gflags/). Is not quite as
91 * robust as gflags, but suits our purposes. For example, allows creating
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000092 * a flag -h or -help which will never be used, since SkCommandLineFlags handles it.
93 * SkCommandLineFlags will also allow creating --flag and --noflag. Uses the same input
scroggo@google.com161e1ba2013-03-04 16:41:06 +000094 * format as gflags and creates similarly named variables (i.e. FLAGS_name).
95 * Strings are handled differently (resulting variable will be an array of
96 * strings) so that a flag can be followed by multiple parameters.
97 */
98
scroggo@google.com161e1ba2013-03-04 16:41:06 +000099class SkFlagInfo;
100
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000101class SkCommandLineFlags {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000102
103public:
104 /**
105 * Call to set the help message to be displayed. Should be called before
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000106 * Parse.
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000107 */
108 static void SetUsage(const char* usage);
109
110 /**
msarett3478f752016-02-12 14:47:09 -0800111 * Call this to display the help message. Should be called after SetUsage.
112 */
113 static void PrintUsage();
114
115 /**
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000116 * Call at the beginning of main to parse flags created by DEFINE_x, above.
117 * Must only be called once.
118 */
Cary Clark7265ea32017-09-14 12:12:32 -0400119 static void Parse(int argc, const char* const * argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000120
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000121 /**
122 * Custom class for holding the arguments for a string flag.
123 * Publicly only has accessors so the strings cannot be modified.
124 */
125 class StringArray {
126 public:
kkinnunen3e980c32015-12-23 01:33:00 -0800127 StringArray() { }
128 explicit StringArray(const SkTArray<SkString>& strings)
129 : fStrings(strings) {
130 }
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000131 const char* operator[](int i) const {
132 SkASSERT(i >= 0 && i < fStrings.count());
133 return fStrings[i].c_str();
134 }
135
136 int count() const {
137 return fStrings.count();
138 }
139
140 bool isEmpty() const { return this->count() == 0; }
141
epoger@google.comdefc4872013-09-19 06:18:27 +0000142 /**
143 * Returns true iff string is equal to one of the strings in this array.
144 */
145 bool contains(const char* string) const {
146 for (int i = 0; i < fStrings.count(); i++) {
147 if (fStrings[i].equals(string)) {
148 return true;
149 }
150 }
151 return false;
152 }
153
caryclark936b7342014-07-11 12:14:51 -0700154 void set(int i, const char* str) {
155 fStrings[i].set(str);
156 }
157
Florin Malita094ccde2017-12-30 12:27:00 -0500158 const SkString* begin() const { return fStrings.begin(); }
159 const SkString* end() const { return fStrings.end(); }
160
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000161 private:
162 void reset() { fStrings.reset(); }
163
164 void append(const char* string) {
165 fStrings.push_back().set(string);
166 }
167
scroggo@google.com58104a92013-04-24 19:25:26 +0000168 void append(const char* string, size_t length) {
169 fStrings.push_back().set(string, length);
170 }
171
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000172 SkTArray<SkString> fStrings;
173
174 friend class SkFlagInfo;
175 };
176
commit-bot@chromium.orga6f37e72013-08-30 15:52:46 +0000177 /* Takes a list of the form [~][^]match[$]
178 ~ causes a matching test to always be skipped
179 ^ requires the start of the test to match
180 $ requires the end of the test to match
181 ^ and $ requires an exact match
182 If a test does not match any list entry, it is skipped unless some list entry starts with ~
183 */
184 static bool ShouldSkip(const SkTDArray<const char*>& strings, const char* name);
185 static bool ShouldSkip(const StringArray& strings, const char* name);
186
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000187private:
188 static SkFlagInfo* gHead;
189 static SkString gUsage;
190
191 // For access to gHead.
192 friend class SkFlagInfo;
193};
194
195#define TO_STRING2(s) #s
196#define TO_STRING(s) TO_STRING2(s)
197
198#define DEFINE_bool(name, defaultValue, helpString) \
199bool FLAGS_##name; \
fmalita523beb72015-06-10 10:46:50 -0700200SK_UNUSED static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name), \
halcanary96fcdcc2015-08-27 07:41:13 -0700201 nullptr, \
fmalita523beb72015-06-10 10:46:50 -0700202 &FLAGS_##name, \
203 defaultValue, \
204 helpString)
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000205
206// bool 2 allows specifying a short name. No check is done to ensure that shortName
207// is actually shorter than name.
208#define DEFINE_bool2(name, shortName, defaultValue, helpString) \
209bool FLAGS_##name; \
fmalita523beb72015-06-10 10:46:50 -0700210SK_UNUSED static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name), \
211 TO_STRING(shortName),\
212 &FLAGS_##name, \
213 defaultValue, \
214 helpString)
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000215
216#define DECLARE_bool(name) extern bool FLAGS_##name;
217
218#define DEFINE_string(name, defaultValue, helpString) \
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000219SkCommandLineFlags::StringArray FLAGS_##name; \
fmalita523beb72015-06-10 10:46:50 -0700220SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
halcanary96fcdcc2015-08-27 07:41:13 -0700221 nullptr, \
fmalita523beb72015-06-10 10:46:50 -0700222 &FLAGS_##name, \
223 defaultValue, \
kkinnunen3e980c32015-12-23 01:33:00 -0800224 helpString, nullptr)
225#define DEFINE_extended_string(name, defaultValue, helpString, extendedHelpString) \
226SkCommandLineFlags::StringArray FLAGS_##name; \
227SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
228 nullptr, \
229 &FLAGS_##name, \
230 defaultValue, \
231 helpString, \
232 extendedHelpString)
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000233
scroggo@google.com604e0c22013-04-09 21:25:46 +0000234// string2 allows specifying a short name. There is an assert that shortName
235// is only 1 character.
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000236#define DEFINE_string2(name, shortName, defaultValue, helpString) \
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000237SkCommandLineFlags::StringArray FLAGS_##name; \
fmalita523beb72015-06-10 10:46:50 -0700238SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
239 TO_STRING(shortName), \
240 &FLAGS_##name, \
241 defaultValue, \
kkinnunen3e980c32015-12-23 01:33:00 -0800242 helpString, nullptr)
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000243
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000244#define DECLARE_string(name) extern SkCommandLineFlags::StringArray FLAGS_##name;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000245
robertphillips5ce341f2015-09-18 09:04:43 -0700246
247
248
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000249#define DEFINE_int32(name, defaultValue, helpString) \
250int32_t FLAGS_##name; \
fmalita523beb72015-06-10 10:46:50 -0700251SK_UNUSED static bool unused_##name = SkFlagInfo::CreateIntFlag(TO_STRING(name), \
252 &FLAGS_##name, \
253 defaultValue, \
254 helpString)
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000255
robertphillips5ce341f2015-09-18 09:04:43 -0700256#define DEFINE_int32_2(name, shortName, defaultValue, helpString) \
257int32_t FLAGS_##name; \
258SK_UNUSED static bool unused_##name = SkFlagInfo::CreateIntFlag(TO_STRING(name), \
259 TO_STRING(shortName), \
260 &FLAGS_##name, \
261 defaultValue, \
262 helpString)
263
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000264#define DECLARE_int32(name) extern int32_t FLAGS_##name;
265
266#define DEFINE_double(name, defaultValue, helpString) \
267double FLAGS_##name; \
fmalita523beb72015-06-10 10:46:50 -0700268SK_UNUSED static bool unused_##name = SkFlagInfo::CreateDoubleFlag(TO_STRING(name), \
269 &FLAGS_##name, \
270 defaultValue, \
271 helpString)
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000272
273#define DECLARE_double(name) extern double FLAGS_##name;
274
275class SkFlagInfo {
276
277public:
278 enum FlagTypes {
279 kBool_FlagType,
280 kString_FlagType,
281 kInt_FlagType,
282 kDouble_FlagType,
283 };
284
scroggo@google.com58104a92013-04-24 19:25:26 +0000285 /**
286 * Each Create<Type>Flag function creates an SkFlagInfo of the specified type. The SkFlagInfo
287 * object is appended to a list, which is deleted when SkCommandLineFlags::Parse is called.
288 * Therefore, each call should be made before the call to ::Parse. They are not intended
289 * to be called directly. Instead, use the macros described above.
290 * @param name Long version (at least 2 characters) of the name of the flag. This name can
291 * be referenced on the command line as "--name" to set the value of this flag.
292 * @param shortName Short version (one character) of the name of the flag. This name can
293 * be referenced on the command line as "-shortName" to set the value of this flag.
294 * @param p<Type> Pointer to a global variable which holds the value set by SkCommandLineFlags.
295 * @param defaultValue The default value of this flag. The variable pointed to by p<Type> will
296 * be set to this value initially. This is also displayed as part of the help output.
297 * @param helpString Explanation of what this flag changes in the program.
298 */
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000299 static bool CreateBoolFlag(const char* name, const char* shortName, bool* pBool,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000300 bool defaultValue, const char* helpString) {
kkinnunen3e980c32015-12-23 01:33:00 -0800301 SkFlagInfo* info = new SkFlagInfo(name, shortName, kBool_FlagType, helpString, nullptr);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000302 info->fBoolValue = pBool;
303 *info->fBoolValue = info->fDefaultBool = defaultValue;
304 return true;
305 }
306
scroggo@google.com58104a92013-04-24 19:25:26 +0000307 /**
308 * See comments for CreateBoolFlag.
309 * @param pStrings Unlike the others, this is a pointer to an array of values.
310 * @param defaultValue Thise default will be parsed so that strings separated by spaces
311 * will be added to pStrings.
312 */
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000313 static bool CreateStringFlag(const char* name, const char* shortName,
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000314 SkCommandLineFlags::StringArray* pStrings,
kkinnunen3e980c32015-12-23 01:33:00 -0800315 const char* defaultValue, const char* helpString,
316 const char* extendedHelpString);
skia.committer@gmail.com075b0892013-03-05 07:09:08 +0000317
scroggo@google.com58104a92013-04-24 19:25:26 +0000318 /**
319 * See comments for CreateBoolFlag.
320 */
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000321 static bool CreateIntFlag(const char* name, int32_t* pInt,
322 int32_t defaultValue, const char* helpString) {
kkinnunen3e980c32015-12-23 01:33:00 -0800323 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kInt_FlagType, helpString, nullptr);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000324 info->fIntValue = pInt;
325 *info->fIntValue = info->fDefaultInt = defaultValue;
326 return true;
327 }
328
robertphillips5ce341f2015-09-18 09:04:43 -0700329 static bool CreateIntFlag(const char* name, const char* shortName, int32_t* pInt,
330 int32_t defaultValue, const char* helpString) {
kkinnunen3e980c32015-12-23 01:33:00 -0800331 SkFlagInfo* info = new SkFlagInfo(name, shortName, kInt_FlagType, helpString, nullptr);
robertphillips5ce341f2015-09-18 09:04:43 -0700332 info->fIntValue = pInt;
333 *info->fIntValue = info->fDefaultInt = defaultValue;
334 return true;
335 }
336
scroggo@google.com58104a92013-04-24 19:25:26 +0000337 /**
338 * See comments for CreateBoolFlag.
339 */
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000340 static bool CreateDoubleFlag(const char* name, double* pDouble,
341 double defaultValue, const char* helpString) {
kkinnunen3e980c32015-12-23 01:33:00 -0800342 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kDouble_FlagType, helpString, nullptr);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000343 info->fDoubleValue = pDouble;
344 *info->fDoubleValue = info->fDefaultDouble = defaultValue;
345 return true;
346 }
347
348 /**
scroggo@google.com5dc4ca12013-03-21 13:10:59 +0000349 * Returns true if the string matches this flag.
350 * For a boolean flag, also sets the value, since a boolean flag can be set in a number of ways
351 * without looking at the following string:
352 * --name
353 * --noname
354 * --name=true
355 * --name=false
356 * --name=1
357 * --name=0
358 * --name=TRUE
359 * --name=FALSE
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000360 */
scroggo@google.com5dc4ca12013-03-21 13:10:59 +0000361 bool match(const char* string);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000362
363 FlagTypes getFlagType() const { return fFlagType; }
364
365 void resetStrings() {
366 if (kString_FlagType == fFlagType) {
367 fStrings->reset();
368 } else {
mtklein@google.com330313a2013-08-22 15:37:26 +0000369 SkDEBUGFAIL("Can only call resetStrings on kString_FlagType");
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000370 }
371 }
372
373 void append(const char* string) {
374 if (kString_FlagType == fFlagType) {
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000375 fStrings->append(string);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000376 } else {
mtklein@google.com330313a2013-08-22 15:37:26 +0000377 SkDEBUGFAIL("Can only append to kString_FlagType");
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000378 }
379 }
380
381 void setInt(int32_t value) {
382 if (kInt_FlagType == fFlagType) {
383 *fIntValue = value;
384 } else {
mtklein@google.com330313a2013-08-22 15:37:26 +0000385 SkDEBUGFAIL("Can only call setInt on kInt_FlagType");
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000386 }
387 }
388
389 void setDouble(double value) {
390 if (kDouble_FlagType == fFlagType) {
391 *fDoubleValue = value;
392 } else {
mtklein@google.com330313a2013-08-22 15:37:26 +0000393 SkDEBUGFAIL("Can only call setDouble on kDouble_FlagType");
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000394 }
395 }
396
scroggo@google.com5dc4ca12013-03-21 13:10:59 +0000397 void setBool(bool value) {
398 if (kBool_FlagType == fFlagType) {
399 *fBoolValue = value;
400 } else {
mtklein@google.com330313a2013-08-22 15:37:26 +0000401 SkDEBUGFAIL("Can only call setBool on kBool_FlagType");
scroggo@google.com5dc4ca12013-03-21 13:10:59 +0000402 }
403 }
404
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000405 SkFlagInfo* next() { return fNext; }
406
407 const SkString& name() const { return fName; }
408
scroggo@google.com8366df02013-03-20 19:50:41 +0000409 const SkString& shortName() const { return fShortName; }
410
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000411 const SkString& help() const { return fHelpString; }
kkinnunen3e980c32015-12-23 01:33:00 -0800412 const SkString& extendedHelp() const { return fExtendedHelpString; }
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000413
414 SkString defaultValue() const {
415 SkString result;
416 switch (fFlagType) {
417 case SkFlagInfo::kBool_FlagType:
418 result.printf("%s", fDefaultBool ? "true" : "false");
419 break;
420 case SkFlagInfo::kString_FlagType:
421 return fDefaultString;
422 case SkFlagInfo::kInt_FlagType:
423 result.printf("%i", fDefaultInt);
424 break;
425 case SkFlagInfo::kDouble_FlagType:
426 result.printf("%2.2f", fDefaultDouble);
427 break;
428 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000429 SkDEBUGFAIL("Invalid flag type");
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000430 }
431 return result;
432 }
433
434 SkString typeAsString() const {
435 switch (fFlagType) {
436 case SkFlagInfo::kBool_FlagType:
437 return SkString("bool");
438 case SkFlagInfo::kString_FlagType:
439 return SkString("string");
440 case SkFlagInfo::kInt_FlagType:
441 return SkString("int");
442 case SkFlagInfo::kDouble_FlagType:
443 return SkString("double");
444 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000445 SkDEBUGFAIL("Invalid flag type");
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000446 return SkString();
447 }
448 }
449
450private:
kkinnunen3e980c32015-12-23 01:33:00 -0800451 SkFlagInfo(const char* name, const char* shortName, FlagTypes type, const char* helpString,
452 const char* extendedHelpString)
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000453 : fName(name)
scroggo@google.com604e0c22013-04-09 21:25:46 +0000454 , fShortName(shortName)
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000455 , fFlagType(type)
456 , fHelpString(helpString)
kkinnunen3e980c32015-12-23 01:33:00 -0800457 , fExtendedHelpString(extendedHelpString)
halcanary96fcdcc2015-08-27 07:41:13 -0700458 , fBoolValue(nullptr)
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000459 , fDefaultBool(false)
halcanary96fcdcc2015-08-27 07:41:13 -0700460 , fIntValue(nullptr)
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000461 , fDefaultInt(0)
halcanary96fcdcc2015-08-27 07:41:13 -0700462 , fDoubleValue(nullptr)
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000463 , fDefaultDouble(0)
halcanary96fcdcc2015-08-27 07:41:13 -0700464 , fStrings(nullptr) {
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000465 fNext = SkCommandLineFlags::gHead;
466 SkCommandLineFlags::gHead = this;
bsalomon49f085d2014-09-05 13:34:00 -0700467 SkASSERT(name && strlen(name) > 1);
halcanary96fcdcc2015-08-27 07:41:13 -0700468 SkASSERT(nullptr == shortName || 1 == strlen(shortName));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000469 }
scroggo@google.com58104a92013-04-24 19:25:26 +0000470
471 /**
472 * Set a StringArray to hold the values stored in defaultStrings.
473 * @param array The StringArray to modify.
474 * @param defaultStrings Space separated list of strings that should be inserted into array
475 * individually.
476 */
477 static void SetDefaultStrings(SkCommandLineFlags::StringArray* array,
478 const char* defaultStrings);
479
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000480 // Name of the flag, without initial dashes
481 SkString fName;
scroggo@google.com09fd4d22013-03-20 14:20:18 +0000482 SkString fShortName;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000483 FlagTypes fFlagType;
484 SkString fHelpString;
kkinnunen3e980c32015-12-23 01:33:00 -0800485 SkString fExtendedHelpString;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000486 bool* fBoolValue;
487 bool fDefaultBool;
488 int32_t* fIntValue;
489 int32_t fDefaultInt;
490 double* fDoubleValue;
491 double fDefaultDouble;
scroggo@google.comb7dbf632013-04-23 15:38:09 +0000492 SkCommandLineFlags::StringArray* fStrings;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000493 // Both for the help string and in case fStrings is empty.
494 SkString fDefaultString;
495
496 // In order to keep a linked list.
497 SkFlagInfo* fNext;
498};
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000499#endif // SK_COMMAND_LINE_FLAGS_H