1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2002-2006 Marcin Kalicinski
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see www.boost.org
9 // ----------------------------------------------------------------------------
10 #ifndef BOOST_PROPERTY_TREE_DETAIL_EXCEPTIONS_IMPLEMENTATION_HPP_INCLUDED
11 #define BOOST_PROPERTY_TREE_DETAIL_EXCEPTIONS_IMPLEMENTATION_HPP_INCLUDED
13 namespace boost
{ namespace property_tree
19 // Default path-to-string converter; this is overridden for default path
21 std::string
path_to_string(const P
&path
)
23 return std::string("<cannot convert path to string>");
26 // Helper for preparing what string in ptree_bad_path exception
28 std::string
prepare_bad_path_what(const std::string
&what
, const P
&path
)
30 using namespace detail
; // To allow correct resolution of path_to_string()
31 return what
+ " (" + path_to_string(path
) + ")";
34 // Default data-to-string converter; this is overridden for default data (string)
36 std::string
data_to_string(const D
&data
)
38 return std::string("<cannot convert data to string>");
41 // Helper for preparing what string in ptree_bad_data exception
43 std::string
prepare_bad_data_what(const std::string
&what
, const D
&data
)
45 using namespace detail
; // To allow correct resolution of data_to_string()
46 return what
+ " (" + data_to_string(data
) + ")";
51 ///////////////////////////////////////////////////////////////////////////
54 inline ptree_error::ptree_error(const std::string
&what
):
55 std::runtime_error(what
)
59 inline ptree_error::~ptree_error() throw()
63 ///////////////////////////////////////////////////////////////////////////
67 ptree_bad_data::ptree_bad_data(const std::string
&what
, const D
&data
):
68 ptree_error(detail::prepare_bad_data_what(what
, data
)),
73 inline ptree_bad_data::~ptree_bad_data() throw()
78 D
ptree_bad_data::data()
80 return boost::any_cast
<D
>(m_data
);
83 ///////////////////////////////////////////////////////////////////////////
87 ptree_bad_path::ptree_bad_path(const std::string
&what
, const P
&path
):
88 ptree_error(detail::prepare_bad_path_what(what
, path
)),
94 inline ptree_bad_path::~ptree_bad_path() throw()
99 P
ptree_bad_path::path()
101 return boost::any_cast
<P
>(m_path
);