1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #include "gflags/gflags.h"
class GFLAGS_DLL_DECL FlagRegisterer { public: template <typename FlagType> FlagRegisterer(const char *name, const char *help, const char *filename, FlagType *current_storage, FlagType *defvalue_storage) { FlagValue *const current = new FlagValue(current_storage, false); FlagValue *const defvalue = new FlagValue(defvalue_storage, false); RegisterCommandLineFlag(name, help, filename, current, defvalue); } };
#define DEFINE_VARIABLE(type, shorttype, name, value, help) \ namespace fL##shorttype { \ static const type FLAGS_nono##name = value; \ GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \ type FLAGS_no##name = FLAGS_nono##name; \ static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \ #name, MAYBE_STRIPPED_HELP(help), __FILE__, &FLAGS_##name, &FLAGS_no##name); \ } \ using fL##shorttype::FLAGS_##name
#define DEFINE_bool(name, val, txt) \ namespace fLB { \ typedef ::fLB::CompileAssert \ FLAG_##name##_value_is_not_a_bool[(sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \ } \ DEFINE_VARIABLE(bool, B, name, val, txt)
#define DEFINE_int32(name, val, txt) DEFINE_VARIABLE(GFLAGS_NAMESPACE::int32, I, name, val, txt) #define DEFINE_uint32(name, val, txt) DEFINE_VARIABLE(GFLAGS_NAMESPACE::uint32, U, name, val, txt) #define DEFINE_int64(name, val, txt) DEFINE_VARIABLE(GFLAGS_NAMESPACE::int64, I64, name, val, txt) #define DEFINE_uint64(name, val, txt) DEFINE_VARIABLE(GFLAGS_NAMESPACE::uint64, U64, name, val, txt) #define DEFINE_double(name, val, txt) DEFINE_VARIABLE(double, D, name, val, txt) #define DEFINE_string(name, val, txt) \ namespace fLS { \ using ::fLS::clstring; \ using ::fLS::StringFlagDestructor; \ static union { \ void *align; \ char s[sizeof(clstring)]; \ } s_##name[2]; \ clstring *const FLAGS_no##name = ::fLS::dont_pass0toDEFINE_string(s_##name[0].s, val); \ static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \ #name, MAYBE_STRIPPED_HELP(txt), __FILE__, FLAGS_no##name, new (s_##name[1].s) clstring(*FLAGS_no##name)); \ static StringFlagDestructor d_##name(s_##name[0].s, s_##name[1].s); \ extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \ using fLS::FLAGS_##name; \ clstring& FLAGS_##name = *FLAGS_no##name; \ } \ using fLS::FLAGS_##name
|