Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: tools/flags/SkCommandLineFlags.h

Issue 12521019: SkFlags now follows proper dashing convention. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/bench_pictures_main.cpp ('k') | tools/flags/SkCommandLineFlags.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 * will create the following variable: 34 * will create the following variable:
35 * 35 *
36 * bool FLAGS_boolean; 36 * bool FLAGS_boolean;
37 * 37 *
38 * which will initially be set to false, and can be set to true by using the 38 * which will initially be set to false, and can be set to true by using the
39 * flag "--boolean" on the commandline. "--noboolean" will set FLAGS_boolean 39 * flag "--boolean" on the commandline. "--noboolean" will set FLAGS_boolean
40 * to false. FLAGS_boolean can also be set using "--boolean=true" or 40 * to false. FLAGS_boolean can also be set using "--boolean=true" or
41 * "--boolean true" (where "true" can be replaced by "false", "TRUE", "FALSE", 41 * "--boolean true" (where "true" can be replaced by "false", "TRUE", "FALSE",
42 * "1" or "0"). 42 * "1" or "0").
43 * 43 *
44 * Single dashes are also permitted for this and other flags.
45 *
46 * The helpString will be printed if the help flag (-h or -help) is used. 44 * The helpString will be printed if the help flag (-h or -help) is used.
47 * 45 *
48 * Similarly, the line 46 * Similarly, the line
49 * 47 *
50 * DEFINE_int32(integer, .., ..); 48 * DEFINE_int32(integer, .., ..);
51 * 49 *
52 * will create 50 * will create
53 * 51 *
54 * int32_t FLAGS_integer; 52 * int32_t FLAGS_integer;
55 * 53 *
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 #define DECLARE_bool(name) extern bool FLAGS_##name; 140 #define DECLARE_bool(name) extern bool FLAGS_##name;
143 141
144 #define DEFINE_string(name, defaultValue, helpString) \ 142 #define DEFINE_string(name, defaultValue, helpString) \
145 SkTDArray<const char*> FLAGS_##name; \ 143 SkTDArray<const char*> FLAGS_##name; \
146 static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \ 144 static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
147 NULL, \ 145 NULL, \
148 &FLAGS_##name, \ 146 &FLAGS_##name, \
149 defaultValue, \ 147 defaultValue, \
150 helpString) 148 helpString)
151 149
152 // string2 allows specifying a short name. No check is done to ensure that short Name 150 // string2 allows specifying a short name. There is an assert that shortName
153 // is actually shorter than name. 151 // is only 1 character.
154 #define DEFINE_string2(name, shortName, defaultValue, helpString) \ 152 #define DEFINE_string2(name, shortName, defaultValue, helpString) \
reed1 2013/03/21 22:06:59 Can we name this DEFINE_char or DEFINE_string1, to
scroggo 2013/03/22 17:52:31 I agree that the current name is bad... I'm thinki
155 SkTDArray<const char*> FLAGS_##name; \ 153 SkTDArray<const char*> FLAGS_##name; \
156 static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \ 154 static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
157 TO_STRING(shortName), \ 155 TO_STRING(shortName), \
158 &FLAGS_##name, \ 156 &FLAGS_##name, \
159 defaultValue, \ 157 defaultValue, \
160 helpString) 158 helpString)
161 159
162 #define DECLARE_string(name) extern SkTDArray<const char*> FLAGS_##name; 160 #define DECLARE_string(name) extern SkTDArray<const char*> FLAGS_##name;
163 161
164 #define DEFINE_int32(name, defaultValue, helpString) \ 162 #define DEFINE_int32(name, defaultValue, helpString) \
(...skipping 20 matching lines...) Expand all
185 enum FlagTypes { 183 enum FlagTypes {
186 kBool_FlagType, 184 kBool_FlagType,
187 kString_FlagType, 185 kString_FlagType,
188 kInt_FlagType, 186 kInt_FlagType,
189 kDouble_FlagType, 187 kDouble_FlagType,
190 }; 188 };
191 189
192 // Create flags of the desired type, and append to the list. 190 // Create flags of the desired type, and append to the list.
193 static bool CreateBoolFlag(const char* name, const char* shortName, bool* pB ool, 191 static bool CreateBoolFlag(const char* name, const char* shortName, bool* pB ool,
194 bool defaultValue, const char* helpString) { 192 bool defaultValue, const char* helpString) {
195 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, kBool_FlagType, helpStr ing)); 193 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kBool_FlagTy pe, helpString));
196 info->fShortName.set(shortName);
197 info->fBoolValue = pBool; 194 info->fBoolValue = pBool;
198 *info->fBoolValue = info->fDefaultBool = defaultValue; 195 *info->fBoolValue = info->fDefaultBool = defaultValue;
199 return true; 196 return true;
200 } 197 }
201 198
202 static bool CreateStringFlag(const char* name, const char* shortName, 199 static bool CreateStringFlag(const char* name, const char* shortName,
203 SkTDArray<const char*>* pStrings, 200 SkTDArray<const char*>* pStrings,
204 const char* defaultValue, const char* helpStrin g) { 201 const char* defaultValue, const char* helpStrin g) {
205 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, kString_FlagType, helpS tring)); 202 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_Flag Type, helpString));
206 info->fShortName.set(shortName);
207 info->fDefaultString.set(defaultValue); 203 info->fDefaultString.set(defaultValue);
208 204
209 info->fStrings = pStrings; 205 info->fStrings = pStrings;
210 info->fStrings->reset(); 206 info->fStrings->reset();
211 // If default is "", leave the array empty. 207 // If default is "", leave the array empty.
212 if (info->fDefaultString.size() > 0) { 208 if (info->fDefaultString.size() > 0) {
213 info->fStrings->append(1, &defaultValue); 209 info->fStrings->append(1, &defaultValue);
214 } 210 }
215 return true; 211 return true;
216 } 212 }
217 213
218 static bool CreateIntFlag(const char* name, int32_t* pInt, 214 static bool CreateIntFlag(const char* name, int32_t* pInt,
219 int32_t defaultValue, const char* helpString) { 215 int32_t defaultValue, const char* helpString) {
220 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, kInt_FlagType, helpStri ng)); 216 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, NULL, kInt_FlagType, he lpString));
221 info->fIntValue = pInt; 217 info->fIntValue = pInt;
222 *info->fIntValue = info->fDefaultInt = defaultValue; 218 *info->fIntValue = info->fDefaultInt = defaultValue;
223 return true; 219 return true;
224 } 220 }
225 221
226 static bool CreateDoubleFlag(const char* name, double* pDouble, 222 static bool CreateDoubleFlag(const char* name, double* pDouble,
227 double defaultValue, const char* helpString) { 223 double defaultValue, const char* helpString) {
228 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, kDouble_FlagType, helpS tring)); 224 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, NULL, kDouble_FlagType, helpString));
229 info->fDoubleValue = pDouble; 225 info->fDoubleValue = pDouble;
230 *info->fDoubleValue = info->fDefaultDouble = defaultValue; 226 *info->fDoubleValue = info->fDefaultDouble = defaultValue;
231 return true; 227 return true;
232 } 228 }
233 229
234 /** 230 /**
235 * Returns true if the string matches this flag. 231 * Returns true if the string matches this flag.
236 * For a boolean flag, also sets the value, since a boolean flag can be set in a number of ways 232 * For a boolean flag, also sets the value, since a boolean flag can be set in a number of ways
237 * without looking at the following string: 233 * without looking at the following string:
238 * --name 234 * --name
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return SkString("int"); 322 return SkString("int");
327 case SkFlagInfo::kDouble_FlagType: 323 case SkFlagInfo::kDouble_FlagType:
328 return SkString("double"); 324 return SkString("double");
329 default: 325 default:
330 SkASSERT(!"Invalid flag type"); 326 SkASSERT(!"Invalid flag type");
331 return SkString(); 327 return SkString();
332 } 328 }
333 } 329 }
334 330
335 private: 331 private:
336 SkFlagInfo(const char* name, FlagTypes type, const char* helpString) 332 SkFlagInfo(const char* name, const char* shortName, FlagTypes type, const ch ar* helpString)
337 : fName(name) 333 : fName(name)
334 , fShortName(shortName)
338 , fFlagType(type) 335 , fFlagType(type)
339 , fHelpString(helpString) 336 , fHelpString(helpString)
340 , fBoolValue(NULL) 337 , fBoolValue(NULL)
341 , fDefaultBool(false) 338 , fDefaultBool(false)
342 , fIntValue(NULL) 339 , fIntValue(NULL)
343 , fDefaultInt(0) 340 , fDefaultInt(0)
344 , fDoubleValue(NULL) 341 , fDoubleValue(NULL)
345 , fDefaultDouble(0) 342 , fDefaultDouble(0)
346 , fStrings(NULL) { 343 , fStrings(NULL) {
347 fNext = SkCommandLineFlags::gHead; 344 fNext = SkCommandLineFlags::gHead;
348 SkCommandLineFlags::gHead = this; 345 SkCommandLineFlags::gHead = this;
346 SkASSERT(NULL != name && strlen(name) > 1);
347 SkASSERT(NULL == shortName || 1 == strlen(shortName));
349 } 348 }
350 // Name of the flag, without initial dashes 349 // Name of the flag, without initial dashes
351 SkString fName; 350 SkString fName;
352 SkString fShortName; 351 SkString fShortName;
353 FlagTypes fFlagType; 352 FlagTypes fFlagType;
354 SkString fHelpString; 353 SkString fHelpString;
355 bool* fBoolValue; 354 bool* fBoolValue;
356 bool fDefaultBool; 355 bool fDefaultBool;
357 int32_t* fIntValue; 356 int32_t* fIntValue;
358 int32_t fDefaultInt; 357 int32_t fDefaultInt;
359 double* fDoubleValue; 358 double* fDoubleValue;
360 double fDefaultDouble; 359 double fDefaultDouble;
361 SkTDArray<const char*>* fStrings; 360 SkTDArray<const char*>* fStrings;
362 // Both for the help string and in case fStrings is empty. 361 // Both for the help string and in case fStrings is empty.
363 SkString fDefaultString; 362 SkString fDefaultString;
364 363
365 // In order to keep a linked list. 364 // In order to keep a linked list.
366 SkFlagInfo* fNext; 365 SkFlagInfo* fNext;
367 }; 366 };
368 #endif // SK_COMMAND_LINE_FLAGS_H 367 #endif // SK_COMMAND_LINE_FLAGS_H
OLDNEW
« no previous file with comments | « tools/bench_pictures_main.cpp ('k') | tools/flags/SkCommandLineFlags.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698