Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
SkFlagInfo Class Reference

#include <CommandLineFlags.h>

Public Types

enum  FlagTypes { kBool_FlagType , kString_FlagType , kInt_FlagType , kDouble_FlagType }
 

Public Member Functions

bool match (const char *string)
 
FlagTypes getFlagType () const
 
void resetStrings ()
 
void append (const char *string)
 
void setInt (int value)
 
void setDouble (double value)
 
void setBool (bool value)
 
SkFlagInfonext ()
 
const SkStringname () const
 
const SkStringshortName () const
 
const SkStringhelp () const
 
const SkStringextendedHelp () const
 
SkString defaultValue () const
 
SkString typeAsString () const
 

Static Public Member Functions

static bool CreateBoolFlag (const char *name, const char *shortName, bool *pBool, bool defaultValue, const char *helpString)
 
static bool CreateStringFlag (const char *name, const char *shortName, CommandLineFlags::StringArray *pStrings, const char *defaultValue, const char *helpString, const char *extendedHelpString)
 
static bool CreateIntFlag (const char *name, int *pInt, int defaultValue, const char *helpString)
 
static bool CreateIntFlag (const char *name, const char *shortName, int *pInt, int defaultValue, const char *helpString)
 
static bool CreateDoubleFlag (const char *name, double *pDouble, double defaultValue, const char *helpString)
 

Detailed Description

Definition at line 273 of file CommandLineFlags.h.

Member Enumeration Documentation

◆ FlagTypes

Enumerator
kBool_FlagType 
kString_FlagType 
kInt_FlagType 
kDouble_FlagType 

Definition at line 275 of file CommandLineFlags.h.

Member Function Documentation

◆ append()

void SkFlagInfo::append ( const char *  string)
inline

Definition at line 382 of file CommandLineFlags.h.

382 {
383 if (kString_FlagType == fFlagType) {
384 fStrings->append(string);
385 } else {
386 SkDEBUGFAIL("Can only append to kString_FlagType");
387 }
388 }
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118

◆ CreateBoolFlag()

static bool SkFlagInfo::CreateBoolFlag ( const char *  name,
const char *  shortName,
bool *  pBool,
bool  defaultValue,
const char *  helpString 
)
inlinestatic

Each Create<Type>Flag function creates an SkFlagInfo of the specified type. The SkFlagInfo object is appended to a list, which is deleted when CommandLineFlags::Parse is called. Therefore, each call should be made before the call to ::Parse. They are not intended to be called directly. Instead, use the macros described above.

Parameters
nameLong version (at least 2 characters) of the name of the flag. This name can be referenced on the command line as "--name" to set the value of this flag.
shortNameShort version (one character) of the name of the flag. This name can be referenced on the command line as "-shortName" to set the value of this flag.
p<Type>Pointer to a global variable which holds the value set by CommandLineFlags.
defaultValueThe default value of this flag. The variable pointed to by p<Type> will be set to this value initially. This is also displayed as part of the help output.
helpStringExplanation of what this flag changes in the program.

Definition at line 296 of file CommandLineFlags.h.

300 {
301 SkFlagInfo* info = new SkFlagInfo(name, shortName, kBool_FlagType, helpString, nullptr);
302 info->fBoolValue = pBool;
303 *info->fBoolValue = info->fDefaultBool = defaultValue;
304 return true;
305 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
const SkString & name() const
const SkString & shortName() const
SkString defaultValue() const

◆ CreateDoubleFlag()

static bool SkFlagInfo::CreateDoubleFlag ( const char *  name,
double *  pDouble,
double  defaultValue,
const char *  helpString 
)
inlinestatic

See comments for CreateBoolFlag.

Definition at line 347 of file CommandLineFlags.h.

350 {
351 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kDouble_FlagType, helpString, nullptr);
352 info->fDoubleValue = pDouble;
353 *info->fDoubleValue = info->fDefaultDouble = defaultValue;
354 return true;
355 }

◆ CreateIntFlag() [1/2]

static bool SkFlagInfo::CreateIntFlag ( const char *  name,
const char *  shortName,
int pInt,
int  defaultValue,
const char *  helpString 
)
inlinestatic

Definition at line 333 of file CommandLineFlags.h.

337 {
338 SkFlagInfo* info = new SkFlagInfo(name, shortName, kInt_FlagType, helpString, nullptr);
339 info->fIntValue = pInt;
340 *info->fIntValue = info->fDefaultInt = defaultValue;
341 return true;
342 }

◆ CreateIntFlag() [2/2]

static bool SkFlagInfo::CreateIntFlag ( const char *  name,
int pInt,
int  defaultValue,
const char *  helpString 
)
inlinestatic

See comments for CreateBoolFlag.

Definition at line 323 of file CommandLineFlags.h.

326 {
327 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kInt_FlagType, helpString, nullptr);
328 info->fIntValue = pInt;
329 *info->fIntValue = info->fDefaultInt = defaultValue;
330 return true;
331 }

◆ CreateStringFlag()

bool SkFlagInfo::CreateStringFlag ( const char *  name,
const char *  shortName,
CommandLineFlags::StringArray pStrings,
const char *  defaultValue,
const char *  helpString,
const char *  extendedHelpString 
)
static

See comments for CreateBoolFlag.

Parameters
pStringsUnlike the others, this is a pointer to an array of values.
defaultValueThise default will be parsed so that strings separated by spaces will be added to pStrings.

Definition at line 16 of file CommandLineFlags.cpp.

21 {
23 new SkFlagInfo(name, shortName, kString_FlagType, helpString, extendedHelpString);
24 info->fDefaultString.set(defaultValue);
25
26 info->fStrings = pStrings;
27 SetDefaultStrings(pStrings, defaultValue);
28 return true;
29}

