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