diff options
author | Andreas Schuh <andreas.schuh.84@gmail.com> | 2013-04-20 18:35:34 +0000 |
---|---|---|
committer | Andreas Schuh <andreas.schuh.84@gmail.com> | 2013-04-20 18:35:34 +0000 |
commit | 45a53dea87d3c732ab81cd1154b15e07055823dd (patch) | |
tree | 6d802d63e22ec1884f3b37fb8ec7ca2f5628db7a | |
parent | 8011f612470309955d357679324937e369096589 (diff) | |
download | gflags-45a53dea87d3c732ab81cd1154b15e07055823dd.tar.gz gflags-45a53dea87d3c732ab81cd1154b15e07055823dd.tar.bz2 gflags-45a53dea87d3c732ab81cd1154b15e07055823dd.zip |
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
-rw-r--r-- | src/gflags/gflags.h.in | 5 | ||||
-rw-r--r-- | src/gflags_unittest.cc | 9 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/gflags/gflags.h.in b/src/gflags/gflags.h.in index dd51a2d..eb084f5 100644 --- a/src/gflags/gflags.h.in +++ b/src/gflags/gflags.h.in @@ -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 diff --git a/src/gflags_unittest.cc b/src/gflags_unittest.cc index 08abc1b..cce60d9 100644 --- a/src/gflags_unittest.cc +++ b/src/gflags_unittest.cc @@ -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") |