Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Macros
CommandLineFlags.h File Reference
#include "include/core/SkString.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTDArray.h"
#include "src/core/SkTHash.h"

Go to the source code of this file.

Classes

class  CommandLineFlags
 
class  CommandLineFlags::StringArray
 
class  SkFlagInfo
 

Macros

#define TO_STRING2(s)   #s
 
#define TO_STRING(s)   TO_STRING2(s)
 
#define DEFINE_bool(name, defaultValue, helpString)
 
#define DEFINE_bool2(name, shortName, defaultValue, helpString)
 
#define DECLARE_bool(name)   extern bool FLAGS_##name;
 
#define DEFINE_string(name, defaultValue, helpString)
 
#define DEFINE_extended_string(name, defaultValue, helpString, extendedHelpString)
 
#define DEFINE_string2(name, shortName, defaultValue, helpString)
 
#define DECLARE_string(name)   extern CommandLineFlags::StringArray FLAGS_##name;
 
#define DEFINE_int(name, defaultValue, helpString)
 
#define DEFINE_int_2(name, shortName, defaultValue, helpString)
 
#define DECLARE_int(name)   extern int FLAGS_##name;
 
#define DEFINE_double(name, defaultValue, helpString)
 
#define DECLARE_double(name)   extern double FLAGS_##name;
 

Macro Definition Documentation

◆ DECLARE_bool

#define DECLARE_bool (   name)    extern bool FLAGS_##name;

Definition at line 230 of file CommandLineFlags.h.

◆ DECLARE_double

#define DECLARE_double (   name)    extern double FLAGS_##name;

Definition at line 271 of file CommandLineFlags.h.

◆ DECLARE_int

#define DECLARE_int (   name)    extern int FLAGS_##name;

Definition at line 264 of file CommandLineFlags.h.

◆ DECLARE_string

#define DECLARE_string (   name)    extern CommandLineFlags::StringArray FLAGS_##name;

Definition at line 252 of file CommandLineFlags.h.

◆ DEFINE_bool

#define DEFINE_bool (   name,
  defaultValue,
  helpString 
)
Value:
bool FLAGS_##name; \
[[maybe_unused]] static bool unused_##name = SkFlagInfo::CreateBoolFlag( \
TO_STRING(name), nullptr, &FLAGS_##name, defaultValue, helpString)
#define TO_STRING(s)
static bool CreateBoolFlag(const char *name, const char *shortName, bool *pBool, bool defaultValue, const char *helpString)
const char * name
Definition fuchsia.cc:50

Definition at line 218 of file CommandLineFlags.h.

272 {
273public:
274 enum FlagTypes {
275 kBool_FlagType,
276 kString_FlagType,
277 kInt_FlagType,
278 kDouble_FlagType,
279 };
280
281 /**
282 * Each Create<Type>Flag function creates an SkFlagInfo of the specified type. The SkFlagInfo
283 * object is appended to a list, which is deleted when CommandLineFlags::Parse is called.
284 * Therefore, each call should be made before the call to ::Parse. They are not intended
285 * to be called directly. Instead, use the macros described above.
286 * @param name Long version (at least 2 characters) of the name of the flag. This name can
287 * be referenced on the command line as "--name" to set the value of this flag.
288 * @param shortName Short version (one character) of the name of the flag. This name can
289 * be referenced on the command line as "-shortName" to set the value of this flag.
290 * @param p<Type> Pointer to a global variable which holds the value set by CommandLineFlags.
291 * @param defaultValue The default value of this flag. The variable pointed to by p<Type> will
292 * be set to this value initially. This is also displayed as part of the help output.
293 * @param helpString Explanation of what this flag changes in the program.
294 */
295 static bool CreateBoolFlag(const char* name,
296 const char* shortName,
297 bool* pBool,
298 bool defaultValue,
299 const char* helpString) {
300 SkFlagInfo* info = new SkFlagInfo(name, shortName, kBool_FlagType, helpString, nullptr);
301 info->fBoolValue = pBool;
302 *info->fBoolValue = info->fDefaultBool = defaultValue;
303 return true;
304 }
305
306 /**
307 * See comments for CreateBoolFlag.
308 * @param pStrings Unlike the others, this is a pointer to an array of values.
309 * @param defaultValue Thise default will be parsed so that strings separated by spaces
310 * will be added to pStrings.
311 */
312 static bool CreateStringFlag(const char* name,
313 const char* shortName,
315 const char* defaultValue,
316 const char* helpString,
317 const char* extendedHelpString);
318
319 /**
320 * See comments for CreateBoolFlag.
321 */
322 static bool CreateIntFlag(const char* name,
323 int* pInt,
324 int defaultValue,
325 const char* helpString) {
326 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kInt_FlagType, helpString, nullptr);
327 info->fIntValue = pInt;
328 *info->fIntValue = info->fDefaultInt = defaultValue;
329 return true;
330 }
331
332 static bool CreateIntFlag(const char* name,
333 const char* shortName,
334 int* pInt,
335 int defaultValue,
336 const char* helpString) {
337 SkFlagInfo* info = new SkFlagInfo(name, shortName, kInt_FlagType, helpString, nullptr);
338 info->fIntValue = pInt;
339 *info->fIntValue = info->fDefaultInt = defaultValue;
340 return true;
341 }
342
343 /**
344 * See comments for CreateBoolFlag.
345 */
346 static bool CreateDoubleFlag(const char* name,
347 double* pDouble,
348 double defaultValue,
349 const char* helpString) {
350 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kDouble_FlagType, helpString, nullptr);
351 info->fDoubleValue = pDouble;
352 *info->fDoubleValue = info->fDefaultDouble = defaultValue;
353 return true;
354 }
355
356 /**
357 * Returns true if the string matches this flag.
358 * For a boolean flag, also sets the value, since a boolean flag can be set in a number of ways
359 * without looking at the following string:
360 * --name
361 * --noname
362 * --name=true
363 * --name=false
364 * --name=1
365 * --name=0
366 * --name=TRUE
367 * --name=FALSE
368 */
369 bool match(const char* string);
370
371 FlagTypes getFlagType() const { return fFlagType; }
372
373 void resetStrings() {
374 if (kString_FlagType == fFlagType) {
375 fStrings->reset();
376 } else {
377 SkDEBUGFAIL("Can only call resetStrings on kString_FlagType");
378 }
379 }
380
381 void append(const char* string) {
382 if (kString_FlagType == fFlagType) {
383 fStrings->append(string);
384 } else {
385 SkDEBUGFAIL("Can only append to kString_FlagType");
386 }
387 }
388
389 void setInt(int value) {
390 if (kInt_FlagType == fFlagType) {
391 *fIntValue = value;
392 } else {
393 SkDEBUGFAIL("Can only call setInt on kInt_FlagType");
394 }
395 }
396
397 void setDouble(double value) {
398 if (kDouble_FlagType == fFlagType) {
399 *fDoubleValue = value;
400 } else {
401 SkDEBUGFAIL("Can only call setDouble on kDouble_FlagType");
402 }
403 }
404
405 void setBool(bool value) {
406 if (kBool_FlagType == fFlagType) {
407 *fBoolValue = value;
408 } else {
409 SkDEBUGFAIL("Can only call setBool on kBool_FlagType");
410 }
411 }
412
413 SkFlagInfo* next() { return fNext; }
414
415 const SkString& name() const { return fName; }
416
417 const SkString& shortName() const { return fShortName; }
418
419 const SkString& help() const { return fHelpString; }
420 const SkString& extendedHelp() const { return fExtendedHelpString; }
421
422 SkString defaultValue() const {
424 switch (fFlagType) {
426 result.printf("%s", fDefaultBool ? "true" : "false");
427 break;
428 case SkFlagInfo::kString_FlagType: return fDefaultString;
429 case SkFlagInfo::kInt_FlagType: result.printf("%i", fDefaultInt); break;
430 case SkFlagInfo::kDouble_FlagType: result.printf("%2.2f", fDefaultDouble); break;
431 default: SkDEBUGFAIL("Invalid flag type");
432 }
433 return result;
434 }
435
436 SkString typeAsString() const {
437 switch (fFlagType) {
438 case SkFlagInfo::kBool_FlagType: return SkString("bool");
439 case SkFlagInfo::kString_FlagType: return SkString("string");
440 case SkFlagInfo::kInt_FlagType: return SkString("int");
441 case SkFlagInfo::kDouble_FlagType: return SkString("double");
442 default: SkDEBUGFAIL("Invalid flag type"); return SkString();
443 }
444 }
445
446private:
447 SkFlagInfo(const char* name,
448 const char* shortName,
449 FlagTypes type,
450 const char* helpString,
451 const char* extendedHelpString)
452 : fName(name)
453 , fShortName(shortName)
454 , fFlagType(type)
455 , fHelpString(helpString)
456 , fExtendedHelpString(extendedHelpString)
457 , fBoolValue(nullptr)
458 , fDefaultBool(false)
459 , fIntValue(nullptr)
460 , fDefaultInt(0)
461 , fDoubleValue(nullptr)
462 , fDefaultDouble(0)
463 , fStrings(nullptr) {
464 fNext = CommandLineFlags::gHead;
465 CommandLineFlags::gHead = this;
466 SkASSERT(name && strlen(name) > 1);
467 SkASSERT(nullptr == shortName || 1 == strlen(shortName));
468 }
469
470 /**
471 * Set a StringArray to hold the values stored in defaultStrings.
472 * @param array The StringArray to modify.
473 * @param defaultStrings Space separated list of strings that should be inserted into array
474 * individually.
475 */
476 static void SetDefaultStrings(CommandLineFlags::StringArray* array, const char* defaultStrings);
477
478 // Name of the flag, without initial dashes
480 SkString fShortName;
481 FlagTypes fFlagType;
482 SkString fHelpString;
483 SkString fExtendedHelpString;
484 bool* fBoolValue;
485 bool fDefaultBool;
486 int* fIntValue;
487 int fDefaultInt;
488 double* fDoubleValue;
489 double fDefaultDouble;
491 // Both for the help string and in case fStrings is empty.
492 SkString fDefaultString;
493
494 // In order to keep a linked list.
496};
497#endif // SK_COMMAND_LINE_FLAGS_H
static bool match(const char *needle, const char *haystack)
Definition DM.cpp:1132
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
Instance * fNext
const char * fName
static float next(float f)
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118
#define SkASSERT(cond)
Definition SkAssert.h:116
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
static void append(char **dst, size_t *count, const char *src, size_t n)
Definition editor.cpp:211
uint8_t value
GAsyncResult * result
help
Definition zip.py:79

