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 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 helpString) | 197 helpString) |
198 | 198 |
199 #define DECLARE_bool(name) extern bool FLAGS_##name; | 199 #define DECLARE_bool(name) extern bool FLAGS_##name; |
200 | 200 |
201 #define DEFINE_string(name, defaultValue, helpString) \ | 201 #define DEFINE_string(name, defaultValue, helpString) \ |
202 SkCommandLineFlags::StringArray FLAGS_##name; \ | 202 SkCommandLineFlags::StringArray FLAGS_##name; \ |
203 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(nam
e), \ | 203 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(nam
e), \ |
204 nullptr,
\ | 204 nullptr,
\ |
205 &FLAGS_##name
, \ | 205 &FLAGS_##name
, \ |
206 defaultValue,
\ | 206 defaultValue,
\ |
207 helpString) | 207 helpString, n
ullptr) |
| 208 #define DEFINE_extended_string(name, defaultValue, helpString, extendedHelpStrin
g) \ |
| 209 SkCommandLineFlags::StringArray FLAGS_##name;
\ |
| 210 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(nam
e), \ |
| 211 nullptr, \ |
| 212 &FLAGS_##name
, \ |
| 213 defaultValue,
\ |
| 214 helpString, \ |
| 215 extendedHelpS
tring) |
208 | 216 |
209 // string2 allows specifying a short name. There is an assert that shortName | 217 // string2 allows specifying a short name. There is an assert that shortName |
210 // is only 1 character. | 218 // is only 1 character. |
211 #define DEFINE_string2(name, shortName, defaultValue, helpString)
\ | 219 #define DEFINE_string2(name, shortName, defaultValue, helpString)
\ |
212 SkCommandLineFlags::StringArray FLAGS_##name;
\ | 220 SkCommandLineFlags::StringArray FLAGS_##name;
\ |
213 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(nam
e), \ | 221 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(nam
e), \ |
214 TO_STRING(sho
rtName), \ | 222 TO_STRING(sho
rtName), \ |
215 &FLAGS_##name
, \ | 223 &FLAGS_##name
, \ |
216 defaultValue,
\ | 224 defaultValue,
\ |
217 helpString) | 225 helpString, n
ullptr) |
218 | 226 |
219 #define DECLARE_string(name) extern SkCommandLineFlags::StringArray FLAGS_##name
; | 227 #define DECLARE_string(name) extern SkCommandLineFlags::StringArray FLAGS_##name
; |
220 | 228 |
221 | 229 |
222 | 230 |
223 | 231 |
224 #define DEFINE_int32(name, defaultValue, helpString) \ | 232 #define DEFINE_int32(name, defaultValue, helpString) \ |
225 int32_t FLAGS_##name; \ | 233 int32_t FLAGS_##name; \ |
226 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateIntFlag(TO_STRING(name),
\ | 234 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateIntFlag(TO_STRING(name),
\ |
227 &FLAGS_##name,
\ | 235 &FLAGS_##name,
\ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 * be referenced on the command line as "--name" to set the value of th
is flag. | 274 * be referenced on the command line as "--name" to set the value of th
is flag. |
267 * @param shortName Short version (one character) of the name of the flag.
This name can | 275 * @param shortName Short version (one character) of the name of the flag.
This name can |
268 * be referenced on the command line as "-shortName" to set the value o
f this flag. | 276 * be referenced on the command line as "-shortName" to set the value o
f this flag. |
269 * @param p<Type> Pointer to a global variable which holds the value set by
SkCommandLineFlags. | 277 * @param p<Type> Pointer to a global variable which holds the value set by
SkCommandLineFlags. |
270 * @param defaultValue The default value of this flag. The variable pointed
to by p<Type> will | 278 * @param defaultValue The default value of this flag. The variable pointed
to by p<Type> will |
271 * be set to this value initially. This is also displayed as part of th
e help output. | 279 * be set to this value initially. This is also displayed as part of th
e help output. |
272 * @param helpString Explanation of what this flag changes in the program. | 280 * @param helpString Explanation of what this flag changes in the program. |
273 */ | 281 */ |
274 static bool CreateBoolFlag(const char* name, const char* shortName, bool* pB
ool, | 282 static bool CreateBoolFlag(const char* name, const char* shortName, bool* pB
ool, |
275 bool defaultValue, const char* helpString) { | 283 bool defaultValue, const char* helpString) { |
276 SkFlagInfo* info = new SkFlagInfo(name, shortName, kBool_FlagType, helpS
tring); | 284 SkFlagInfo* info = new SkFlagInfo(name, shortName, kBool_FlagType, helpS
tring, nullptr); |
277 info->fBoolValue = pBool; | 285 info->fBoolValue = pBool; |
278 *info->fBoolValue = info->fDefaultBool = defaultValue; | 286 *info->fBoolValue = info->fDefaultBool = defaultValue; |
279 return true; | 287 return true; |
280 } | 288 } |
281 | 289 |
282 /** | 290 /** |
283 * See comments for CreateBoolFlag. | 291 * See comments for CreateBoolFlag. |
284 * @param pStrings Unlike the others, this is a pointer to an array of valu
es. | 292 * @param pStrings Unlike the others, this is a pointer to an array of valu
es. |
285 * @param defaultValue Thise default will be parsed so that strings separat
ed by spaces | 293 * @param defaultValue Thise default will be parsed so that strings separat
ed by spaces |
286 * will be added to pStrings. | 294 * will be added to pStrings. |
287 */ | 295 */ |
288 static bool CreateStringFlag(const char* name, const char* shortName, | 296 static bool CreateStringFlag(const char* name, const char* shortName, |
289 SkCommandLineFlags::StringArray* pStrings, | 297 SkCommandLineFlags::StringArray* pStrings, |
290 const char* defaultValue, const char* helpStrin
g); | 298 const char* defaultValue, const char* helpStrin
g, |
| 299 const char* extendedHelpString); |
291 | 300 |
292 /** | 301 /** |
293 * See comments for CreateBoolFlag. | 302 * See comments for CreateBoolFlag. |
294 */ | 303 */ |
295 static bool CreateIntFlag(const char* name, int32_t* pInt, | 304 static bool CreateIntFlag(const char* name, int32_t* pInt, |
296 int32_t defaultValue, const char* helpString) { | 305 int32_t defaultValue, const char* helpString) { |
297 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kInt_FlagType, helpStri
ng); | 306 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kInt_FlagType, helpStri
ng, nullptr); |
298 info->fIntValue = pInt; | 307 info->fIntValue = pInt; |
299 *info->fIntValue = info->fDefaultInt = defaultValue; | 308 *info->fIntValue = info->fDefaultInt = defaultValue; |
300 return true; | 309 return true; |
301 } | 310 } |
302 | 311 |
303 static bool CreateIntFlag(const char* name, const char* shortName, int32_t*
pInt, | 312 static bool CreateIntFlag(const char* name, const char* shortName, int32_t*
pInt, |
304 int32_t defaultValue, const char* helpString) { | 313 int32_t defaultValue, const char* helpString) { |
305 SkFlagInfo* info = new SkFlagInfo(name, shortName, kInt_FlagType, helpSt
ring); | 314 SkFlagInfo* info = new SkFlagInfo(name, shortName, kInt_FlagType, helpSt
ring, nullptr); |
306 info->fIntValue = pInt; | 315 info->fIntValue = pInt; |
307 *info->fIntValue = info->fDefaultInt = defaultValue; | 316 *info->fIntValue = info->fDefaultInt = defaultValue; |
308 return true; | 317 return true; |
309 } | 318 } |
310 | 319 |
311 /** | 320 /** |
312 * See comments for CreateBoolFlag. | 321 * See comments for CreateBoolFlag. |
313 */ | 322 */ |
314 static bool CreateDoubleFlag(const char* name, double* pDouble, | 323 static bool CreateDoubleFlag(const char* name, double* pDouble, |
315 double defaultValue, const char* helpString) { | 324 double defaultValue, const char* helpString) { |
316 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kDouble_FlagType, helpS
tring); | 325 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kDouble_FlagType, helpS
tring, nullptr); |
317 info->fDoubleValue = pDouble; | 326 info->fDoubleValue = pDouble; |
318 *info->fDoubleValue = info->fDefaultDouble = defaultValue; | 327 *info->fDoubleValue = info->fDefaultDouble = defaultValue; |
319 return true; | 328 return true; |
320 } | 329 } |
321 | 330 |
322 /** | 331 /** |
323 * Returns true if the string matches this flag. | 332 * Returns true if the string matches this flag. |
324 * For a boolean flag, also sets the value, since a boolean flag can be set
in a number of ways | 333 * For a boolean flag, also sets the value, since a boolean flag can be set
in a number of ways |
325 * without looking at the following string: | 334 * without looking at the following string: |
326 * --name | 335 * --name |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 } | 385 } |
377 } | 386 } |
378 | 387 |
379 SkFlagInfo* next() { return fNext; } | 388 SkFlagInfo* next() { return fNext; } |
380 | 389 |
381 const SkString& name() const { return fName; } | 390 const SkString& name() const { return fName; } |
382 | 391 |
383 const SkString& shortName() const { return fShortName; } | 392 const SkString& shortName() const { return fShortName; } |
384 | 393 |
385 const SkString& help() const { return fHelpString; } | 394 const SkString& help() const { return fHelpString; } |
| 395 const SkString& extendedHelp() const { return fExtendedHelpString; } |
386 | 396 |
387 SkString defaultValue() const { | 397 SkString defaultValue() const { |
388 SkString result; | 398 SkString result; |
389 switch (fFlagType) { | 399 switch (fFlagType) { |
390 case SkFlagInfo::kBool_FlagType: | 400 case SkFlagInfo::kBool_FlagType: |
391 result.printf("%s", fDefaultBool ? "true" : "false"); | 401 result.printf("%s", fDefaultBool ? "true" : "false"); |
392 break; | 402 break; |
393 case SkFlagInfo::kString_FlagType: | 403 case SkFlagInfo::kString_FlagType: |
394 return fDefaultString; | 404 return fDefaultString; |
395 case SkFlagInfo::kInt_FlagType: | 405 case SkFlagInfo::kInt_FlagType: |
(...skipping 18 matching lines...) Expand all Loading... |
414 return SkString("int"); | 424 return SkString("int"); |
415 case SkFlagInfo::kDouble_FlagType: | 425 case SkFlagInfo::kDouble_FlagType: |
416 return SkString("double"); | 426 return SkString("double"); |
417 default: | 427 default: |
418 SkDEBUGFAIL("Invalid flag type"); | 428 SkDEBUGFAIL("Invalid flag type"); |
419 return SkString(); | 429 return SkString(); |
420 } | 430 } |
421 } | 431 } |
422 | 432 |
423 private: | 433 private: |
424 SkFlagInfo(const char* name, const char* shortName, FlagTypes type, const ch
ar* helpString) | 434 SkFlagInfo(const char* name, const char* shortName, FlagTypes type, const ch
ar* helpString, const char* extendedHelpString) |
425 : fName(name) | 435 : fName(name) |
426 , fShortName(shortName) | 436 , fShortName(shortName) |
427 , fFlagType(type) | 437 , fFlagType(type) |
428 , fHelpString(helpString) | 438 , fHelpString(helpString) |
| 439 , fExtendedHelpString(extendedHelpString) |
429 , fBoolValue(nullptr) | 440 , fBoolValue(nullptr) |
430 , fDefaultBool(false) | 441 , fDefaultBool(false) |
431 , fIntValue(nullptr) | 442 , fIntValue(nullptr) |
432 , fDefaultInt(0) | 443 , fDefaultInt(0) |
433 , fDoubleValue(nullptr) | 444 , fDoubleValue(nullptr) |
434 , fDefaultDouble(0) | 445 , fDefaultDouble(0) |
435 , fStrings(nullptr) { | 446 , fStrings(nullptr) { |
436 fNext = SkCommandLineFlags::gHead; | 447 fNext = SkCommandLineFlags::gHead; |
437 SkCommandLineFlags::gHead = this; | 448 SkCommandLineFlags::gHead = this; |
438 SkASSERT(name && strlen(name) > 1); | 449 SkASSERT(name && strlen(name) > 1); |
439 SkASSERT(nullptr == shortName || 1 == strlen(shortName)); | 450 SkASSERT(nullptr == shortName || 1 == strlen(shortName)); |
440 } | 451 } |
441 | 452 |
442 /** | 453 /** |
443 * Set a StringArray to hold the values stored in defaultStrings. | 454 * Set a StringArray to hold the values stored in defaultStrings. |
444 * @param array The StringArray to modify. | 455 * @param array The StringArray to modify. |
445 * @param defaultStrings Space separated list of strings that should be ins
erted into array | 456 * @param defaultStrings Space separated list of strings that should be ins
erted into array |
446 * individually. | 457 * individually. |
447 */ | 458 */ |
448 static void SetDefaultStrings(SkCommandLineFlags::StringArray* array, | 459 static void SetDefaultStrings(SkCommandLineFlags::StringArray* array, |
449 const char* defaultStrings); | 460 const char* defaultStrings); |
450 | 461 |
451 // Name of the flag, without initial dashes | 462 // Name of the flag, without initial dashes |
452 SkString fName; | 463 SkString fName; |
453 SkString fShortName; | 464 SkString fShortName; |
454 FlagTypes fFlagType; | 465 FlagTypes fFlagType; |
455 SkString fHelpString; | 466 SkString fHelpString; |
| 467 SkString fExtendedHelpString; |
456 bool* fBoolValue; | 468 bool* fBoolValue; |
457 bool fDefaultBool; | 469 bool fDefaultBool; |
458 int32_t* fIntValue; | 470 int32_t* fIntValue; |
459 int32_t fDefaultInt; | 471 int32_t fDefaultInt; |
460 double* fDoubleValue; | 472 double* fDoubleValue; |
461 double fDefaultDouble; | 473 double fDefaultDouble; |
462 SkCommandLineFlags::StringArray* fStrings; | 474 SkCommandLineFlags::StringArray* fStrings; |
463 // Both for the help string and in case fStrings is empty. | 475 // Both for the help string and in case fStrings is empty. |
464 SkString fDefaultString; | 476 SkString fDefaultString; |
465 | 477 |
466 // In order to keep a linked list. | 478 // In order to keep a linked list. |
467 SkFlagInfo* fNext; | 479 SkFlagInfo* fNext; |
468 }; | 480 }; |
469 #endif // SK_COMMAND_LINE_FLAGS_H | 481 #endif // SK_COMMAND_LINE_FLAGS_H |
OLD | NEW |