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_TZDB_LIST_H
13#define _LIBCPP___CHRONO_TZDB_LIST_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 <__chrono/time_zone.h>
20# include <__chrono/tzdb.h>
21# include <__config>
22# include <__fwd/string.h>
23# include <forward_list>
24# include <string_view>
25
26# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27# pragma GCC system_header
28# endif
29
30# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
34
35namespace chrono {
36
37// TODO TZDB
38// Libc++ recently switched to only export __ugly_names from the dylib.
39// Since the library is still experimental the functions in this header
40// should be adapted to this new style. The other tzdb headers should be
41// evaluated too.
42
43class _LIBCPP_AVAILABILITY_TZDB tzdb_list {
44public:
45 class __impl; // public to allow construction in dylib
46 _LIBCPP_HIDE_FROM_ABI explicit tzdb_list(__impl* __p) : __impl_(__p) {
47 _LIBCPP_ASSERT_NON_NULL(__impl_ != nullptr, "initialized time_zone without a valid pimpl object");
48 }
49 _LIBCPP_EXPORTED_FROM_ABI ~tzdb_list();
50
51 tzdb_list(const tzdb_list&) = delete;
52 tzdb_list& operator=(const tzdb_list&) = delete;
53
54 using const_iterator = forward_list<tzdb>::const_iterator;
55
56 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const tzdb& front() const noexcept { return __front(); }
57
58 _LIBCPP_HIDE_FROM_ABI const_iterator erase_after(const_iterator __p) { return __erase_after(__p); }
59
60 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { return __begin(); }
61 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { return __end(); }
62
63 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return __cbegin(); }
64 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return __cend(); }
65
66 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI __impl& __implementation() { return *__impl_; }
67
68private:
69 [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const tzdb& __front() const noexcept;
70
71 _LIBCPP_EXPORTED_FROM_ABI const_iterator __erase_after(const_iterator __p);
72
73 [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __begin() const noexcept;
74 [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __end() const noexcept;
75
76 [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cbegin() const noexcept;
77 [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cend() const noexcept;
78
79 __impl* __impl_;
80};
81
82[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI tzdb_list& get_tzdb_list();
83
84[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline const tzdb& get_tzdb() {
85 return get_tzdb_list().front();
86}
87
88[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline const time_zone* locate_zone(string_view __name) {
89 return get_tzdb().locate_zone(__name);
90}
91
92[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline const time_zone* current_zone() {
93 return get_tzdb().current_zone();
94}
95
96_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb();
97
98[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI string remote_version();
99
100} // namespace chrono
101
102_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
103_LIBCPP_END_NAMESPACE_STD
104
105# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
106 // _LIBCPP_HAS_LOCALIZATION
107
108#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
109
110#endif // _LIBCPP___CHRONO_TZDB_LIST_H
111