1161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com/* 2161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Copyright 2013 Google Inc. 3161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 4161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Use of this source code is governed by a BSD-style license that can be 5161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * found in the LICENSE file. 6161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com */ 7161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 8d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com#ifndef SK_COMMAND_LINE_FLAGS_H 9d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com#define SK_COMMAND_LINE_FLAGS_H 10161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 11bf521ff9415b3bdb1acde7b8d18139df176236e5bungeman#include "../private/SkTArray.h" 12a7e9f05119174848c6be5028568f46eb5e85398ebungeman#include "../private/SkTDArray.h" 13161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#include "SkString.h" 14161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 15161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com/** 16d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com * Including this file (and compiling SkCommandLineFlags.cpp) provides command line 17161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * parsing. In order to use it, use the following macros in global 18161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * namespace: 19161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 20161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * DEFINE_bool(name, defaultValue, helpString); 21161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * DEFINE_string(name, defaultValue, helpString); 22161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * DEFINE_int32(name, defaultValue, helpString); 23161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * DEFINE_double(name, defaultValue, helpString); 24161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 25d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com * Then, in main, call SkCommandLineFlags::SetUsage() to describe usage and call 26d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com * SkCommandLineFlags::Parse() to parse the flags. Henceforth, each flag can 27161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * be referenced using 28161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 29161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * FLAGS_name 30161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 31161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * For example, the line 32161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 33161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * DEFINE_bool(boolean, false, "The variable boolean does such and such"); 34161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 35161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * will create the following variable: 36161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 37161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * bool FLAGS_boolean; 38161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 39161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * which will initially be set to false, and can be set to true by using the 40161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * flag "--boolean" on the commandline. "--noboolean" will set FLAGS_boolean 415dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * to false. FLAGS_boolean can also be set using "--boolean=true" or 425dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * "--boolean true" (where "true" can be replaced by "false", "TRUE", "FALSE", 435dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * "1" or "0"). 445dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * 455dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * The helpString will be printed if the help flag (-h or -help) is used. 46161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 47161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Similarly, the line 48161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 49161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * DEFINE_int32(integer, .., ..); 50161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 51161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * will create 52161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 53161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * int32_t FLAGS_integer; 54161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 55161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * and 56161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 57161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * DEFINE_double(real, .., ..); 58161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 59161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * will create 60161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 61161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * double FLAGS_real; 62161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 63161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * These flags can be set by specifying, for example, "--integer 7" and 64161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * "--real 3.14" on the command line. 65161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 66161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Unlike the others, the line 67161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 68161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * DEFINE_string(args, .., ..); 69161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 70161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * creates an array: 71161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 72b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com * SkCommandLineFlags::StringArray FLAGS_args; 73161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 74161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * If the default value is the empty string, FLAGS_args will default to a size 75161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * of zero. Otherwise it will default to a size of 1 with the default string 76161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * as its value. All strings that follow the flag on the command line (until 77161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * a string that begins with '-') will be entries in the array. 78161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 793e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen * DEFINE_extended_string(args, .., .., extendedHelpString); 803e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen * 813e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen * creates a similar string array flag as DEFINE_string. The flag will have extended help text 823e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen * (extendedHelpString) that can the user can see with '--help <args>' flag. 833e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen * 84161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Any flag can be referenced from another file after using the following: 85161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 86161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * DECLARE_x(name); 87161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 88161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * (where 'x' is the type specified in the DEFINE). 89161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * 90161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Inspired by gflags (https://code.google.com/p/gflags/). Is not quite as 91161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * robust as gflags, but suits our purposes. For example, allows creating 92d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com * a flag -h or -help which will never be used, since SkCommandLineFlags handles it. 93d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com * SkCommandLineFlags will also allow creating --flag and --noflag. Uses the same input 94161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * format as gflags and creates similarly named variables (i.e. FLAGS_name). 95161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Strings are handled differently (resulting variable will be an array of 96161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * strings) so that a flag can be followed by multiple parameters. 97161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com */ 98161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 99161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.comclass SkFlagInfo; 100161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 101d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.comclass SkCommandLineFlags { 102161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 103161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.compublic: 104161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com /** 105161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Call to set the help message to be displayed. Should be called before 106d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com * Parse. 107161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com */ 108161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com static void SetUsage(const char* usage); 109161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 110161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com /** 1113478f753ffc28a6f0f0877cc06be7373f960c527msarett * Call this to display the help message. Should be called after SetUsage. 1123478f753ffc28a6f0f0877cc06be7373f960c527msarett */ 1133478f753ffc28a6f0f0877cc06be7373f960c527msarett static void PrintUsage(); 1143478f753ffc28a6f0f0877cc06be7373f960c527msarett 1153478f753ffc28a6f0f0877cc06be7373f960c527msarett /** 116161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Call at the beginning of main to parse flags created by DEFINE_x, above. 117161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com * Must only be called once. 118161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com */ 119d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com static void Parse(int argc, char** argv); 120161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 121b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com /** 122b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com * Custom class for holding the arguments for a string flag. 123b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com * Publicly only has accessors so the strings cannot be modified. 124b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com */ 125b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com class StringArray { 126b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com public: 1273e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen StringArray() { } 1283e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen explicit StringArray(const SkTArray<SkString>& strings) 1293e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen : fStrings(strings) { 1303e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen } 131b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com const char* operator[](int i) const { 132b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com SkASSERT(i >= 0 && i < fStrings.count()); 133b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com return fStrings[i].c_str(); 134b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com } 135b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com 136b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com int count() const { 137b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com return fStrings.count(); 138b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com } 139b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com 140b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com bool isEmpty() const { return this->count() == 0; } 141b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com 142defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com /** 143defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com * Returns true iff string is equal to one of the strings in this array. 144defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com */ 145defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com bool contains(const char* string) const { 146defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com for (int i = 0; i < fStrings.count(); i++) { 147defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com if (fStrings[i].equals(string)) { 148defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com return true; 149defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com } 150defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com } 151defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com return false; 152defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com } 153defc487aa9e6bef16f76846f286f8a1343524d45epoger@google.com 154936b73424f7393994be832376287da988a52b993caryclark void set(int i, const char* str) { 155936b73424f7393994be832376287da988a52b993caryclark fStrings[i].set(str); 156936b73424f7393994be832376287da988a52b993caryclark } 157936b73424f7393994be832376287da988a52b993caryclark 158b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com private: 159b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com void reset() { fStrings.reset(); } 160b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com 161b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com void append(const char* string) { 162b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com fStrings.push_back().set(string); 163b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com } 164b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com 16558104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com void append(const char* string, size_t length) { 16658104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com fStrings.push_back().set(string, length); 16758104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com } 16858104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com 169b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com SkTArray<SkString> fStrings; 170b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com 171b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com friend class SkFlagInfo; 172b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com }; 173b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com 174a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org /* Takes a list of the form [~][^]match[$] 175a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org ~ causes a matching test to always be skipped 176a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org ^ requires the start of the test to match 177a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org $ requires the end of the test to match 178a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org ^ and $ requires an exact match 179a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org If a test does not match any list entry, it is skipped unless some list entry starts with ~ 180a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org */ 181a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org static bool ShouldSkip(const SkTDArray<const char*>& strings, const char* name); 182a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org static bool ShouldSkip(const StringArray& strings, const char* name); 183a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcfcommit-bot@chromium.org 184161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.comprivate: 185161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com static SkFlagInfo* gHead; 186161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com static SkString gUsage; 187161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 188161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com // For access to gHead. 189161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com friend class SkFlagInfo; 190161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com}; 191161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 192161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#define TO_STRING2(s) #s 193161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#define TO_STRING(s) TO_STRING2(s) 194161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 195161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#define DEFINE_bool(name, defaultValue, helpString) \ 196161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.combool FLAGS_##name; \ 197523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalitaSK_UNUSED static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name), \ 19896fcdcc219d2a0d3579719b84b28bede76efba64halcanary nullptr, \ 199523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita &FLAGS_##name, \ 200523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita defaultValue, \ 201523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita helpString) 20209fd4d216963c498c24ba355accce9337a5029a8scroggo@google.com 20309fd4d216963c498c24ba355accce9337a5029a8scroggo@google.com// bool 2 allows specifying a short name. No check is done to ensure that shortName 20409fd4d216963c498c24ba355accce9337a5029a8scroggo@google.com// is actually shorter than name. 20509fd4d216963c498c24ba355accce9337a5029a8scroggo@google.com#define DEFINE_bool2(name, shortName, defaultValue, helpString) \ 20609fd4d216963c498c24ba355accce9337a5029a8scroggo@google.combool FLAGS_##name; \ 207523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalitaSK_UNUSED static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name), \ 208523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita TO_STRING(shortName),\ 209523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita &FLAGS_##name, \ 210523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita defaultValue, \ 211523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita helpString) 212161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 213161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#define DECLARE_bool(name) extern bool FLAGS_##name; 214161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 215161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#define DEFINE_string(name, defaultValue, helpString) \ 216b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.comSkCommandLineFlags::StringArray FLAGS_##name; \ 217523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalitaSK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \ 21896fcdcc219d2a0d3579719b84b28bede76efba64halcanary nullptr, \ 219523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita &FLAGS_##name, \ 220523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita defaultValue, \ 2213e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen helpString, nullptr) 2223e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen#define DEFINE_extended_string(name, defaultValue, helpString, extendedHelpString) \ 2233e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenSkCommandLineFlags::StringArray FLAGS_##name; \ 2243e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunenSK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \ 2253e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen nullptr, \ 2263e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen &FLAGS_##name, \ 2273e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen defaultValue, \ 2283e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen helpString, \ 2293e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen extendedHelpString) 230161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 231604e0c249ef0e11a1b8bc41195081363fd86d892scroggo@google.com// string2 allows specifying a short name. There is an assert that shortName 232604e0c249ef0e11a1b8bc41195081363fd86d892scroggo@google.com// is only 1 character. 23309fd4d216963c498c24ba355accce9337a5029a8scroggo@google.com#define DEFINE_string2(name, shortName, defaultValue, helpString) \ 234b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.comSkCommandLineFlags::StringArray FLAGS_##name; \ 235523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalitaSK_UNUSED static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \ 236523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita TO_STRING(shortName), \ 237523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita &FLAGS_##name, \ 238523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita defaultValue, \ 2393e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen helpString, nullptr) 24009fd4d216963c498c24ba355accce9337a5029a8scroggo@google.com 241b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com#define DECLARE_string(name) extern SkCommandLineFlags::StringArray FLAGS_##name; 242161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 2435ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips 2445ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips 2455ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips 246161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#define DEFINE_int32(name, defaultValue, helpString) \ 247161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.comint32_t FLAGS_##name; \ 248523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalitaSK_UNUSED static bool unused_##name = SkFlagInfo::CreateIntFlag(TO_STRING(name), \ 249523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita &FLAGS_##name, \ 250523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita defaultValue, \ 251523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita helpString) 252161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 2535ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips#define DEFINE_int32_2(name, shortName, defaultValue, helpString) \ 2545ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillipsint32_t FLAGS_##name; \ 2555ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillipsSK_UNUSED static bool unused_##name = SkFlagInfo::CreateIntFlag(TO_STRING(name), \ 2565ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips TO_STRING(shortName), \ 2575ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips &FLAGS_##name, \ 2585ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips defaultValue, \ 2595ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips helpString) 2605ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips 261161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#define DECLARE_int32(name) extern int32_t FLAGS_##name; 262161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 263161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#define DEFINE_double(name, defaultValue, helpString) \ 264161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.comdouble FLAGS_##name; \ 265523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalitaSK_UNUSED static bool unused_##name = SkFlagInfo::CreateDoubleFlag(TO_STRING(name), \ 266523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita &FLAGS_##name, \ 267523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita defaultValue, \ 268523beb7fd91e6a171a69f44cf6cc8e8d88a22dd0fmalita helpString) 269161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 270161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com#define DECLARE_double(name) extern double FLAGS_##name; 271161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 272161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.comclass SkFlagInfo { 273161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 274161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.compublic: 275161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com enum FlagTypes { 276161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com kBool_FlagType, 277161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com kString_FlagType, 278161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com kInt_FlagType, 279161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com kDouble_FlagType, 280161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com }; 281161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 28258104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com /** 28358104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * Each Create<Type>Flag function creates an SkFlagInfo of the specified type. The SkFlagInfo 28458104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * object is appended to a list, which is deleted when SkCommandLineFlags::Parse is called. 28558104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * Therefore, each call should be made before the call to ::Parse. They are not intended 28658104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * to be called directly. Instead, use the macros described above. 28758104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * @param name Long version (at least 2 characters) of the name of the flag. This name can 28858104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * be referenced on the command line as "--name" to set the value of this flag. 28958104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * @param shortName Short version (one character) of the name of the flag. This name can 29058104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * be referenced on the command line as "-shortName" to set the value of this flag. 29158104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * @param p<Type> Pointer to a global variable which holds the value set by SkCommandLineFlags. 29258104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * @param defaultValue The default value of this flag. The variable pointed to by p<Type> will 29358104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * be set to this value initially. This is also displayed as part of the help output. 29458104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * @param helpString Explanation of what this flag changes in the program. 29558104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com */ 29609fd4d216963c498c24ba355accce9337a5029a8scroggo@google.com static bool CreateBoolFlag(const char* name, const char* shortName, bool* pBool, 297161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com bool defaultValue, const char* helpString) { 2983e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkFlagInfo* info = new SkFlagInfo(name, shortName, kBool_FlagType, helpString, nullptr); 299161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com info->fBoolValue = pBool; 300161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com *info->fBoolValue = info->fDefaultBool = defaultValue; 301161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return true; 302161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 303161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 30458104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com /** 30558104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * See comments for CreateBoolFlag. 30658104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * @param pStrings Unlike the others, this is a pointer to an array of values. 30758104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * @param defaultValue Thise default will be parsed so that strings separated by spaces 30858104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * will be added to pStrings. 30958104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com */ 31009fd4d216963c498c24ba355accce9337a5029a8scroggo@google.com static bool CreateStringFlag(const char* name, const char* shortName, 311b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com SkCommandLineFlags::StringArray* pStrings, 3123e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const char* defaultValue, const char* helpString, 3133e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const char* extendedHelpString); 314161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 31558104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com /** 31658104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * See comments for CreateBoolFlag. 31758104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com */ 318161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com static bool CreateIntFlag(const char* name, int32_t* pInt, 319161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com int32_t defaultValue, const char* helpString) { 3203e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkFlagInfo* info = new SkFlagInfo(name, nullptr, kInt_FlagType, helpString, nullptr); 321161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com info->fIntValue = pInt; 322161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com *info->fIntValue = info->fDefaultInt = defaultValue; 323161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return true; 3245ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips } 3255ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips 3265ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips static bool CreateIntFlag(const char* name, const char* shortName, int32_t* pInt, 3275ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips int32_t defaultValue, const char* helpString) { 3283e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkFlagInfo* info = new SkFlagInfo(name, shortName, kInt_FlagType, helpString, nullptr); 3295ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips info->fIntValue = pInt; 3305ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips *info->fIntValue = info->fDefaultInt = defaultValue; 3315ce341fcd7eb63fc98c182b34c5503fb1780faf5robertphillips return true; 332161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 333161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 33458104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com /** 33558104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * See comments for CreateBoolFlag. 33658104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com */ 337161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com static bool CreateDoubleFlag(const char* name, double* pDouble, 338161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com double defaultValue, const char* helpString) { 3393e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkFlagInfo* info = new SkFlagInfo(name, nullptr, kDouble_FlagType, helpString, nullptr); 340161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com info->fDoubleValue = pDouble; 341161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com *info->fDoubleValue = info->fDefaultDouble = defaultValue; 342161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return true; 343161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 344161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 345161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com /** 3465dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * Returns true if the string matches this flag. 3475dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * For a boolean flag, also sets the value, since a boolean flag can be set in a number of ways 3485dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * without looking at the following string: 3495dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * --name 3505dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * --noname 3515dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * --name=true 3525dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * --name=false 3535dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * --name=1 3545dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * --name=0 3555dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * --name=TRUE 3565dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com * --name=FALSE 357161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com */ 3585dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com bool match(const char* string); 359161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 360161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com FlagTypes getFlagType() const { return fFlagType; } 361161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 362161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com void resetStrings() { 363161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com if (kString_FlagType == fFlagType) { 364161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com fStrings->reset(); 365161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } else { 366330313a8a8343876ee596da39da06a5d69badd9cmtklein@google.com SkDEBUGFAIL("Can only call resetStrings on kString_FlagType"); 367161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 368161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 369161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 370161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com void append(const char* string) { 371161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com if (kString_FlagType == fFlagType) { 372b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com fStrings->append(string); 373161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } else { 374330313a8a8343876ee596da39da06a5d69badd9cmtklein@google.com SkDEBUGFAIL("Can only append to kString_FlagType"); 375161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 376161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 377161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 378161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com void setInt(int32_t value) { 379161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com if (kInt_FlagType == fFlagType) { 380161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com *fIntValue = value; 381161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } else { 382330313a8a8343876ee596da39da06a5d69badd9cmtklein@google.com SkDEBUGFAIL("Can only call setInt on kInt_FlagType"); 383161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 384161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 385161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 386161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com void setDouble(double value) { 387161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com if (kDouble_FlagType == fFlagType) { 388161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com *fDoubleValue = value; 389161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } else { 390330313a8a8343876ee596da39da06a5d69badd9cmtklein@google.com SkDEBUGFAIL("Can only call setDouble on kDouble_FlagType"); 391161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 392161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 393161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 3945dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com void setBool(bool value) { 3955dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com if (kBool_FlagType == fFlagType) { 3965dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com *fBoolValue = value; 3975dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com } else { 398330313a8a8343876ee596da39da06a5d69badd9cmtklein@google.com SkDEBUGFAIL("Can only call setBool on kBool_FlagType"); 3995dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com } 4005dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com } 4015dc4ca1ce6e89e4de9675ef44215333480a497d2scroggo@google.com 402161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com SkFlagInfo* next() { return fNext; } 403161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 404161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com const SkString& name() const { return fName; } 405161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 4068366df025a5c3eb562c6bff1ddf63213fbf3f7d6scroggo@google.com const SkString& shortName() const { return fShortName; } 4078366df025a5c3eb562c6bff1ddf63213fbf3f7d6scroggo@google.com 408161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com const SkString& help() const { return fHelpString; } 4093e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const SkString& extendedHelp() const { return fExtendedHelpString; } 410161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 411161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com SkString defaultValue() const { 412161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com SkString result; 413161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com switch (fFlagType) { 414161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com case SkFlagInfo::kBool_FlagType: 415161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com result.printf("%s", fDefaultBool ? "true" : "false"); 416161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com break; 417161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com case SkFlagInfo::kString_FlagType: 418161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return fDefaultString; 419161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com case SkFlagInfo::kInt_FlagType: 420161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com result.printf("%i", fDefaultInt); 421161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com break; 422161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com case SkFlagInfo::kDouble_FlagType: 423161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com result.printf("%2.2f", fDefaultDouble); 424161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com break; 425161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com default: 426330313a8a8343876ee596da39da06a5d69badd9cmtklein@google.com SkDEBUGFAIL("Invalid flag type"); 427161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 428161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return result; 429161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 430161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 431161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com SkString typeAsString() const { 432161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com switch (fFlagType) { 433161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com case SkFlagInfo::kBool_FlagType: 434161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return SkString("bool"); 435161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com case SkFlagInfo::kString_FlagType: 436161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return SkString("string"); 437161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com case SkFlagInfo::kInt_FlagType: 438161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return SkString("int"); 439161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com case SkFlagInfo::kDouble_FlagType: 440161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return SkString("double"); 441161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com default: 442330313a8a8343876ee596da39da06a5d69badd9cmtklein@google.com SkDEBUGFAIL("Invalid flag type"); 443161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com return SkString(); 444161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 445161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 446161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 447161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.comprivate: 4483e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkFlagInfo(const char* name, const char* shortName, FlagTypes type, const char* helpString, 4493e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen const char* extendedHelpString) 450161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com : fName(name) 451604e0c249ef0e11a1b8bc41195081363fd86d892scroggo@google.com , fShortName(shortName) 452161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com , fFlagType(type) 453161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com , fHelpString(helpString) 4543e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen , fExtendedHelpString(extendedHelpString) 45596fcdcc219d2a0d3579719b84b28bede76efba64halcanary , fBoolValue(nullptr) 456161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com , fDefaultBool(false) 45796fcdcc219d2a0d3579719b84b28bede76efba64halcanary , fIntValue(nullptr) 458161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com , fDefaultInt(0) 45996fcdcc219d2a0d3579719b84b28bede76efba64halcanary , fDoubleValue(nullptr) 460161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com , fDefaultDouble(0) 46196fcdcc219d2a0d3579719b84b28bede76efba64halcanary , fStrings(nullptr) { 462d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com fNext = SkCommandLineFlags::gHead; 463d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com SkCommandLineFlags::gHead = this; 46449f085dddff10473b6ebf832a974288300224e60bsalomon SkASSERT(name && strlen(name) > 1); 46596fcdcc219d2a0d3579719b84b28bede76efba64halcanary SkASSERT(nullptr == shortName || 1 == strlen(shortName)); 466161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com } 46758104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com 46858104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com /** 46958104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * Set a StringArray to hold the values stored in defaultStrings. 47058104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * @param array The StringArray to modify. 47158104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * @param defaultStrings Space separated list of strings that should be inserted into array 47258104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com * individually. 47358104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com */ 47458104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com static void SetDefaultStrings(SkCommandLineFlags::StringArray* array, 47558104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com const char* defaultStrings); 47658104a9c2517b25355d6838844ace2ea876f3a1cscroggo@google.com 477161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com // Name of the flag, without initial dashes 478161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com SkString fName; 47909fd4d216963c498c24ba355accce9337a5029a8scroggo@google.com SkString fShortName; 480161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com FlagTypes fFlagType; 481161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com SkString fHelpString; 4823e980c3d88fbc509b79e7ccef16ca38f5bbfb180kkinnunen SkString fExtendedHelpString; 483161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com bool* fBoolValue; 484161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com bool fDefaultBool; 485161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com int32_t* fIntValue; 486161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com int32_t fDefaultInt; 487161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com double* fDoubleValue; 488161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com double fDefaultDouble; 489b7dbf633a69408fef33105e39b60c442771dba07scroggo@google.com SkCommandLineFlags::StringArray* fStrings; 490161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com // Both for the help string and in case fStrings is empty. 491161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com SkString fDefaultString; 492161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com 493161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com // In order to keep a linked list. 494161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com SkFlagInfo* fNext; 495161e1ba4c0a82e21c7d68808529699fd2394ad6cscroggo@google.com}; 496d9ba9a05d6f5766fdb1378b6ed84c0659009a8dascroggo@google.com#endif // SK_COMMAND_LINE_FLAGS_H 497