1 | // boost/filesystem/exception.hpp -----------------------------------------------------// |
2 | |
3 | // Copyright Beman Dawes 2003 |
4 | // Copyright Andrey Semashev 2019 |
5 | |
6 | // Distributed under the Boost Software License, Version 1.0. |
7 | // See http://www.boost.org/LICENSE_1_0.txt |
8 | |
9 | // Library home page: http://www.boost.org/libs/filesystem |
10 | |
11 | #ifndef BOOST_FILESYSTEM_EXCEPTION_HPP |
12 | #define BOOST_FILESYSTEM_EXCEPTION_HPP |
13 | |
14 | #include <boost/filesystem/config.hpp> |
15 | #include <boost/filesystem/path.hpp> |
16 | |
17 | #include <string> |
18 | #include <boost/system/error_code.hpp> |
19 | #include <boost/system/system_error.hpp> |
20 | #include <boost/smart_ptr/intrusive_ptr.hpp> |
21 | #include <boost/smart_ptr/intrusive_ref_counter.hpp> |
22 | |
23 | #include <boost/filesystem/detail/header.hpp> // must be the last #include |
24 | |
25 | namespace boost { |
26 | namespace filesystem { |
27 | |
28 | //--------------------------------------------------------------------------------------// |
29 | // // |
30 | // class filesystem_error // |
31 | // // |
32 | //--------------------------------------------------------------------------------------// |
33 | |
34 | class BOOST_SYMBOL_VISIBLE filesystem_error : |
35 | public system::system_error |
36 | { |
37 | // see http://www.boost.org/more/error_handling.html for design rationale |
38 | |
39 | public: |
40 | BOOST_FILESYSTEM_DECL filesystem_error(const char* what_arg, system::error_code ec); |
41 | BOOST_FILESYSTEM_DECL filesystem_error(std::string const& what_arg, system::error_code ec); |
42 | BOOST_FILESYSTEM_DECL filesystem_error(const char* what_arg, path const& path1_arg, system::error_code ec); |
43 | BOOST_FILESYSTEM_DECL filesystem_error(std::string const& what_arg, path const& path1_arg, system::error_code ec); |
44 | BOOST_FILESYSTEM_DECL filesystem_error(const char* what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec); |
45 | BOOST_FILESYSTEM_DECL filesystem_error(std::string const& what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec); |
46 | |
47 | BOOST_FILESYSTEM_DECL filesystem_error(filesystem_error const& that); |
48 | BOOST_FILESYSTEM_DECL filesystem_error& operator=(filesystem_error const& that); |
49 | |
50 | BOOST_FILESYSTEM_DECL ~filesystem_error() noexcept; |
51 | |
52 | path const& path1() const noexcept |
53 | { |
54 | return m_imp_ptr.get() ? m_imp_ptr->m_path1 : get_empty_path(); |
55 | } |
56 | path const& path2() const noexcept |
57 | { |
58 | return m_imp_ptr.get() ? m_imp_ptr->m_path2 : get_empty_path(); |
59 | } |
60 | |
61 | BOOST_FILESYSTEM_DECL const char* what() const noexcept override; |
62 | |
63 | private: |
64 | BOOST_FILESYSTEM_DECL static path const& get_empty_path() noexcept; |
65 | |
66 | private: |
67 | struct impl : |
68 | public boost::intrusive_ref_counter< impl > |
69 | { |
70 | path m_path1; // may be empty() |
71 | path m_path2; // may be empty() |
72 | std::string m_what; // not built until needed |
73 | |
74 | impl() = default; |
75 | explicit impl(path const& path1) : |
76 | m_path1(path1) |
77 | { |
78 | } |
79 | impl(path const& path1, path const& path2) : |
80 | m_path1(path1), m_path2(path2) |
81 | { |
82 | } |
83 | }; |
84 | boost::intrusive_ptr< impl > m_imp_ptr; |
85 | }; |
86 | |
87 | } // namespace filesystem |
88 | } // namespace boost |
89 | |
90 | #include <boost/filesystem/detail/footer.hpp> |
91 | |
92 | #endif // BOOST_FILESYSTEM_EXCEPTION_HPP |
93 | |