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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 * | 59 * |
60 * double FLAGS_real; | 60 * double FLAGS_real; |
61 * | 61 * |
62 * These flags can be set by specifying, for example, "--integer 7" and | 62 * These flags can be set by specifying, for example, "--integer 7" and |
63 * "--real 3.14" on the command line. | 63 * "--real 3.14" on the command line. |
64 * | 64 * |
65 * Unlike the others, the line | 65 * Unlike the others, the line |
66 * | 66 * |
67 * DEFINE_string(args, .., ..); | 67 * DEFINE_string(args, .., ..); |
68 * | 68 * |
69 * creates an array: | 69 * creates an array: |
epoger
2013/04/23 16:54:13
Thoughts for a separate CL: I think it would be cl
scroggo
2013/04/24 18:42:36
Good idea. I have filed https://code.google.com/p/
| |
70 * | 70 * |
71 * SkCommandLineFlags::StringArray FLAGS_args; | 71 * SkCommandLineFlags::StringArray FLAGS_args; |
72 * | 72 * |
73 * If the default value is the empty string, FLAGS_args will default to a size | 73 * If the default value is the empty string, FLAGS_args will default to a size |
74 * of zero. Otherwise it will default to a size of 1 with the default string | 74 * of zero. Otherwise it will default to a size of 1 with the default string |
75 * as its value. All strings that follow the flag on the command line (until | 75 * as its value. All strings that follow the flag on the command line (until |
76 * a string that begins with '-') will be entries in the array. | 76 * a string that begins with '-') will be entries in the array. |
77 * | 77 * |
78 * Any flag can be referenced from another file after using the following: | 78 * Any flag can be referenced from another file after using the following: |
79 * | 79 * |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 | 125 |
126 bool isEmpty() const { return this->count() == 0; } | 126 bool isEmpty() const { return this->count() == 0; } |
127 | 127 |
128 private: | 128 private: |
129 void reset() { fStrings.reset(); } | 129 void reset() { fStrings.reset(); } |
130 | 130 |
131 void append(const char* string) { | 131 void append(const char* string) { |
132 fStrings.push_back().set(string); | 132 fStrings.push_back().set(string); |
133 } | 133 } |
134 | 134 |
135 void append(const char* string, size_t length) { | |
136 fStrings.push_back().set(string, length); | |
137 } | |
138 | |
135 SkTArray<SkString> fStrings; | 139 SkTArray<SkString> fStrings; |
136 | 140 |
137 friend class SkFlagInfo; | 141 friend class SkFlagInfo; |
138 }; | 142 }; |
139 | 143 |
140 private: | 144 private: |
141 static SkFlagInfo* gHead; | 145 static SkFlagInfo* gHead; |
142 static SkString gUsage; | 146 static SkString gUsage; |
143 | 147 |
144 // For access to gHead. | 148 // For access to gHead. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 | 222 |
219 // Create flags of the desired type, and append to the list. | 223 // Create flags of the desired type, and append to the list. |
220 static bool CreateBoolFlag(const char* name, const char* shortName, bool* pB ool, | 224 static bool CreateBoolFlag(const char* name, const char* shortName, bool* pB ool, |
221 bool defaultValue, const char* helpString) { | 225 bool defaultValue, const char* helpString) { |
222 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kBool_FlagTy pe, helpString)); | 226 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kBool_FlagTy pe, helpString)); |
223 info->fBoolValue = pBool; | 227 info->fBoolValue = pBool; |
224 *info->fBoolValue = info->fDefaultBool = defaultValue; | 228 *info->fBoolValue = info->fDefaultBool = defaultValue; |
225 return true; | 229 return true; |
226 } | 230 } |
227 | 231 |
228 static bool CreateStringFlag(const char* name, const char* shortName, | 232 static bool CreateStringFlag(const char* name, const char* shortName, |
epoger
2013/04/23 16:54:13
Please add documentation for this (and maybe other
scroggo
2013/04/24 18:42:36
Done.
| |
229 SkCommandLineFlags::StringArray* pStrings, | 233 SkCommandLineFlags::StringArray* pStrings, |
230 const char* defaultValue, const char* helpStrin g) { | 234 const char* defaultValue, const char* helpStrin g); |
231 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, shortName, kString_Flag Type, helpString)); | |
232 info->fDefaultString.set(defaultValue); | |
233 | |
234 info->fStrings = pStrings; | |
235 info->fStrings->reset(); | |
236 // If default is "", leave the array empty. | |
237 if (info->fDefaultString.size() > 0) { | |
238 info->fStrings->append(defaultValue); | |
239 } | |
240 return true; | |
241 } | |
242 | 235 |
243 static bool CreateIntFlag(const char* name, int32_t* pInt, | 236 static bool CreateIntFlag(const char* name, int32_t* pInt, |
244 int32_t defaultValue, const char* helpString) { | 237 int32_t defaultValue, const char* helpString) { |
245 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, NULL, kInt_FlagType, he lpString)); | 238 SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, NULL, kInt_FlagType, he lpString)); |
246 info->fIntValue = pInt; | 239 info->fIntValue = pInt; |
247 *info->fIntValue = info->fDefaultInt = defaultValue; | 240 *info->fIntValue = info->fDefaultInt = defaultValue; |
248 return true; | 241 return true; |
249 } | 242 } |
250 | 243 |
251 static bool CreateDoubleFlag(const char* name, double* pDouble, | 244 static bool CreateDoubleFlag(const char* name, double* pDouble, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 double* fDoubleValue; | 380 double* fDoubleValue; |
388 double fDefaultDouble; | 381 double fDefaultDouble; |
389 SkCommandLineFlags::StringArray* fStrings; | 382 SkCommandLineFlags::StringArray* fStrings; |
390 // Both for the help string and in case fStrings is empty. | 383 // Both for the help string and in case fStrings is empty. |
391 SkString fDefaultString; | 384 SkString fDefaultString; |
392 | 385 |
393 // In order to keep a linked list. | 386 // In order to keep a linked list. |
394 SkFlagInfo* fNext; | 387 SkFlagInfo* fNext; |
395 }; | 388 }; |
396 #endif // SK_COMMAND_LINE_FLAGS_H | 389 #endif // SK_COMMAND_LINE_FLAGS_H |
OLD | NEW |