X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fportability%2FGFlags.h;h=48bd125da73655fe1cd5b478c71369f7cf68c26b;hb=cffc8a776b21a070f0af6ed0748452c329ad6e5f;hp=d28c6a281eabd774acff06a44398e37c3b76b349;hpb=dee8a5180aa542d98d1b71c74f83a006e4627952;p=folly.git diff --git a/folly/portability/GFlags.h b/folly/portability/GFlags.h index d28c6a28..48bd125d 100644 --- a/folly/portability/GFlags.h +++ b/folly/portability/GFlags.h @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,53 @@ #pragma once -#include +#include + +#if !FOLLY_HAVE_LIBGFLAGS +// glog/logging.h is dependent on this implementation detail +// being defined otherwise it undefines all of this -_-.... +// +// Also, this is deliberately expanded such that places using +// it directly break loudly. (C will break louder than C++, but oh well) +#define DECLARE_VARIABLE() \ + static_assert(false, "You shouldn't be using GFlags internals."); + +#define FOLLY_DECLARE_FLAG(_type, _shortType, _name) \ + namespace fL##_shortType { \ + extern _type FLAGS_##_name; \ + } \ + using fL##_shortType::FLAGS_##_name + +#define DECLARE_bool(_name) FOLLY_DECLARE_FLAG(bool, B, _name) +#define DECLARE_double(_name) FOLLY_DECLARE_FLAG(double, D, _name) +#define DECLARE_int32(_name) FOLLY_DECLARE_FLAG(int, I, _name) +#define DECLARE_int64(_name) FOLLY_DECLARE_FLAG(long long, I64, _name) +#define DECLARE_uint64(_name) FOLLY_DECLARE_FLAG(unsigned long long, U64, _name) +#define DECLARE_string(_name) FOLLY_DECLARE_FLAG(std::string, S, _name) + +#define FOLLY_DEFINE_FLAG(_type, _shortType, _name, _default) \ + namespace fL##_shortType { \ + _type FLAGS_##_name = _default; \ + } \ + using fL##_shortType::FLAGS_##_name + +#define DEFINE_bool(_name, _default, _description) \ + FOLLY_DEFINE_FLAG(bool, B, _name, _default) +#define DEFINE_double(_name, _default, _description) \ + FOLLY_DEFINE_FLAG(double, D, _name, _default) +#define DEFINE_int32(_name, _default, _description) \ + FOLLY_DEFINE_FLAG(int, I, _name, _default) +#define DEFINE_int64(_name, _default, _description) \ + FOLLY_DEFINE_FLAG(long long, I64, _name, _default) +#define DEFINE_uint64(_name, _default, _description) \ + FOLLY_DEFINE_FLAG(unsigned long long, U64, _name, _default) +#define DEFINE_string(_name, _default, _description) \ + FOLLY_DEFINE_FLAG(std::string, S, _name, _default) + +namespace google { +class FlagSaver {}; +} -#if FOLLY_HAVE_LIBGFLAGS -#include #else -#define DEFINE_int32(_name, _default, _description) int FLAGS_##_name = _default +#include #endif