Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2019 The Abseil Authors. |
| 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 | // https://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 | // File: declare.h |
| 18 | // ----------------------------------------------------------------------------- |
| 19 | // |
| 20 | // This file defines the ABSL_DECLARE_FLAG macro, allowing you to declare an |
| 21 | // `absl::Flag` for use within a translation unit. You should place this |
| 22 | // declaration within the header file associated with the .cc file that defines |
| 23 | // and owns the `Flag`. |
| 24 | |
| 25 | #ifndef ABSL_FLAGS_DECLARE_H_ |
| 26 | #define ABSL_FLAGS_DECLARE_H_ |
| 27 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 28 | #include "absl/base/config.h" |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 29 | |
| 30 | namespace absl { |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 31 | ABSL_NAMESPACE_BEGIN |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 32 | namespace flags_internal { |
| 33 | |
| 34 | // absl::Flag<T> represents a flag of type 'T' created by ABSL_FLAG. |
| 35 | template <typename T> |
| 36 | class Flag; |
| 37 | |
| 38 | } // namespace flags_internal |
| 39 | |
| 40 | // Flag |
| 41 | // |
| 42 | // Forward declaration of the `absl::Flag` type for use in defining the macro. |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 43 | #if defined(_MSC_VER) && !defined(__clang__) |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 44 | template <typename T> |
| 45 | class Flag; |
| 46 | #else |
| 47 | template <typename T> |
| 48 | using Flag = flags_internal::Flag<T>; |
| 49 | #endif |
| 50 | |
Austin Schuh | b4691e9 | 2020-12-31 12:37:18 -0800 | [diff] [blame^] | 51 | ABSL_NAMESPACE_END |
Austin Schuh | 36244a1 | 2019-09-21 17:52:38 -0700 | [diff] [blame] | 52 | } // namespace absl |
| 53 | |
| 54 | // ABSL_DECLARE_FLAG() |
| 55 | // |
| 56 | // This macro is a convenience for declaring use of an `absl::Flag` within a |
| 57 | // translation unit. This macro should be used within a header file to |
| 58 | // declare usage of the flag within any .cc file including that header file. |
| 59 | // |
| 60 | // The ABSL_DECLARE_FLAG(type, name) macro expands to: |
| 61 | // |
| 62 | // extern absl::Flag<type> FLAGS_name; |
| 63 | #define ABSL_DECLARE_FLAG(type, name) extern ::absl::Flag<type> FLAGS_##name |
| 64 | |
| 65 | #endif // ABSL_FLAGS_DECLARE_H_ |