Austin Schuh | 1eb16d1 | 2015-09-06 17:21:56 -0700 | [diff] [blame] | 1 | // Copyright (c) 1999, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | // --- |
| 31 | // |
| 32 | // Revamped and reorganized by Craig Silverstein |
| 33 | // |
| 34 | // This is the file that should be included by any file which declares |
| 35 | // command line flag. |
| 36 | |
| 37 | #ifndef GFLAGS_DECLARE_H_ |
| 38 | #define GFLAGS_DECLARE_H_ |
| 39 | |
| 40 | |
| 41 | // --------------------------------------------------------------------------- |
| 42 | // Namespace of gflags library symbols. |
| 43 | #define GFLAGS_NAMESPACE @GFLAGS_NAMESPACE@ |
| 44 | |
| 45 | // --------------------------------------------------------------------------- |
| 46 | // Windows DLL import/export. |
| 47 | |
Austin Schuh | 8fec4f4 | 2018-10-29 21:52:32 -0700 | [diff] [blame] | 48 | // Whether gflags library is a DLL. |
| 49 | // |
| 50 | // Set to 1 by default when the shared gflags library was built on Windows. |
| 51 | // Must be overwritten when this header file is used with the optionally also |
| 52 | // built static library instead; set by CMake's INTERFACE_COMPILE_DEFINITIONS. |
| 53 | #ifndef GFLAGS_IS_A_DLL |
| 54 | # define GFLAGS_IS_A_DLL @GFLAGS_IS_A_DLL@ |
| 55 | #endif |
| 56 | |
| 57 | // We always want to import the symbols of the gflags library. |
Austin Schuh | 1eb16d1 | 2015-09-06 17:21:56 -0700 | [diff] [blame] | 58 | #ifndef GFLAGS_DLL_DECL |
Austin Schuh | 8fec4f4 | 2018-10-29 21:52:32 -0700 | [diff] [blame] | 59 | # if GFLAGS_IS_A_DLL && defined(_MSC_VER) |
Austin Schuh | 1eb16d1 | 2015-09-06 17:21:56 -0700 | [diff] [blame] | 60 | # define GFLAGS_DLL_DECL __declspec(dllimport) |
| 61 | # else |
| 62 | # define GFLAGS_DLL_DECL |
| 63 | # endif |
| 64 | #endif |
| 65 | |
Austin Schuh | 8fec4f4 | 2018-10-29 21:52:32 -0700 | [diff] [blame] | 66 | // We always want to import variables declared in user code. |
Austin Schuh | 1eb16d1 | 2015-09-06 17:21:56 -0700 | [diff] [blame] | 67 | #ifndef GFLAGS_DLL_DECLARE_FLAG |
Austin Schuh | 8fec4f4 | 2018-10-29 21:52:32 -0700 | [diff] [blame] | 68 | # if GFLAGS_IS_A_DLL && defined(_MSC_VER) |
Austin Schuh | 1eb16d1 | 2015-09-06 17:21:56 -0700 | [diff] [blame] | 69 | # define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport) |
| 70 | # else |
| 71 | # define GFLAGS_DLL_DECLARE_FLAG |
| 72 | # endif |
| 73 | #endif |
| 74 | |
| 75 | // --------------------------------------------------------------------------- |
| 76 | // Flag types |
| 77 | #include <string> |
| 78 | #if @HAVE_STDINT_H@ |
| 79 | # include <stdint.h> // the normal place uint32_t is defined |
| 80 | #elif @HAVE_SYS_TYPES_H@ |
| 81 | # include <sys/types.h> // the normal place u_int32_t is defined |
| 82 | #elif @HAVE_INTTYPES_H@ |
| 83 | # include <inttypes.h> // a third place for uint32_t or u_int32_t |
| 84 | #endif |
| 85 | |
| 86 | namespace GFLAGS_NAMESPACE { |
| 87 | |
| 88 | #if @GFLAGS_INTTYPES_FORMAT_C99@ // C99 |
| 89 | typedef int32_t int32; |
| 90 | typedef uint32_t uint32; |
| 91 | typedef int64_t int64; |
| 92 | typedef uint64_t uint64; |
| 93 | #elif @GFLAGS_INTTYPES_FORMAT_BSD@ // BSD |
| 94 | typedef int32_t int32; |
| 95 | typedef u_int32_t uint32; |
| 96 | typedef int64_t int64; |
| 97 | typedef u_int64_t uint64; |
| 98 | #elif @GFLAGS_INTTYPES_FORMAT_VC7@ // Windows |
| 99 | typedef __int32 int32; |
| 100 | typedef unsigned __int32 uint32; |
| 101 | typedef __int64 int64; |
| 102 | typedef unsigned __int64 uint64; |
| 103 | #else |
| 104 | # error Do not know how to define a 32-bit integer quantity on your system |
| 105 | #endif |
| 106 | |
| 107 | } // namespace GFLAGS_NAMESPACE |
| 108 | |
| 109 | |
| 110 | namespace fLS { |
| 111 | |
| 112 | // The meaning of "string" might be different between now and when the |
| 113 | // macros below get invoked (e.g., if someone is experimenting with |
| 114 | // other string implementations that get defined after this file is |
| 115 | // included). Save the current meaning now and use it in the macros. |
| 116 | typedef std::string clstring; |
| 117 | |
| 118 | } // namespace fLS |
| 119 | |
| 120 | |
| 121 | #define DECLARE_VARIABLE(type, shorttype, name) \ |
| 122 | /* We always want to import declared variables, dll or no */ \ |
| 123 | namespace fL##shorttype { extern GFLAGS_DLL_DECLARE_FLAG type FLAGS_##name; } \ |
| 124 | using fL##shorttype::FLAGS_##name |
| 125 | |
| 126 | #define DECLARE_bool(name) \ |
| 127 | DECLARE_VARIABLE(bool, B, name) |
| 128 | |
| 129 | #define DECLARE_int32(name) \ |
| 130 | DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int32, I, name) |
| 131 | |
Austin Schuh | 8fec4f4 | 2018-10-29 21:52:32 -0700 | [diff] [blame] | 132 | #define DECLARE_uint32(name) \ |
| 133 | DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint32, U, name) |
| 134 | |
Austin Schuh | 1eb16d1 | 2015-09-06 17:21:56 -0700 | [diff] [blame] | 135 | #define DECLARE_int64(name) \ |
| 136 | DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int64, I64, name) |
| 137 | |
| 138 | #define DECLARE_uint64(name) \ |
| 139 | DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint64, U64, name) |
| 140 | |
| 141 | #define DECLARE_double(name) \ |
| 142 | DECLARE_VARIABLE(double, D, name) |
| 143 | |
| 144 | #define DECLARE_string(name) \ |
| 145 | /* We always want to import declared variables, dll or no */ \ |
| 146 | namespace fLS { \ |
Austin Schuh | 1eb16d1 | 2015-09-06 17:21:56 -0700 | [diff] [blame] | 147 | extern GFLAGS_DLL_DECLARE_FLAG ::fLS::clstring& FLAGS_##name; \ |
| 148 | } \ |
| 149 | using fLS::FLAGS_##name |
| 150 | |
| 151 | |
| 152 | #endif // GFLAGS_DECLARE_H_ |