filesystem_error.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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___FILESYSTEM_FILESYSTEM_ERROR_H
  10. #define _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H
  11. #include <__availability>
  12. #include <__config>
  13. #include <__filesystem/path.h>
  14. #include <__memory/shared_ptr.h>
  15. #include <__system_error/error_code.h>
  16. #include <__system_error/system_error.h>
  17. #include <__utility/forward.h>
  18. #include <__verbose_abort>
  19. #include <iosfwd>
  20. #include <new>
  21. #include <string>
  22. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  23. # pragma GCC system_header
  24. #endif
  25. #ifndef _LIBCPP_CXX03_LANG
  26. _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
  27. class _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_EXPORTED_FROM_ABI filesystem_error : public system_error {
  28. public:
  29. _LIBCPP_HIDE_FROM_ABI filesystem_error(const string& __what, error_code __ec)
  30. : system_error(__ec, __what), __storage_(make_shared<_Storage>(path(), path())) {
  31. __create_what(0);
  32. }
  33. _LIBCPP_HIDE_FROM_ABI filesystem_error(const string& __what, const path& __p1, error_code __ec)
  34. : system_error(__ec, __what), __storage_(make_shared<_Storage>(__p1, path())) {
  35. __create_what(1);
  36. }
  37. _LIBCPP_HIDE_FROM_ABI filesystem_error(const string& __what, const path& __p1, const path& __p2, error_code __ec)
  38. : system_error(__ec, __what), __storage_(make_shared<_Storage>(__p1, __p2)) {
  39. __create_what(2);
  40. }
  41. _LIBCPP_HIDE_FROM_ABI const path& path1() const noexcept { return __storage_->__p1_; }
  42. _LIBCPP_HIDE_FROM_ABI const path& path2() const noexcept { return __storage_->__p2_; }
  43. _LIBCPP_HIDE_FROM_ABI filesystem_error(const filesystem_error&) = default;
  44. ~filesystem_error() override; // key function
  45. _LIBCPP_HIDE_FROM_ABI_VIRTUAL
  46. const char* what() const noexcept override { return __storage_->__what_.c_str(); }
  47. void __create_what(int __num_paths);
  48. private:
  49. struct _LIBCPP_HIDDEN _Storage {
  50. _LIBCPP_HIDE_FROM_ABI _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {}
  51. path __p1_;
  52. path __p2_;
  53. string __what_;
  54. };
  55. shared_ptr<_Storage> __storage_;
  56. };
  57. # ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  58. template <class... _Args>
  59. _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
  60. __throw_filesystem_error(_Args&&... __args) {
  61. throw filesystem_error(_VSTD::forward<_Args>(__args)...);
  62. }
  63. # else
  64. template <class... _Args>
  65. _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
  66. __throw_filesystem_error(_Args&&...) {
  67. _LIBCPP_VERBOSE_ABORT("filesystem_error was thrown in -fno-exceptions mode");
  68. }
  69. # endif
  70. _LIBCPP_END_NAMESPACE_FILESYSTEM
  71. #endif // _LIBCPP_CXX03_LANG
  72. #endif // _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H