proxygen
GFlags.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
20 
21 #if !FOLLY_HAVE_LIBGFLAGS
22 // glog/logging.h is dependent on this implementation detail
23 // being defined otherwise it undefines all of this -_-....
24 //
25 // Also, this is deliberately expanded such that places using
26 // it directly break loudly. (C will break louder than C++, but oh well)
27 #define DECLARE_VARIABLE() \
28  static_assert(false, "You shouldn't be using GFlags internals.");
29 
30 #define FOLLY_DECLARE_FLAG(_type, _shortType, _name) \
31  namespace fL##_shortType { \
32  extern _type FLAGS_##_name; \
33  } \
34  using fL##_shortType::FLAGS_##_name
35 
36 #define DECLARE_bool(_name) FOLLY_DECLARE_FLAG(bool, B, _name)
37 #define DECLARE_double(_name) FOLLY_DECLARE_FLAG(double, D, _name)
38 #define DECLARE_int32(_name) FOLLY_DECLARE_FLAG(int, I, _name)
39 #define DECLARE_int64(_name) FOLLY_DECLARE_FLAG(long long, I64, _name)
40 #define DECLARE_uint32(_name) FOLLY_DECLARE_FLAG(unsigned long, U32, _name)
41 #define DECLARE_uint64(_name) FOLLY_DECLARE_FLAG(unsigned long long, U64, _name)
42 #define DECLARE_string(_name) FOLLY_DECLARE_FLAG(std::string, S, _name)
43 
44 #define FOLLY_DEFINE_FLAG(_type, _shortType, _name, _default) \
45  namespace fL##_shortType { \
46  _type FLAGS_##_name = _default; \
47  } \
48  using fL##_shortType::FLAGS_##_name
49 
50 #define DEFINE_bool(_name, _default, _description) \
51  FOLLY_DEFINE_FLAG(bool, B, _name, _default)
52 #define DEFINE_double(_name, _default, _description) \
53  FOLLY_DEFINE_FLAG(double, D, _name, _default)
54 #define DEFINE_int32(_name, _default, _description) \
55  FOLLY_DEFINE_FLAG(int, I, _name, _default)
56 #define DEFINE_int64(_name, _default, _description) \
57  FOLLY_DEFINE_FLAG(long long, I64, _name, _default)
58 #define DEFINE_uint32(_name, _default, _description) \
59  FOLLY_DEFINE_FLAG(unsigned long, U32, _name, _default)
60 #define DEFINE_uint64(_name, _default, _description) \
61  FOLLY_DEFINE_FLAG(unsigned long long, U64, _name, _default)
62 #define DEFINE_string(_name, _default, _description) \
63  FOLLY_DEFINE_FLAG(std::string, S, _name, _default)
64 
65 namespace google {
66 class FlagSaver {};
67 } // namespace google
68 
69 #else
70 #include <gflags/gflags.h>
71 #endif
Definition: GFlags.h:65