Commit c23c6c6f authored by Craig Silverstein's avatar Craig Silverstein

Starting the rollback of flag categories.

I left in the old FlagRegisterer constructor.
I also left in 'categories' in CommandLineFlagInfo for now,
though I never use it.  I doubt anyone else does either, but I
want to minimize the number of ways this rollback can break
the build.  I will remove it in a subsequent CL.

R=ncalvin
DELTA=121  (28 added, 55 deleted, 38 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=3574


git-svn-id: https://gflags.googlecode.com/svn/trunk@68 6586e3c6-dcc4-952a-343f-ff74eb82781d
parent 17a627a4
...@@ -112,8 +112,6 @@ ...@@ -112,8 +112,6 @@
#include "mutex.h" #include "mutex.h"
#include "util.h" #include "util.h"
using fL::OptionalDefineArgs;
#ifndef PATH_SEPARATOR #ifndef PATH_SEPARATOR
#define PATH_SEPARATOR '/' #define PATH_SEPARATOR '/'
#endif #endif
...@@ -484,14 +482,12 @@ class CommandLineFlag { ...@@ -484,14 +482,12 @@ class CommandLineFlag {
public: public:
// Note: we take over memory-ownership of current_val and default_val. // Note: we take over memory-ownership of current_val and default_val.
CommandLineFlag(const char* name, const char* help, const char* filename, CommandLineFlag(const char* name, const char* help, const char* filename,
const char* categories,
FlagValue* current_val, FlagValue* default_val); FlagValue* current_val, FlagValue* default_val);
~CommandLineFlag(); ~CommandLineFlag();
const char* name() const { return name_; } const char* name() const { return name_; }
const char* help() const { return help_; } const char* help() const { return help_; }
const char* filename() const { return file_; } const char* filename() const { return file_; }
const char* categories() const { return categories_ ? categories_ : ""; }
const char* CleanFileName() const; // nixes irrelevant prefix such as homedir const char* CleanFileName() const; // nixes irrelevant prefix such as homedir
string current_value() const { return current_->ToString(); } string current_value() const { return current_->ToString(); }
string default_value() const { return defvalue_->ToString(); } string default_value() const { return defvalue_->ToString(); }
...@@ -520,7 +516,6 @@ class CommandLineFlag { ...@@ -520,7 +516,6 @@ class CommandLineFlag {
const char* const name_; // Flag name const char* const name_; // Flag name
const char* const help_; // Help message const char* const help_; // Help message
const char* const file_; // Which file did this come from? const char* const file_; // Which file did this come from?
const char* categories_; // Comma-separated list of flag's 'categories'
bool modified_; // Set after default assignment? bool modified_; // Set after default assignment?
FlagValue* defvalue_; // Default value for flag FlagValue* defvalue_; // Default value for flag
FlagValue* current_; // Current value for flag FlagValue* current_; // Current value for flag
...@@ -535,11 +530,10 @@ class CommandLineFlag { ...@@ -535,11 +530,10 @@ class CommandLineFlag {
}; };
CommandLineFlag::CommandLineFlag(const char* name, const char* help, CommandLineFlag::CommandLineFlag(const char* name, const char* help,
const char* filename, const char* categories, const char* filename,
FlagValue* current_val, FlagValue* default_val) FlagValue* current_val, FlagValue* default_val)
: name_(name), help_(help), file_(filename), categories_(categories), : name_(name), help_(help), file_(filename), modified_(false),
modified_(false), defvalue_(default_val), current_(current_val), defvalue_(default_val), current_(current_val), validate_fn_proto_(NULL) {
validate_fn_proto_(NULL) {
} }
CommandLineFlag::~CommandLineFlag() { CommandLineFlag::~CommandLineFlag() {
...@@ -575,7 +569,6 @@ void CommandLineFlag::FillCommandLineFlagInfo( ...@@ -575,7 +569,6 @@ void CommandLineFlag::FillCommandLineFlagInfo(
result->name = name(); result->name = name();
result->type = type_name(); result->type = type_name();
result->description = help(); result->description = help();
result->categories = categories();
result->current_value = current_value(); result->current_value = current_value();
result->default_value = default_value(); result->default_value = default_value();
result->filename = CleanFileName(); result->filename = CleanFileName();
...@@ -1405,10 +1398,28 @@ bool AddFlagValidator(const void* flag_ptr, ValidateFnProto validate_fn_proto) { ...@@ -1405,10 +1398,28 @@ bool AddFlagValidator(const void* flag_ptr, ValidateFnProto validate_fn_proto) {
// values in a global destructor. // values in a global destructor.
// -------------------------------------------------------------------- // --------------------------------------------------------------------
FlagRegisterer::FlagRegisterer(const char* name, const char* type,
const char* help, const char* filename,
void* current_storage, void* defvalue_storage) {
if (help == NULL)
help = "";
// FlagValue expects the type-name to not include any namespace
// components, so we get rid of those, if any.
if (strchr(type, ':'))
type = strrchr(type, ':') + 1;
FlagValue* current = new FlagValue(current_storage, type, false);
FlagValue* defvalue = new FlagValue(defvalue_storage, type, false);
// Importantly, flag_ will never be deleted, so storage is always good.
CommandLineFlag* flag = new CommandLineFlag(name, help, filename,
current, defvalue);
FlagRegistry::GlobalRegistry()->RegisterFlag(flag); // default registry
}
// TODO(csilvers): remove
FlagRegisterer::FlagRegisterer(const char* name, const char* type, FlagRegisterer::FlagRegisterer(const char* name, const char* type,
const char* help, const char* filename, const char* help, const char* filename,
void* current_storage, void* defvalue_storage, void* current_storage, void* defvalue_storage,
const OptionalDefineArgs& optional_args) { const fL::OptionalDefineArgs& optional_args) {
if (help == NULL) if (help == NULL)
help = ""; help = "";
// FlagValue expects the type-name to not include any namespace // FlagValue expects the type-name to not include any namespace
...@@ -1419,7 +1430,6 @@ FlagRegisterer::FlagRegisterer(const char* name, const char* type, ...@@ -1419,7 +1430,6 @@ FlagRegisterer::FlagRegisterer(const char* name, const char* type,
FlagValue* defvalue = new FlagValue(defvalue_storage, type, false); FlagValue* defvalue = new FlagValue(defvalue_storage, type, false);
// Importantly, flag_ will never be deleted, so storage is always good. // Importantly, flag_ will never be deleted, so storage is always good.
CommandLineFlag* flag = new CommandLineFlag(name, help, filename, CommandLineFlag* flag = new CommandLineFlag(name, help, filename,
optional_args.categories,
current, defvalue); current, defvalue);
FlagRegistry::GlobalRegistry()->RegisterFlag(flag); // default registry FlagRegistry::GlobalRegistry()->RegisterFlag(flag); // default registry
} }
...@@ -1664,7 +1674,7 @@ class FlagSaverImpl { ...@@ -1664,7 +1674,7 @@ class FlagSaverImpl {
const CommandLineFlag* main = it->second; const CommandLineFlag* main = it->second;
// Sets up all the const variables in backup correctly // Sets up all the const variables in backup correctly
CommandLineFlag* backup = new CommandLineFlag( CommandLineFlag* backup = new CommandLineFlag(
main->name(), main->help(), main->filename(), main->categories(), main->name(), main->help(), main->filename(),
main->current_->New(), main->defvalue_->New()); main->current_->New(), main->defvalue_->New());
// Sets up all the non-const variables in backup correctly // Sets up all the non-const variables in backup correctly
backup->CopyFrom(*main); backup->CopyFrom(*main);
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
// //
// DEFINE_int32(end, 1000, "The last record to read"); // DEFINE_int32(end, 1000, "The last record to read");
// //
// DEFINE_string(filename, "my_file.txt", "The file to read", "important"); // DEFINE_string(filename, "my_file.txt", "The file to read");
// // Crash if the specified file does not exist. // // Crash if the specified file does not exist.
// static bool dummy = RegisterFlagValidator(&FLAGS_filename, // static bool dummy = RegisterFlagValidator(&FLAGS_filename,
// &ValidateIsFile); // &ValidateIsFile);
...@@ -81,6 +81,9 @@ ...@@ -81,6 +81,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <gflags/gflags_declare.h> // IWYU pragma: export #include <gflags/gflags_declare.h> // IWYU pragma: export
@ac_google_start_namespace@
namespace fL { struct OptionalDefineArgs { }; } // TODO(csilvers): remove
// //
// NOTE: all functions below MUST have an explicit 'extern' before // NOTE: all functions below MUST have an explicit 'extern' before
...@@ -90,10 +93,6 @@ ...@@ -90,10 +93,6 @@
#define GFLAGS_DLL_DECL /* rewritten to be non-empty in windows dir */ #define GFLAGS_DLL_DECL /* rewritten to be non-empty in windows dir */
#define GFLAGS_DLL_DEFINE_FLAG /* rewritten to be non-empty in windows dir */ #define GFLAGS_DLL_DEFINE_FLAG /* rewritten to be non-empty in windows dir */
namespace fL { struct OptionalDefineArgs; } // defined below
@ac_google_start_namespace@
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// To actually define a flag in a file, use DEFINE_bool, // To actually define a flag in a file, use DEFINE_bool,
...@@ -154,7 +153,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo { ...@@ -154,7 +153,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo {
std::string name; // the name of the flag std::string name; // the name of the flag
std::string type; // the type of the flag: int32, etc std::string type; // the type of the flag: int32, etc
std::string description; // the "help text" associated with the flag std::string description; // the "help text" associated with the flag
std::string categories; // the value of the "categories" arg to DEFINE_*() std::string categories; // unused (TODO(csilvers): remove this)
std::string current_value; // the current value, as a string std::string current_value; // the current value, as a string
std::string default_value; // the default value, as a string std::string default_value; // the default value, as a string
std::string filename; // 'cleaned' version of filename holding the flag std::string filename; // 'cleaned' version of filename holding the flag
...@@ -429,6 +428,10 @@ extern void ShutDownCommandLineFlags(); ...@@ -429,6 +428,10 @@ extern void ShutDownCommandLineFlags();
class GFLAGS_DLL_DECL FlagRegisterer { class GFLAGS_DLL_DECL FlagRegisterer {
public: public:
FlagRegisterer(const char* name, const char* type,
const char* help, const char* filename,
void* current_storage, void* defvalue_storage);
// TODO(csilvers): remove this once
FlagRegisterer(const char* name, const char* type, FlagRegisterer(const char* name, const char* type,
const char* help, const char* filename, const char* help, const char* filename,
void* current_storage, void* defvalue_storage, void* current_storage, void* defvalue_storage,
...@@ -454,19 +457,6 @@ extern const char kStrippedFlagHelp[]; ...@@ -454,19 +457,6 @@ extern const char kStrippedFlagHelp[];
#define MAYBE_STRIPPED_HELP(txt) txt #define MAYBE_STRIPPED_HELP(txt) txt
#endif #endif
// This holds all the optional macro argument fields that *may* be
// present in DEFINE_* after the helpstring, but are not required to
// be. We use static initialization, so they must all be POD types,
// and if not specified they default to 0.
namespace fL {
struct OptionalDefineArgs {
// A comma-separated list of "categories" this flag falls into.
// For details on categories, see gflags_categories.h.
const char* categories;
};
typedef OptionalDefineArgs ODA; // used in macros to save on code size
}
// Each command-line flag has two variables associated with it: one // Each command-line flag has two variables associated with it: one
// with the current value, and one with the default value. However, // with the current value, and one with the default value. However,
// we have a third variable, which is where value is assigned; it's a // we have a third variable, which is where value is assigned; it's a
...@@ -478,18 +468,15 @@ typedef OptionalDefineArgs ODA; // used in macros to save on code size ...@@ -478,18 +468,15 @@ typedef OptionalDefineArgs ODA; // used in macros to save on code size
// FLAGS_no<name>. This serves the second purpose of assuring a // FLAGS_no<name>. This serves the second purpose of assuring a
// compile error if someone tries to define a flag named no<name> // compile error if someone tries to define a flag named no<name>
// which is illegal (--foo and --nofoo both affect the "foo" flag). // which is illegal (--foo and --nofoo both affect the "foo" flag).
// The ... maps to the fields in OptionalDefineArgs, above. It may #define DEFINE_VARIABLE(type, shorttype, name, value, help) \
// be omitted entirely if no optional args need to be specified.
#define DEFINE_VARIABLE(type, shorttype, name, value, help, ...) \
namespace fL##shorttype { \ namespace fL##shorttype { \
static const type v_##name = value; \ static const type FLAGS_nono##name = value; \
static const ::fL::ODA e_##name = { __VA_ARGS__ }; \
/* We always want to export defined variables, dll or no */ \ /* We always want to export defined variables, dll or no */ \
GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = v_##name; \ GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \
type FLAGS_no##name = v_##name; \ type FLAGS_no##name = FLAGS_nono##name; \
static @ac_google_namespace@::FlagRegisterer o_##name( \ static @ac_google_namespace@::FlagRegisterer o_##name( \
#name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \ #name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \
&FLAGS_##name, &FLAGS_no##name, e_##name); \ &FLAGS_##name, &FLAGS_no##name); \
} \ } \
using fL##shorttype::FLAGS_##name using fL##shorttype::FLAGS_##name
...@@ -512,28 +499,27 @@ GFLAGS_DLL_DECL bool IsBoolFlag(bool from); ...@@ -512,28 +499,27 @@ GFLAGS_DLL_DECL bool IsBoolFlag(bool from);
// Here are the actual DEFINE_*-macros. The respective DECLARE_*-macros // Here are the actual DEFINE_*-macros. The respective DECLARE_*-macros
// are in a separate include, gflags_declare.h, for reducing // are in a separate include, gflags_declare.h, for reducing
// the physical transitive size for DECLARE use. // the physical transitive size for DECLARE use.
// As always, the ... maps to the fields in OptionalDefineArgs, above. #define DEFINE_bool(name, val, txt) \
#define DEFINE_bool(name, val, txt, ...) \
namespace fLB { \ namespace fLB { \
typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \ typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \
(sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \ (sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \
} \ } \
DEFINE_VARIABLE(bool, B, name, val, txt, __VA_ARGS__) DEFINE_VARIABLE(bool, B, name, val, txt)
#define DEFINE_int32(name, val, txt, ...) \ #define DEFINE_int32(name, val, txt) \
DEFINE_VARIABLE(@ac_google_namespace@::int32, I, \ DEFINE_VARIABLE(@ac_google_namespace@::int32, I, \
name, val, txt, __VA_ARGS__) name, val, txt)
#define DEFINE_int64(name, val, txt, ...) \ #define DEFINE_int64(name, val, txt) \
DEFINE_VARIABLE(@ac_google_namespace@::int64, I64, \ DEFINE_VARIABLE(@ac_google_namespace@::int64, I64, \
name, val, txt, __VA_ARGS__) name, val, txt)
#define DEFINE_uint64(name,val, txt, ...) \ #define DEFINE_uint64(name,val, txt) \
DEFINE_VARIABLE(@ac_google_namespace@::uint64, U64, \ DEFINE_VARIABLE(@ac_google_namespace@::uint64, U64, \
name, val, txt, __VA_ARGS__) name, val, txt)
#define DEFINE_double(name, val, txt, ...) \ #define DEFINE_double(name, val, txt) \
DEFINE_VARIABLE(double, D, name, val, txt, __VA_ARGS__) DEFINE_VARIABLE(double, D, name, val, txt)
// Strings are trickier, because they're not a POD, so we can't // Strings are trickier, because they're not a POD, so we can't
// construct them at static-initialization time (instead they get // construct them at static-initialization time (instead they get
...@@ -563,19 +549,16 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot, ...@@ -563,19 +549,16 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot,
// The weird 'using' + 'extern' inside the fLS namespace is to work around // The weird 'using' + 'extern' inside the fLS namespace is to work around
// an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See // an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See
// http://code.google.com/p/google-gflags/issues/detail?id=20 // http://code.google.com/p/google-gflags/issues/detail?id=20
// As always, the ... maps to the fields in OptionalDefineArgs, above. #define DEFINE_string(name, val, txt) \
#define DEFINE_string(name, val, txt, ...) \
namespace fLS { \ namespace fLS { \
using ::fLS::clstring; \ using ::fLS::clstring; \
static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \ static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \
clstring* const FLAGS_no##name = ::fLS:: \ clstring* const FLAGS_no##name = ::fLS:: \
dont_pass0toDEFINE_string(s_##name[0].s, \ dont_pass0toDEFINE_string(s_##name[0].s, \
val); \ val); \
static const ::fL::ODA e_##name = { __VA_ARGS__ }; \
static @ac_google_namespace@::FlagRegisterer o_##name( \ static @ac_google_namespace@::FlagRegisterer o_##name( \
#name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \ #name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \
s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name), \ s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name)); \
e_##name); \
extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \ extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \
using fLS::FLAGS_##name; \ using fLS::FLAGS_##name; \
clstring& FLAGS_##name = *FLAGS_no##name; \ clstring& FLAGS_##name = *FLAGS_no##name; \
......
...@@ -212,7 +212,6 @@ static string DescribeOneFlagInXML(const CommandLineFlagInfo& flag) { ...@@ -212,7 +212,6 @@ static string DescribeOneFlagInXML(const CommandLineFlagInfo& flag) {
AddXMLTag(&r, "file", flag.filename); AddXMLTag(&r, "file", flag.filename);
AddXMLTag(&r, "name", flag.name); AddXMLTag(&r, "name", flag.name);
AddXMLTag(&r, "meaning", flag.description); AddXMLTag(&r, "meaning", flag.description);
AddXMLTag(&r, "categories", flag.categories);
AddXMLTag(&r, "default", flag.default_value); AddXMLTag(&r, "default", flag.default_value);
AddXMLTag(&r, "current", flag.current_value); AddXMLTag(&r, "current", flag.current_value);
AddXMLTag(&r, "type", flag.type); AddXMLTag(&r, "type", flag.type);
......
...@@ -77,8 +77,7 @@ DEFINE_string(srcdir, StringFromEnv("SRCDIR", "."), ...@@ -77,8 +77,7 @@ DEFINE_string(srcdir, StringFromEnv("SRCDIR", "."),
DECLARE_string(tryfromenv); // in gflags.cc DECLARE_string(tryfromenv); // in gflags.cc
// This 4th arg specifies the 'categories' the flag belongs to. DEFINE_bool(test_bool, false, "tests bool-ness");
DEFINE_bool(test_bool, false, "tests bool-ness", "important,has_category");
DEFINE_int32(test_int32, -1, ""); DEFINE_int32(test_int32, -1, "");
DEFINE_int64(test_int64, -2, ""); DEFINE_int64(test_int64, -2, "");
DEFINE_uint64(test_uint64, 2, ""); DEFINE_uint64(test_uint64, 2, "");
...@@ -96,7 +95,6 @@ DEFINE_bool(test_bool_with_quite_quite_quite_quite_quite_quite_quite_quite_quite ...@@ -96,7 +95,6 @@ DEFINE_bool(test_bool_with_quite_quite_quite_quite_quite_quite_quite_quite_quite
DEFINE_string(test_str1, "initial", ""); DEFINE_string(test_str1, "initial", "");
DEFINE_string(test_str2, "initial", ""); DEFINE_string(test_str2, "initial", "");
DEFINE_string(test_str3, "initial", ""); DEFINE_string(test_str3, "initial", "");
DEFINE_string(test_str_with_category, "", "", "required,filename");
// This is used to test setting tryfromenv manually // This is used to test setting tryfromenv manually
DEFINE_string(test_tryfromenv, "initial", ""); DEFINE_string(test_tryfromenv, "initial", "");
...@@ -218,8 +216,6 @@ MAKEFLAG100(15); ...@@ -218,8 +216,6 @@ MAKEFLAG100(15);
#undef MAKEFLAG10 #undef MAKEFLAG10
#undef MAKEFLAG #undef MAKEFLAG
static fL::OptionalDefineArgs no_optional_args = { };
// This is a pseudo-flag -- we want to register a flag with a filename // This is a pseudo-flag -- we want to register a flag with a filename
// at the top level, but there is no way to do this except by faking // at the top level, but there is no way to do this except by faking
// the filename. // the filename.
...@@ -230,7 +226,7 @@ namespace fLI { ...@@ -230,7 +226,7 @@ namespace fLI {
static FlagRegisterer o_tldflag1( static FlagRegisterer o_tldflag1(
"tldflag1", "int32", "tldflag1", "int32",
"should show up in --helpshort", "gflags_unittest.cc", "should show up in --helpshort", "gflags_unittest.cc",
&FLAGS_tldflag1, &FLAGS_notldflag1, no_optional_args); &FLAGS_tldflag1, &FLAGS_notldflag1);
} }
using fLI::FLAGS_tldflag1; using fLI::FLAGS_tldflag1;
...@@ -241,7 +237,7 @@ namespace fLI { ...@@ -241,7 +237,7 @@ namespace fLI {
static FlagRegisterer o_tldflag2( static FlagRegisterer o_tldflag2(
"tldflag2", "int32", "tldflag2", "int32",
"should show up in --helpshort", "gflags_unittest.", "should show up in --helpshort", "gflags_unittest.",
&FLAGS_tldflag2, &FLAGS_notldflag2, no_optional_args); &FLAGS_tldflag2, &FLAGS_notldflag2);
} }
using fLI::FLAGS_tldflag2; using fLI::FLAGS_tldflag2;
...@@ -991,32 +987,18 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { ...@@ -991,32 +987,18 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) {
EXPECT_EQ("test_int32", info.name); EXPECT_EQ("test_int32", info.name);
EXPECT_EQ("int32", info.type); EXPECT_EQ("int32", info.type);
EXPECT_EQ("", info.description); EXPECT_EQ("", info.description);
EXPECT_EQ("", info.categories);
EXPECT_EQ("-1", info.current_value); EXPECT_EQ("-1", info.current_value);
EXPECT_EQ("-1", info.default_value); EXPECT_EQ("-1", info.default_value);
EXPECT_TRUE(info.is_default); EXPECT_TRUE(info.is_default);
EXPECT_FALSE(info.has_validator_fn); EXPECT_FALSE(info.has_validator_fn);
EXPECT_EQ(&FLAGS_test_int32, info.flag_ptr); EXPECT_EQ(&FLAGS_test_int32, info.flag_ptr);
r = GetCommandLineFlagInfo("test_str_with_category", &info);
EXPECT_TRUE(r);
EXPECT_EQ("test_str_with_category", info.name);
EXPECT_EQ("string", info.type);
EXPECT_EQ("", info.description);
EXPECT_EQ("required,filename", info.categories);
EXPECT_EQ("", info.current_value);
EXPECT_EQ("", info.default_value);
EXPECT_TRUE(info.is_default);
EXPECT_FALSE(info.has_validator_fn);
EXPECT_EQ(&FLAGS_test_str_with_category, info.flag_ptr);
FLAGS_test_bool = true; FLAGS_test_bool = true;
r = GetCommandLineFlagInfo("test_bool", &info); r = GetCommandLineFlagInfo("test_bool", &info);
EXPECT_TRUE(r); EXPECT_TRUE(r);
EXPECT_EQ("test_bool", info.name); EXPECT_EQ("test_bool", info.name);
EXPECT_EQ("bool", info.type); EXPECT_EQ("bool", info.type);
EXPECT_EQ("tests bool-ness", info.description); EXPECT_EQ("tests bool-ness", info.description);
EXPECT_EQ("important,has_category", info.categories);
EXPECT_EQ("true", info.current_value); EXPECT_EQ("true", info.current_value);
EXPECT_EQ("false", info.default_value); EXPECT_EQ("false", info.default_value);
EXPECT_FALSE(info.is_default); EXPECT_FALSE(info.is_default);
...@@ -1029,7 +1011,6 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { ...@@ -1029,7 +1011,6 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) {
EXPECT_EQ("test_bool", info.name); EXPECT_EQ("test_bool", info.name);
EXPECT_EQ("bool", info.type); EXPECT_EQ("bool", info.type);
EXPECT_EQ("tests bool-ness", info.description); EXPECT_EQ("tests bool-ness", info.description);
EXPECT_EQ("important,has_category", info.categories);
EXPECT_EQ("false", info.current_value); EXPECT_EQ("false", info.current_value);
EXPECT_EQ("false", info.default_value); EXPECT_EQ("false", info.default_value);
EXPECT_FALSE(info.is_default); // value is same, but flag *was* modified EXPECT_FALSE(info.is_default); // value is same, but flag *was* modified
...@@ -1364,7 +1345,7 @@ TEST(ParseCommandLineFlagsWrongFields, ...@@ -1364,7 +1345,7 @@ TEST(ParseCommandLineFlagsWrongFields,
static bool current_storage; static bool current_storage;
static bool defvalue_storage; static bool defvalue_storage;
FlagRegisterer fr("flag_name", "bool", 0, "filename", FlagRegisterer fr("flag_name", "bool", 0, "filename",
&current_storage, &defvalue_storage, no_optional_args); &current_storage, &defvalue_storage);
CommandLineFlagInfo fi; CommandLineFlagInfo fi;
EXPECT_TRUE(GetCommandLineFlagInfo("flag_name", &fi)); EXPECT_TRUE(GetCommandLineFlagInfo("flag_name", &fi));
EXPECT_EQ("", fi.description); EXPECT_EQ("", fi.description);
......
...@@ -182,8 +182,6 @@ Expect $LINENO 1 "/gflags_reporting.cc" "" --helppackage ...@@ -182,8 +182,6 @@ Expect $LINENO 1 "/gflags_reporting.cc" "" --helppackage
# xml! # xml!
Expect $LINENO 1 "/gflags_unittest.cc</file>" \ Expect $LINENO 1 "/gflags_unittest.cc</file>" \
"/gflags_unittest.cc:" --helpxml "/gflags_unittest.cc:" --helpxml
Expect $LINENO 1 "<name>test_bool</name><meaning>tests bool-ness</meaning><categories>important,has_category</categories><default>false</default><current>false</current><type>bool</type>" \
"/gflags_unittest.cc:" --helpxml
# just print the version info and exit # just print the version info and exit
Expect $LINENO 0 "gflags_unittest" "gflags_unittest.cc" --version Expect $LINENO 0 "gflags_unittest" "gflags_unittest.cc" --version
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
// //
// DEFINE_int32(end, 1000, "The last record to read"); // DEFINE_int32(end, 1000, "The last record to read");
// //
// DEFINE_string(filename, "my_file.txt", "The file to read", "important"); // DEFINE_string(filename, "my_file.txt", "The file to read");
// // Crash if the specified file does not exist. // // Crash if the specified file does not exist.
// static bool dummy = RegisterFlagValidator(&FLAGS_filename, // static bool dummy = RegisterFlagValidator(&FLAGS_filename,
// &ValidateIsFile); // &ValidateIsFile);
...@@ -81,6 +81,9 @@ ...@@ -81,6 +81,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <gflags/gflags_declare.h> // IWYU pragma: export #include <gflags/gflags_declare.h> // IWYU pragma: export
namespace google {
namespace fL { struct OptionalDefineArgs { }; } // TODO(csilvers): remove
// //
// NOTE: all functions below MUST have an explicit 'extern' before // NOTE: all functions below MUST have an explicit 'extern' before
...@@ -94,10 +97,6 @@ ...@@ -94,10 +97,6 @@
# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport) # define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport)
#endif #endif
namespace fL { struct OptionalDefineArgs; } // defined below
namespace google {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// To actually define a flag in a file, use DEFINE_bool, // To actually define a flag in a file, use DEFINE_bool,
...@@ -158,7 +157,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo { ...@@ -158,7 +157,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo {
std::string name; // the name of the flag std::string name; // the name of the flag
std::string type; // the type of the flag: int32, etc std::string type; // the type of the flag: int32, etc
std::string description; // the "help text" associated with the flag std::string description; // the "help text" associated with the flag
std::string categories; // the value of the "categories" arg to DEFINE_*() std::string categories; // unused (TODO(csilvers): remove this)
std::string current_value; // the current value, as a string std::string current_value; // the current value, as a string
std::string default_value; // the default value, as a string std::string default_value; // the default value, as a string
std::string filename; // 'cleaned' version of filename holding the flag std::string filename; // 'cleaned' version of filename holding the flag
...@@ -433,6 +432,10 @@ extern GFLAGS_DLL_DECL void ShutDownCommandLineFlags(); ...@@ -433,6 +432,10 @@ extern GFLAGS_DLL_DECL void ShutDownCommandLineFlags();
class GFLAGS_DLL_DECL FlagRegisterer { class GFLAGS_DLL_DECL FlagRegisterer {
public: public:
FlagRegisterer(const char* name, const char* type,
const char* help, const char* filename,
void* current_storage, void* defvalue_storage);
// TODO(csilvers): remove this once
FlagRegisterer(const char* name, const char* type, FlagRegisterer(const char* name, const char* type,
const char* help, const char* filename, const char* help, const char* filename,
void* current_storage, void* defvalue_storage, void* current_storage, void* defvalue_storage,
...@@ -458,19 +461,6 @@ extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[]; ...@@ -458,19 +461,6 @@ extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[];
#define MAYBE_STRIPPED_HELP(txt) txt #define MAYBE_STRIPPED_HELP(txt) txt
#endif #endif
// This holds all the optional macro argument fields that *may* be
// present in DEFINE_* after the helpstring, but are not required to
// be. We use static initialization, so they must all be POD types,
// and if not specified they default to 0.
namespace fL {
struct OptionalDefineArgs {
// A comma-separated list of "categories" this flag falls into.
// For details on categories, see gflags_categories.h.
const char* categories;
};
typedef OptionalDefineArgs ODA; // used in macros to save on code size
}
// Each command-line flag has two variables associated with it: one // Each command-line flag has two variables associated with it: one
// with the current value, and one with the default value. However, // with the current value, and one with the default value. However,
// we have a third variable, which is where value is assigned; it's a // we have a third variable, which is where value is assigned; it's a
...@@ -482,18 +472,15 @@ typedef OptionalDefineArgs ODA; // used in macros to save on code size ...@@ -482,18 +472,15 @@ typedef OptionalDefineArgs ODA; // used in macros to save on code size
// FLAGS_no<name>. This serves the second purpose of assuring a // FLAGS_no<name>. This serves the second purpose of assuring a
// compile error if someone tries to define a flag named no<name> // compile error if someone tries to define a flag named no<name>
// which is illegal (--foo and --nofoo both affect the "foo" flag). // which is illegal (--foo and --nofoo both affect the "foo" flag).
// The ... maps to the fields in OptionalDefineArgs, above. It may #define DEFINE_VARIABLE(type, shorttype, name, value, help) \
// be omitted entirely if no optional args need to be specified.
#define DEFINE_VARIABLE(type, shorttype, name, value, help, ...) \
namespace fL##shorttype { \ namespace fL##shorttype { \
static const type v_##name = value; \ static const type FLAGS_nono##name = value; \
static const ::fL::ODA e_##name = { __VA_ARGS__ }; \
/* We always want to export defined variables, dll or no */ \ /* We always want to export defined variables, dll or no */ \
GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = v_##name; \ GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \
type FLAGS_no##name = v_##name; \ type FLAGS_no##name = FLAGS_nono##name; \
static ::google::FlagRegisterer o_##name( \ static ::google::FlagRegisterer o_##name( \
#name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \ #name, #type, MAYBE_STRIPPED_HELP(help), __FILE__, \
&FLAGS_##name, &FLAGS_no##name, e_##name); \ &FLAGS_##name, &FLAGS_no##name); \
} \ } \
using fL##shorttype::FLAGS_##name using fL##shorttype::FLAGS_##name
...@@ -516,28 +503,27 @@ GFLAGS_DLL_DECL bool IsBoolFlag(bool from); ...@@ -516,28 +503,27 @@ GFLAGS_DLL_DECL bool IsBoolFlag(bool from);
// Here are the actual DEFINE_*-macros. The respective DECLARE_*-macros // Here are the actual DEFINE_*-macros. The respective DECLARE_*-macros
// are in a separate include, gflags_declare.h, for reducing // are in a separate include, gflags_declare.h, for reducing
// the physical transitive size for DECLARE use. // the physical transitive size for DECLARE use.
// As always, the ... maps to the fields in OptionalDefineArgs, above. #define DEFINE_bool(name, val, txt) \
#define DEFINE_bool(name, val, txt, ...) \
namespace fLB { \ namespace fLB { \
typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \ typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \
(sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \ (sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \
} \ } \
DEFINE_VARIABLE(bool, B, name, val, txt, __VA_ARGS__) DEFINE_VARIABLE(bool, B, name, val, txt)
#define DEFINE_int32(name, val, txt, ...) \ #define DEFINE_int32(name, val, txt) \
DEFINE_VARIABLE(::google::int32, I, \ DEFINE_VARIABLE(::google::int32, I, \
name, val, txt, __VA_ARGS__) name, val, txt)
#define DEFINE_int64(name, val, txt, ...) \ #define DEFINE_int64(name, val, txt) \
DEFINE_VARIABLE(::google::int64, I64, \ DEFINE_VARIABLE(::google::int64, I64, \
name, val, txt, __VA_ARGS__) name, val, txt)
#define DEFINE_uint64(name,val, txt, ...) \ #define DEFINE_uint64(name,val, txt) \
DEFINE_VARIABLE(::google::uint64, U64, \ DEFINE_VARIABLE(::google::uint64, U64, \
name, val, txt, __VA_ARGS__) name, val, txt)
#define DEFINE_double(name, val, txt, ...) \ #define DEFINE_double(name, val, txt) \
DEFINE_VARIABLE(double, D, name, val, txt, __VA_ARGS__) DEFINE_VARIABLE(double, D, name, val, txt)
// Strings are trickier, because they're not a POD, so we can't // Strings are trickier, because they're not a POD, so we can't
// construct them at static-initialization time (instead they get // construct them at static-initialization time (instead they get
...@@ -567,19 +553,16 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot, ...@@ -567,19 +553,16 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot,
// The weird 'using' + 'extern' inside the fLS namespace is to work around // The weird 'using' + 'extern' inside the fLS namespace is to work around
// an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See // an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See
// http://code.google.com/p/google-gflags/issues/detail?id=20 // http://code.google.com/p/google-gflags/issues/detail?id=20
// As always, the ... maps to the fields in OptionalDefineArgs, above. #define DEFINE_string(name, val, txt) \
#define DEFINE_string(name, val, txt, ...) \
namespace fLS { \ namespace fLS { \
using ::fLS::clstring; \ using ::fLS::clstring; \
static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \ static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \
clstring* const FLAGS_no##name = ::fLS:: \ clstring* const FLAGS_no##name = ::fLS:: \
dont_pass0toDEFINE_string(s_##name[0].s, \ dont_pass0toDEFINE_string(s_##name[0].s, \
val); \ val); \
static const ::fL::ODA e_##name = { __VA_ARGS__ }; \
static ::google::FlagRegisterer o_##name( \ static ::google::FlagRegisterer o_##name( \
#name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \ #name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \
s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name), \ s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name)); \
e_##name); \
extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \ extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \
using fLS::FLAGS_##name; \ using fLS::FLAGS_##name; \
clstring& FLAGS_##name = *FLAGS_no##name; \ clstring& FLAGS_##name = *FLAGS_no##name; \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment