xref: /freebsd/contrib/llvm-project/libcxx/include/__chrono/time_zone_link.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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 !defined(_LIBCPP_HAS_NO_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 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&   \
35       !defined(_LIBCPP_HAS_NO_LOCALIZATION)
36 
37 namespace chrono {
38 
39 class time_zone_link {
40 public:
41   [[nodiscard]]
time_zone_link(__private_constructor_tag,string_view __name,string_view __target)42   _LIBCPP_HIDE_FROM_ABI explicit time_zone_link(__private_constructor_tag, string_view __name, string_view __target)
43       : __name_{__name}, __target_{__target} {}
44 
45   _LIBCPP_HIDE_FROM_ABI time_zone_link(time_zone_link&&)            = default;
46   _LIBCPP_HIDE_FROM_ABI time_zone_link& operator=(time_zone_link&&) = default;
47 
name()48   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name_; }
target()49   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view target() const noexcept { return __target_; }
50 
51 private:
52   string __name_;
53   // TODO TZDB instead of the name we can store the pointer to a zone. These
54   // pointers are immutable. This makes it possible to directly return a
55   // pointer in the time_zone in the 'locate_zone' function.
56   string __target_;
57 };
58 
59 [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline bool
60 operator==(const time_zone_link& __x, const time_zone_link& __y) noexcept {
61   return __x.name() == __y.name();
62 }
63 
64 [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline strong_ordering
65 operator<=>(const time_zone_link& __x, const time_zone_link& __y) noexcept {
66   return __x.name() <=> __y.name();
67 }
68 
69 } // namespace chrono
70 
71 #  endif //_LIBCPP_STD_VER >= 20
72 
73 _LIBCPP_END_NAMESPACE_STD
74 
75 _LIBCPP_POP_MACROS
76 
77 #endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
78 
79 #endif // _LIBCPP___CHRONO_TIME_ZONE_LINK_H
80