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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // For access to gHead. | 174 // For access to gHead. |
175 friend class SkFlagInfo; | 175 friend class SkFlagInfo; |
176 }; | 176 }; |
177 | 177 |
178 #define TO_STRING2(s) #s | 178 #define TO_STRING2(s) #s |
179 #define TO_STRING(s) TO_STRING2(s) | 179 #define TO_STRING(s) TO_STRING2(s) |
180 | 180 |
181 #define DEFINE_bool(name, defaultValue, helpString) \ | 181 #define DEFINE_bool(name, defaultValue, helpString) \ |
182 bool FLAGS_##name; \ | 182 bool FLAGS_##name; \ |
183 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name)
, \ | 183 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name)
, \ |
184 NULL,
\ | 184 nullptr,
\ |
185 &FLAGS_##name,
\ | 185 &FLAGS_##name,
\ |
186 defaultValue,
\ | 186 defaultValue,
\ |
187 helpString) | 187 helpString) |
188 | 188 |
189 // bool 2 allows specifying a short name. No check is done to ensure that shortN
ame | 189 // bool 2 allows specifying a short name. No check is done to ensure that shortN
ame |
190 // is actually shorter than name. | 190 // is actually shorter than name. |
191 #define DEFINE_bool2(name, shortName, defaultValue, helpString) \ | 191 #define DEFINE_bool2(name, shortName, defaultValue, helpString) \ |
192 bool FLAGS_##name; \ | 192 bool FLAGS_##name; \ |
193 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name)
, \ | 193 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name)
, \ |
194 TO_STRING(short
Name),\ | 194 TO_STRING(short
Name),\ |
195 &FLAGS_##name,
\ | 195 &FLAGS_##name,
\ |
196 defaultValue,
\ | 196 defaultValue,
\ |
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 NULL,
\ | 204 nullptr,
\ |
205 &FLAGS_##name
, \ | 205 &FLAGS_##name
, \ |
206 defaultValue,
\ | 206 defaultValue,
\ |
207 helpString) | 207 helpString) |
208 | 208 |
209 // string2 allows specifying a short name. There is an assert that shortName | 209 // string2 allows specifying a short name. There is an assert that shortName |
210 // is only 1 character. | 210 // is only 1 character. |
211 #define DEFINE_string2(name, shortName, defaultValue, helpString)
\ | 211 #define DEFINE_string2(name, shortName, defaultValue, helpString)
\ |
212 SkCommandLineFlags::StringArray FLAGS_##name;
\ | 212 SkCommandLineFlags::StringArray FLAGS_##name;
\ |
213 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(nam
e), \ | 213 SK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(nam
e), \ |
214 TO_STRING(sho
rtName), \ | 214 TO_STRING(sho
rtName), \ |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 */ | 276 */ |
277 static bool CreateStringFlag(const char* name, const char* shortName, | 277 static bool CreateStringFlag(const char* name, const char* shortName, |
278 SkCommandLineFlags::StringArray* pStrings, | 278 SkCommandLineFlags::StringArray* pStrings, |
279 const char* defaultValue, const char* helpStrin
g); | 279 const char* defaultValue, const char* helpStrin
g); |
280 | 280 |
281 /** | 281 /** |
282 * See comments for CreateBoolFlag. | 282 * See comments for CreateBoolFlag. |
283 */ | 283 */ |
284 static bool CreateIntFlag(const char* name, int32_t* pInt, | 284 static bool CreateIntFlag(const char* name, int32_t* pInt, |
285 int32_t defaultValue, const char* helpString) { | 285 int32_t defaultValue, const char* helpString) { |
286 SkFlagInfo* info = new SkFlagInfo(name, NULL, kInt_FlagType, helpString)
; | 286 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kInt_FlagType, helpStri
ng); |
287 info->fIntValue = pInt; | 287 info->fIntValue = pInt; |
288 *info->fIntValue = info->fDefaultInt = defaultValue; | 288 *info->fIntValue = info->fDefaultInt = defaultValue; |
289 return true; | 289 return true; |
290 } | 290 } |
291 | 291 |
292 /** | 292 /** |
293 * See comments for CreateBoolFlag. | 293 * See comments for CreateBoolFlag. |
294 */ | 294 */ |
295 static bool CreateDoubleFlag(const char* name, double* pDouble, | 295 static bool CreateDoubleFlag(const char* name, double* pDouble, |
296 double defaultValue, const char* helpString) { | 296 double defaultValue, const char* helpString) { |
297 SkFlagInfo* info = new SkFlagInfo(name, NULL, kDouble_FlagType, helpStri
ng); | 297 SkFlagInfo* info = new SkFlagInfo(name, nullptr, kDouble_FlagType, helpS
tring); |
298 info->fDoubleValue = pDouble; | 298 info->fDoubleValue = pDouble; |
299 *info->fDoubleValue = info->fDefaultDouble = defaultValue; | 299 *info->fDoubleValue = info->fDefaultDouble = defaultValue; |
300 return true; | 300 return true; |
301 } | 301 } |
302 | 302 |
303 /** | 303 /** |
304 * Returns true if the string matches this flag. | 304 * Returns true if the string matches this flag. |
305 * For a boolean flag, also sets the value, since a boolean flag can be set
in a number of ways | 305 * For a boolean flag, also sets the value, since a boolean flag can be set
in a number of ways |
306 * without looking at the following string: | 306 * without looking at the following string: |
307 * --name | 307 * --name |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 return SkString(); | 400 return SkString(); |
401 } | 401 } |
402 } | 402 } |
403 | 403 |
404 private: | 404 private: |
405 SkFlagInfo(const char* name, const char* shortName, FlagTypes type, const ch
ar* helpString) | 405 SkFlagInfo(const char* name, const char* shortName, FlagTypes type, const ch
ar* helpString) |
406 : fName(name) | 406 : fName(name) |
407 , fShortName(shortName) | 407 , fShortName(shortName) |
408 , fFlagType(type) | 408 , fFlagType(type) |
409 , fHelpString(helpString) | 409 , fHelpString(helpString) |
410 , fBoolValue(NULL) | 410 , fBoolValue(nullptr) |
411 , fDefaultBool(false) | 411 , fDefaultBool(false) |
412 , fIntValue(NULL) | 412 , fIntValue(nullptr) |
413 , fDefaultInt(0) | 413 , fDefaultInt(0) |
414 , fDoubleValue(NULL) | 414 , fDoubleValue(nullptr) |
415 , fDefaultDouble(0) | 415 , fDefaultDouble(0) |
416 , fStrings(NULL) { | 416 , fStrings(nullptr) { |
417 fNext = SkCommandLineFlags::gHead; | 417 fNext = SkCommandLineFlags::gHead; |
418 SkCommandLineFlags::gHead = this; | 418 SkCommandLineFlags::gHead = this; |
419 SkASSERT(name && strlen(name) > 1); | 419 SkASSERT(name && strlen(name) > 1); |
420 SkASSERT(NULL == shortName || 1 == strlen(shortName)); | 420 SkASSERT(nullptr == shortName || 1 == strlen(shortName)); |
421 } | 421 } |
422 | 422 |
423 /** | 423 /** |
424 * Set a StringArray to hold the values stored in defaultStrings. | 424 * Set a StringArray to hold the values stored in defaultStrings. |
425 * @param array The StringArray to modify. | 425 * @param array The StringArray to modify. |
426 * @param defaultStrings Space separated list of strings that should be ins
erted into array | 426 * @param defaultStrings Space separated list of strings that should be ins
erted into array |
427 * individually. | 427 * individually. |
428 */ | 428 */ |
429 static void SetDefaultStrings(SkCommandLineFlags::StringArray* array, | 429 static void SetDefaultStrings(SkCommandLineFlags::StringArray* array, |
430 const char* defaultStrings); | 430 const char* defaultStrings); |
(...skipping 10 matching lines...) Expand all Loading... |
441 double* fDoubleValue; | 441 double* fDoubleValue; |
442 double fDefaultDouble; | 442 double fDefaultDouble; |
443 SkCommandLineFlags::StringArray* fStrings; | 443 SkCommandLineFlags::StringArray* fStrings; |
444 // Both for the help string and in case fStrings is empty. | 444 // Both for the help string and in case fStrings is empty. |
445 SkString fDefaultString; | 445 SkString fDefaultString; |
446 | 446 |
447 // In order to keep a linked list. | 447 // In order to keep a linked list. |
448 SkFlagInfo* fNext; | 448 SkFlagInfo* fNext; |
449 }; | 449 }; |
450 #endif // SK_COMMAND_LINE_FLAGS_H | 450 #endif // SK_COMMAND_LINE_FLAGS_H |
OLD | NEW |