file_clock.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. {
  29. // [time.clock.file], type file_clock
  30. using file_clock = _VSTD_FS::_FilesystemClock;
  31. template<class _Duration>
  32. using file_time = time_point<file_clock, _Duration>;
  33. } // namespace chrono
  34. _LIBCPP_END_NAMESPACE_STD
  35. #endif // _LIBCPP_STD_VER >= 20
  36. #ifndef _LIBCPP_CXX03_LANG
  37. _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
  38. struct _FilesystemClock {
  39. #if !defined(_LIBCPP_HAS_NO_INT128)
  40. typedef __int128_t rep;
  41. typedef nano period;
  42. #else
  43. typedef long long rep;
  44. typedef nano period;
  45. #endif
  46. typedef chrono::duration<rep, period> duration;
  47. typedef chrono::time_point<_FilesystemClock> time_point;
  48. _LIBCPP_EXPORTED_FROM_ABI
  49. static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false;
  50. _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_EXPORTED_FROM_ABI static time_point now() noexcept;
  51. #if _LIBCPP_STD_VER >= 20
  52. template <class _Duration>
  53. _LIBCPP_HIDE_FROM_ABI
  54. static chrono::sys_time<_Duration> to_sys(const chrono::file_time<_Duration>& __t) {
  55. return chrono::sys_time<_Duration>(__t.time_since_epoch());
  56. }
  57. template <class _Duration>
  58. _LIBCPP_HIDE_FROM_ABI
  59. static chrono::file_time<_Duration> from_sys(const chrono::sys_time<_Duration>& __t) {
  60. return chrono::file_time<_Duration>(__t.time_since_epoch());
  61. }
  62. #endif // _LIBCPP_STD_VER >= 20
  63. };
  64. _LIBCPP_END_NAMESPACE_FILESYSTEM
  65. #endif // !_LIBCPP_CXX03_LANG
  66. #endif // _LIBCPP___CHRONO_FILE_CLOCK_H