Commit 45a53dea authored by Andreas Schuh's avatar Andreas Schuh

Add DEFINE_validator macro for convenient registration of a flag validator.

git-svn-id: https://gflags.googlecode.com/svn/trunk@82 6586e3c6-dcc4-952a-343f-ff74eb82781d
parent 8011f612
......@@ -135,6 +135,11 @@ extern bool RegisterFlagValidator(const std::string* flag,
bool (*validate_fn)(const char*,
const std::string&));
// Convenience macro for the registration of a flag validator
#define DEFINE_validator(name, validator) \
static const bool name##_validator_registered = \
@ac_google_namespace@::RegisterFlagValidator(&FLAGS_##name, validator)
// --------------------------------------------------------------------
// These methods are the best way to get access to info about the
......
......@@ -143,9 +143,7 @@ DEFINE_bool(long_helpstring, false,
static bool AlwaysFail(const char* flag, bool value) { return value == false; }
DEFINE_bool(always_fail, false, "will fail to validate when you set it");
namespace {
bool dummy = RegisterFlagValidator(&FLAGS_always_fail, AlwaysFail);
}
DEFINE_validator(always_fail, AlwaysFail);
// See the comment by GetAllFlags in gflags.h
static bool DeadlockIfCantLockInValidators(const char* flag, bool value) {
......@@ -160,10 +158,7 @@ DEFINE_bool(deadlock_if_cant_lock,
false,
"will deadlock if set to true and "
"if locking of registry in validators fails.");
namespace {
bool dummy1 = RegisterFlagValidator(&FLAGS_deadlock_if_cant_lock,
DeadlockIfCantLockInValidators);
}
DEFINE_validator(deadlock_if_cant_lock, DeadlockIfCantLockInValidators);
#define MAKEFLAG(x) DEFINE_int32(test_flag_num##x, x, "Test flag")
......
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