◆ defaultValue()

SkString SkFlagInfo::defaultValue ( ) const
inline

Definition at line 423 of file CommandLineFlags.h.

423 {
425 switch (fFlagType) {
427 result.printf("%s", fDefaultBool ? "true" : "false");
428 break;
429 case SkFlagInfo::kString_FlagType: return fDefaultString;
430 case SkFlagInfo::kInt_FlagType: result.printf("%i", fDefaultInt); break;
431 case SkFlagInfo::kDouble_FlagType: result.printf("%2.2f", fDefaultDouble); break;
432 default: SkDEBUGFAIL("Invalid flag type");
433 }
434 return result;
435 }
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
GAsyncResult * result

◆ extendedHelp()

const SkString & SkFlagInfo::extendedHelp ( ) const
inline

Definition at line 421 of file CommandLineFlags.h.

421{ return fExtendedHelpString; }

◆ getFlagType()

FlagTypes SkFlagInfo::getFlagType ( ) const
inline

Definition at line 372 of file CommandLineFlags.h.

372{ return fFlagType; }

◆ help()

const SkString & SkFlagInfo::help ( ) const
inline

Definition at line 420 of file CommandLineFlags.h.

420{ return fHelpString; }

◆ match()

bool SkFlagInfo::match ( const char *  string)

Returns true if the string matches this flag. For a boolean flag, also sets the value, since a boolean flag can be set in a number of ways without looking at the following string: –name –noname –name=true –name=false –name=1 –name=0 –name=TRUE –name=FALSE

Definition at line 92 of file CommandLineFlags.cpp.

92 {
93 if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
94 string++;
95 const SkString* compareName;
96 if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
97 string++;
98 // There were two dashes. Compare against full name.
99 compareName = &fName;
100 } else {
101 // One dash. Compare against the short name.
102 compareName = &fShortName;
103 }
104 if (kBool_FlagType == fFlagType) {
105 // In this case, go ahead and set the value.
106 if (compareName->equals(string)) {
107 *fBoolValue = true;
108 return true;
109 }
110 if (SkStrStartsWith(string, "no") && strlen(string) > 2) {
111 string += 2;
112 // Only allow "no" to be prepended to the full name.
113 if (fName.equals(string)) {
114 *fBoolValue = false;
115 return true;
116 }
117 return false;
118 }
119 int equalIndex = SkStrFind(string, "=");
120 if (equalIndex > 0) {
121 // The string has an equal sign. Check to see if the string matches.
122 SkString flag(string, equalIndex);
123 if (flag.equals(*compareName)) {
124 // Check to see if the remainder beyond the equal sign is true or false:
125 string += equalIndex + 1;
126 parse_bool_arg(string, fBoolValue);
127 return true;
128 } else {
129 return false;
130 }
131 }
132 }
133 return compareName->equals(string);
134 }
135
136 // Has no dash
137 return false;
138}
static bool parse_bool_arg(const char *string, bool *result)
static bool SkStrStartsWith(const char string[], const char prefixStr[])
Definition SkString.h:26
static int SkStrFind(const char string[], const char substring[])
Definition SkString.h:41
bool equals(const SkString &) const
Definition SkString.cpp:324
FlutterSemanticsFlag flag

◆ name()

const SkString & SkFlagInfo::name ( ) const
inline

Definition at line 416 of file CommandLineFlags.h.

416{ return fName; }

◆ next()

SkFlagInfo * SkFlagInfo::next ( )
inline

Definition at line 414 of file CommandLineFlags.h.

414{ return fNext; }

◆ resetStrings()

void SkFlagInfo::resetStrings ( )
inline

Definition at line 374 of file CommandLineFlags.h.

374 {
375 if (kString_FlagType == fFlagType) {
376 fStrings->reset();
377 } else {
378 SkDEBUGFAIL("Can only call resetStrings on kString_FlagType");
379 }
380 }

◆ setBool()

void SkFlagInfo::setBool ( bool  value)
inline

Definition at line 406 of file CommandLineFlags.h.

406 {
407 if (kBool_FlagType == fFlagType) {
408 *fBoolValue = value;
409 } else {
410 SkDEBUGFAIL("Can only call setBool on kBool_FlagType");
411 }
412 }
uint8_t value

◆ setDouble()

void SkFlagInfo::setDouble ( double  value)
inline

Definition at line 398 of file CommandLineFlags.h.

398 {
399 if (kDouble_FlagType == fFlagType) {
400 *fDoubleValue = value;
401 } else {
402 SkDEBUGFAIL("Can only call setDouble on kDouble_FlagType");
403 }
404 }

◆ setInt()

void SkFlagInfo::setInt ( int  value)
inline

Definition at line 390 of file CommandLineFlags.h.

390 {
391 if (kInt_FlagType == fFlagType) {
392 *fIntValue = value;
393 } else {
394 SkDEBUGFAIL("Can only call setInt on kInt_FlagType");
395 }
396 }

◆ shortName()

const SkString & SkFlagInfo::shortName ( ) const
inline

Definition at line 418 of file CommandLineFlags.h.

418{ return fShortName; }

◆ typeAsString()

SkString SkFlagInfo::typeAsString ( ) const
inline

Definition at line 437 of file CommandLineFlags.h.

437 {
438 switch (fFlagType) {
439 case SkFlagInfo::kBool_FlagType: return SkString("bool");
440 case SkFlagInfo::kString_FlagType: return SkString("string");
441 case SkFlagInfo::kInt_FlagType: return SkString("int");
442 case SkFlagInfo::kDouble_FlagType: return SkString("double");
443 default: SkDEBUGFAIL("Invalid flag type"); return SkString();
444 }
445 }

The documentation for this class was generated from the following files: