declare.h 2.5 KB

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