xref: /freebsd/contrib/llvm-project/libcxx/include/__chrono/file_clock.h (revision 1db9f3b21e39176dd5b67cf8ac378633b172463e)
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 #ifndef _LIBCPP___CHRONO_FILE_CLOCK_H
11 #define _LIBCPP___CHRONO_FILE_CLOCK_H
12 
13 #include <__availability>
14 #include <__chrono/duration.h>
15 #include <__chrono/system_clock.h>
16 #include <__chrono/time_point.h>
17 #include <__config>
18 #include <ratio>
19 
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 #  pragma GCC system_header
22 #endif
23 
24 #ifndef _LIBCPP_CXX03_LANG
25 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
26 struct _FilesystemClock;
27 _LIBCPP_END_NAMESPACE_FILESYSTEM
28 #endif // !_LIBCPP_CXX03_LANG
29 
30 #if _LIBCPP_STD_VER >= 20
31 
32 _LIBCPP_BEGIN_NAMESPACE_STD
33 
34 namespace chrono {
35 
36 // [time.clock.file], type file_clock
37 using file_clock = filesystem::_FilesystemClock;
38 
39 template <class _Duration>
40 using file_time = time_point<file_clock, _Duration>;
41 
42 } // namespace chrono
43 
44 _LIBCPP_END_NAMESPACE_STD
45 
46 #endif // _LIBCPP_STD_VER >= 20
47 
48 #ifndef _LIBCPP_CXX03_LANG
49 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
50 struct _FilesystemClock {
51 #  if !defined(_LIBCPP_HAS_NO_INT128)
52   typedef __int128_t rep;
53   typedef nano period;
54 #  else
55   typedef long long rep;
56   typedef nano period;
57 #  endif
58 
59   typedef chrono::duration<rep, period> duration;
60   typedef chrono::time_point<_FilesystemClock> time_point;
61 
62   _LIBCPP_EXPORTED_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false;
63 
64   _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_EXPORTED_FROM_ABI static time_point now() noexcept;
65 
66 #  if _LIBCPP_STD_VER >= 20
67   template <class _Duration>
68   _LIBCPP_HIDE_FROM_ABI static chrono::sys_time<_Duration> to_sys(const chrono::file_time<_Duration>& __t) {
69     return chrono::sys_time<_Duration>(__t.time_since_epoch());
70   }
71 
72   template <class _Duration>
73   _LIBCPP_HIDE_FROM_ABI static chrono::file_time<_Duration> from_sys(const chrono::sys_time<_Duration>& __t) {
74     return chrono::file_time<_Duration>(__t.time_since_epoch());
75   }
76 #  endif // _LIBCPP_STD_VER >= 20
77 };
78 _LIBCPP_END_NAMESPACE_FILESYSTEM
79 #endif // !_LIBCPP_CXX03_LANG
80 
81 #endif // _LIBCPP___CHRONO_FILE_CLOCK_H
82