time_zone_link.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
  10. #ifndef _LIBCPP___CHRONO_TIME_ZONE_LINK_H
  11. #define _LIBCPP___CHRONO_TIME_ZONE_LINK_H
  12. #include <version>
  13. // Enable the contents of the header only when libc++ was built with experimental features enabled.
  14. #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
  15. # include <__compare/strong_order.h>
  16. # include <__config>
  17. # include <string>
  18. # include <string_view>
  19. # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  20. # pragma GCC system_header
  21. # endif
  22. _LIBCPP_PUSH_MACROS
  23. # include <__undef_macros>
  24. _LIBCPP_BEGIN_NAMESPACE_STD
  25. # if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
  26. !defined(_LIBCPP_HAS_NO_LOCALIZATION)
  27. namespace chrono {
  28. class time_zone_link {
  29. public:
  30. struct __constructor_tag;
  31. _LIBCPP_NODISCARD_EXT
  32. _LIBCPP_HIDE_FROM_ABI explicit time_zone_link(__constructor_tag&&, string_view __name, string_view __target)
  33. : __name_{__name}, __target_{__target} {}
  34. _LIBCPP_HIDE_FROM_ABI time_zone_link(time_zone_link&&) = default;
  35. _LIBCPP_HIDE_FROM_ABI time_zone_link& operator=(time_zone_link&&) = default;
  36. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name_; }
  37. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI string_view target() const noexcept { return __target_; }
  38. private:
  39. string __name_;
  40. // TODO TZDB instead of the name we can store the pointer to a zone. These
  41. // pointers are immutable. This makes it possible to directly return a
  42. // pointer in the time_zone in the 'locate_zone' function.
  43. string __target_;
  44. };
  45. _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline bool
  46. operator==(const time_zone_link& __x, const time_zone_link& __y) noexcept {
  47. return __x.name() == __y.name();
  48. }
  49. _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline strong_ordering
  50. operator<=>(const time_zone_link& __x, const time_zone_link& __y) noexcept {
  51. return __x.name() <=> __y.name();
  52. }
  53. } // namespace chrono
  54. # endif //_LIBCPP_STD_VER >= 20
  55. _LIBCPP_END_NAMESPACE_STD
  56. _LIBCPP_POP_MACROS
  57. #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
  58. #endif // _LIBCPP___CHRONO_TIME_ZONE_LINK_H