file_clock.h 2.3 KB

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