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

Unified Diff: tools/SkFlags.h

Issue 12440052: Reland r8235 "Switch gm to use SkFlags." (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/tools.gyp ('k') | tools/SkFlags.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/SkFlags.h
diff --git a/tools/SkFlags.h b/tools/SkFlags.h
index d40cdd06f3af5c96074b279af6c01c1a4347b2d6..79cc8788a3b26f93393f519ce0014ebbe79dd532 100644
--- a/tools/SkFlags.h
+++ b/tools/SkFlags.h
@@ -119,6 +119,17 @@ private:
#define DEFINE_bool(name, defaultValue, helpString) \
bool FLAGS_##name; \
static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name), \
+ NULL, \
+ &FLAGS_##name, \
+ defaultValue, \
+ helpString)
+
+// bool 2 allows specifying a short name. No check is done to ensure that shortName
+// is actually shorter than name.
+#define DEFINE_bool2(name, shortName, defaultValue, helpString) \
+bool FLAGS_##name; \
+static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name), \
+ TO_STRING(shortName),\
&FLAGS_##name, \
defaultValue, \
helpString)
@@ -128,10 +139,21 @@ static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name), \
#define DEFINE_string(name, defaultValue, helpString) \
SkTDArray<const char*> FLAGS_##name; \
static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
+ NULL, \
&FLAGS_##name, \
defaultValue, \
helpString)
+// string2 allows specifying a short name. No check is done to ensure that shortName
+// is actually shorter than name.
+#define DEFINE_string2(name, shortName, defaultValue, helpString) \
+SkTDArray<const char*> FLAGS_##name; \
+static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
+ TO_STRING(shortName), \
+ &FLAGS_##name, \
+ defaultValue, \
+ helpString)
+
#define DECLARE_string(name) extern SkTDArray<const char*> FLAGS_##name;
#define DEFINE_int32(name, defaultValue, helpString) \
@@ -163,17 +185,20 @@ public:
};
// Create flags of the desired type, and append to the list.
- static bool CreateBoolFlag(const char* name, bool* pBool,
+ static bool CreateBoolFlag(const char* name, const char* shortName, bool* pBool,
bool defaultValue, const char* helpString) {
SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, kBool_FlagType, helpString));
+ info->fShortName.set(shortName);
info->fBoolValue = pBool;
*info->fBoolValue = info->fDefaultBool = defaultValue;
return true;
}
- static bool CreateStringFlag(const char* name, SkTDArray<const char*>* pStrings,
+ static bool CreateStringFlag(const char* name, const char* shortName,
+ SkTDArray<const char*>* pStrings,
const char* defaultValue, const char* helpString) {
SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, kString_FlagType, helpString));
+ info->fShortName.set(shortName);
info->fDefaultString.set(defaultValue);
info->fStrings = pStrings;
@@ -206,27 +231,28 @@ public:
* value, since a bool is specified as true or false by --name or --noname.
*/
bool match(const char* string) {
- if (SkStrStartsWith(string, '-')) {
+ if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
string++;
// Allow one or two dashes
- if (SkStrStartsWith(string, '-')) {
+ if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
string++;
}
if (kBool_FlagType == fFlagType) {
// In this case, go ahead and set the value.
- if (fName.equals(string)) {
+ if (fName.equals(string) || fShortName.equals(string)) {
*fBoolValue = true;
return true;
}
- SkString noname(fName);
- noname.prepend("no");
- if (noname.equals(string)) {
- *fBoolValue = false;
- return true;
+ if (SkStrStartsWith(string, "no") && strlen(string) > 2) {
+ string += 2;
+ if (fName.equals(string) || fShortName.equals(string)) {
+ *fBoolValue = false;
+ return true;
+ }
+ return false;
}
- return false;
}
- return fName.equals(string);
+ return fName.equals(string) || fShortName.equals(string);
} else {
// Has no dash
return false;
@@ -327,6 +353,7 @@ private:
}
// Name of the flag, without initial dashes
SkString fName;
+ SkString fShortName;
FlagTypes fFlagType;
SkString fHelpString;
bool* fBoolValue;
« no previous file with comments | « gyp/tools.gyp ('k') | tools/SkFlags.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698