Flutter Engine
The Flutter Engine
Public Member Functions | Friends | List of all members
CommandLineFlags::StringArray Class Reference

#include <CommandLineFlags.h>

Public Member Functions

 StringArray ()
 
 StringArray (const skia_private::TArray< SkString > &strings)
 
const char * operator[] (int i) const
 
int size () const
 
bool isEmpty () const
 
bool contains (const char *string) const
 
void set (int i, const char *str)
 
const SkStringbegin () const
 
const SkStringend () const
 
template<class E >
SkString parseAndValidate (const char *name, const skia_private::THashMap< SkString, E > &possibleValues, E *out) const
 

Friends

class SkFlagInfo
 

Detailed Description

Custom class for holding the arguments for a string flag. Publicly only has accessors so the strings cannot be modified.

Definition at line 127 of file CommandLineFlags.h.

Constructor & Destructor Documentation

◆ StringArray() [1/2]

CommandLineFlags::StringArray::StringArray ( )
inline

Definition at line 129 of file CommandLineFlags.h.

129{}

◆ StringArray() [2/2]

CommandLineFlags::StringArray::StringArray ( const skia_private::TArray< SkString > &  strings)
inlineexplicit

Definition at line 130 of file CommandLineFlags.h.

130: fStrings(strings) {}

Member Function Documentation

◆ begin()

const SkString * CommandLineFlags::StringArray::begin ( ) const
inline

Definition at line 160 of file CommandLineFlags.h.

160{ return fStrings.begin(); }

◆ contains()

bool CommandLineFlags::StringArray::contains ( const char *  string) const
inline

Returns true iff string is equal to one of the strings in this array.

Definition at line 143 of file CommandLineFlags.h.

143 {
144 for (int i = 0; i < fStrings.size(); i++) {
145 if (fStrings[i].equals(string)) {
146 return true;
147 }
148 }
149 return false;
150 }
bool equals(SkDrawable *a, SkDrawable *b)
int size() const
Definition: SkTArray.h:421

◆ end()

const SkString * CommandLineFlags::StringArray::end ( ) const
inline

Definition at line 161 of file CommandLineFlags.h.

161{ return fStrings.end(); }

◆ isEmpty()

bool CommandLineFlags::StringArray::isEmpty ( ) const
inline

Definition at line 138 of file CommandLineFlags.h.

138{ return this->size() == 0; }

◆ operator[]()

const char * CommandLineFlags::StringArray::operator[] ( int  i) const
inline

Definition at line 131 of file CommandLineFlags.h.

131 {
132 SkASSERT(i >= 0 && i < fStrings.size());
133 return fStrings[i].c_str();
134 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ parseAndValidate()

template<class E >
SkString CommandLineFlags::StringArray::parseAndValidate ( const char *  name,
const skia_private::THashMap< SkString, E > &  possibleValues,
E out 
) const
inline

Parses and validates a string flag that requires exactly one value out of a set of possible values. Returns a non-empty message in the case of errors.

Definition at line 168 of file CommandLineFlags.h.

170 {
171 if (size() == 0) {
172 return SkStringPrintf("Flag %s is required.", name);
173 }
174 if (size() != 1) {
175 return SkStringPrintf("Flag %s takes 1 value, got %d.", name, size());
176 }
177 E* found = possibleValues.find(SkString(operator[](0)));
178 if (found != nullptr) {
179 *out = *found;
180 return SkString();
181 }
182 return SkStringPrintf("Unknown value for flag %s: %s.", name, operator[](0));
183 }
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
V * find(const K &key) const
Definition: SkTHash.h:494
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ set()

void CommandLineFlags::StringArray::set ( int  i,
const char *  str 
)
inline

Definition at line 152 of file CommandLineFlags.h.

152 {
153 if (i >= fStrings.size()) {
154 this->append(str);
155 return;
156 }
157 fStrings[i].set(str);
158 }

◆ size()

int CommandLineFlags::StringArray::size ( ) const
inline

Definition at line 136 of file CommandLineFlags.h.

136{ return fStrings.size(); }

Friends And Related Function Documentation

◆ SkFlagInfo

friend class SkFlagInfo
friend

Definition at line 194 of file CommandLineFlags.h.


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