You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

declare.h 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef ABSL_FLAGS_DECLARE_H_
  25. #define ABSL_FLAGS_DECLARE_H_
  26. #include "absl/base/config.h"
  27. namespace absl
  28. {
  29. ABSL_NAMESPACE_BEGIN
  30. namespace flags_internal
  31. {
  32. // absl::Flag<T> represents a flag of type 'T' created by ABSL_FLAG.
  33. template<typename T>
  34. class Flag;
  35. } // namespace flags_internal
  36. // Flag
  37. //
  38. // Forward declaration of the `absl::Flag` type for use in defining the macro.
  39. #if defined(_MSC_VER) && !defined(__clang__)
  40. template<typename T>
  41. class Flag;
  42. #else
  43. template<typename T>
  44. using Flag = flags_internal::Flag<T>;
  45. #endif
  46. ABSL_NAMESPACE_END
  47. } // namespace absl
  48. // ABSL_DECLARE_FLAG()
  49. //
  50. // This macro is a convenience for declaring use of an `absl::Flag` within a
  51. // translation unit. This macro should be used within a header file to
  52. // declare usage of the flag within any .cc file including that header file.
  53. //
  54. // The ABSL_DECLARE_FLAG(type, name) macro expands to:
  55. //
  56. // extern absl::Flag<type> FLAGS_name;
  57. #define ABSL_DECLARE_FLAG(type, name) ABSL_DECLARE_FLAG_INTERNAL(type, name)
  58. // Internal implementation of ABSL_DECLARE_FLAG to allow macro expansion of its
  59. // arguments. Clients must use ABSL_DECLARE_FLAG instead.
  60. #define ABSL_DECLARE_FLAG_INTERNAL(type, name) \
  61. extern absl::Flag<type> FLAGS_##name; \
  62. namespace absl /* block flags in namespaces */ \
  63. { \
  64. } \
  65. /* second redeclaration is to allow applying attributes */ \
  66. extern absl::Flag<type> FLAGS_##name
  67. #endif // ABSL_FLAGS_DECLARE_H_