xref: /llvm-project/libcxx/include/__chrono/time_zone_link.h (revision 24e70e3930724ce499ad05d669bfbc4423c542e0)
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 
10 // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
11 
12 #ifndef _LIBCPP___CHRONO_TIME_ZONE_LINK_H
13 #define _LIBCPP___CHRONO_TIME_ZONE_LINK_H
14 
15 #include <version>
16 // Enable the contents of the header only when libc++ was built with experimental features enabled.
17 #if _LIBCPP_HAS_EXPERIMENTAL_TZDB
18 
19 #  include <__compare/strong_order.h>
20 #  include <__config>
21 #  include <__utility/private_constructor_tag.h>
22 #  include <string>
23 #  include <string_view>
24 
25 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26 #    pragma GCC system_header
27 #  endif
28 
29 _LIBCPP_PUSH_MACROS
30 #  include <__undef_macros>
31 
32 _LIBCPP_BEGIN_NAMESPACE_STD
33 
34 #  if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
35 
36 namespace chrono {
37 
38 class time_zone_link {
39 public:
40   [[nodiscard]]
41   _LIBCPP_HIDE_FROM_ABI explicit time_zone_link(__private_constructor_tag, string_view __name, string_view __target)
42       : __name_{__name}, __target_{__target} {}
43 
44   _LIBCPP_HIDE_FROM_ABI time_zone_link(time_zone_link&&)            = default;
45   _LIBCPP_HIDE_FROM_ABI time_zone_link& operator=(time_zone_link&&) = default;
46 
47   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name_; }
48   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view target() const noexcept { return __target_; }
49 
50 private:
51   string __name_;
52   // TODO TZDB instead of the name we can store the pointer to a zone. These
53   // pointers are immutable. This makes it possible to directly return a
54   // pointer in the time_zone in the 'locate_zone' function.
55   string __target_;
56 };
57 
58 [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline bool
59 operator==(const time_zone_link& __x, const time_zone_link& __y) noexcept {
60   return __x.name() == __y.name();
61 }
62 
63 [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline strong_ordering
64 operator<=>(const time_zone_link& __x, const time_zone_link& __y) noexcept {
65   return __x.name() <=> __y.name();
66 }
67 
68 } // namespace chrono
69 
70 #  endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
71          // _LIBCPP_HAS_LOCALIZATION
72 
73 _LIBCPP_END_NAMESPACE_STD
74 
75 _LIBCPP_POP_MACROS
76 
77 #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
78 
79 #endif // _LIBCPP___CHRONO_TIME_ZONE_LINK_H
80