◆ DEFINE_bool2

#define DEFINE_bool2 (   name,
  shortName,
  defaultValue,
  helpString 
)
Value:
bool FLAGS_##name; \
[[maybe_unused]] static bool unused_##name = SkFlagInfo::CreateBoolFlag( \
TO_STRING(name), TO_STRING(shortName), &FLAGS_##name, defaultValue, helpString)

Definition at line 225 of file CommandLineFlags.h.

◆ DEFINE_double

#define DEFINE_double (   name,
  defaultValue,
  helpString 
)
Value:
double FLAGS_##name; \
[[maybe_unused]] static bool unused_##name = \
SkFlagInfo::CreateDoubleFlag(TO_STRING(name), &FLAGS_##name, defaultValue, helpString)

Definition at line 266 of file CommandLineFlags.h.

◆ DEFINE_extended_string

#define DEFINE_extended_string (   name,
  defaultValue,
  helpString,
  extendedHelpString 
)
Value:
[[maybe_unused]] static bool unused_##name = SkFlagInfo::CreateStringFlag( \
TO_STRING(name), nullptr, &FLAGS_##name, defaultValue, helpString, extendedHelpString)
static bool CreateStringFlag(const char *name, const char *shortName, CommandLineFlags::StringArray *pStrings, const char *defaultValue, const char *helpString, const char *extendedHelpString)

Definition at line 236 of file CommandLineFlags.h.

◆ DEFINE_int

#define DEFINE_int (   name,
  defaultValue,
  helpString 
)
Value:
int FLAGS_##name; \
[[maybe_unused]] static bool unused_##name = \
SkFlagInfo::CreateIntFlag(TO_STRING(name), &FLAGS_##name, defaultValue, helpString)

Definition at line 254 of file CommandLineFlags.h.

◆ DEFINE_int_2

#define DEFINE_int_2 (   name,
  shortName,
  defaultValue,
  helpString 
)
Value:
int FLAGS_##name; \
[[maybe_unused]] static bool unused_##name = SkFlagInfo::CreateIntFlag( \
TO_STRING(name), TO_STRING(shortName), &FLAGS_##name, defaultValue, helpString)
static bool CreateIntFlag(const char *name, int *pInt, int defaultValue, const char *helpString)

Definition at line 259 of file CommandLineFlags.h.

◆ DEFINE_string

#define DEFINE_string (   name,
  defaultValue,
  helpString 
)
Value:
[[maybe_unused]] static bool unused_##name = SkFlagInfo::CreateStringFlag( \
TO_STRING(name), nullptr, &FLAGS_##name, defaultValue, helpString, nullptr)

Definition at line 232 of file CommandLineFlags.h.

◆ DEFINE_string2

#define DEFINE_string2 (   name,
  shortName,
  defaultValue,
  helpString 
)
Value:
[[maybe_unused]] static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
TO_STRING(shortName),\
&FLAGS_##name, \
defaultValue, \
helpString, \
nullptr)

Definition at line 243 of file CommandLineFlags.h.

◆ TO_STRING

#define TO_STRING (   s)    TO_STRING2(s)

Definition at line 216 of file CommandLineFlags.h.

◆ TO_STRING2

#define TO_STRING2 (   s)    #s

Definition at line 215 of file CommandLineFlags.h.