fix doc example typo
[boost.git] / boost / property_tree / detail / exceptions_implementation.hpp
blob402051c70f64e4294d5af2cf5f85bff11fa2c31a
1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2002-2006 Marcin Kalicinski
3 //
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)
7 //
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
16 namespace detail
19 // Default path-to-string converter; this is overridden for default path
20 template<class P>
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
27 template<class P>
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)
35 template<class D>
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
42 template<class D>
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 ///////////////////////////////////////////////////////////////////////////
52 // ptree_error
54 inline ptree_error::ptree_error(const std::string &what):
55 std::runtime_error(what)
59 inline ptree_error::~ptree_error() throw()
63 ///////////////////////////////////////////////////////////////////////////
64 // ptree_bad_data
66 template<class D>
67 ptree_bad_data::ptree_bad_data(const std::string &what, const D &data):
68 ptree_error(detail::prepare_bad_data_what(what, data)),
69 m_data(data)
73 inline ptree_bad_data::~ptree_bad_data() throw()
77 template<class D>
78 D ptree_bad_data::data()
80 return boost::any_cast<D>(m_data);
83 ///////////////////////////////////////////////////////////////////////////
84 // ptree_bad_path
86 template<class P>
87 ptree_bad_path::ptree_bad_path(const std::string &what, const P &path):
88 ptree_error(detail::prepare_bad_path_what(what, path)),
89 m_path(path)
94 inline ptree_bad_path::~ptree_bad_path() throw()
98 template<class P>
99 P ptree_bad_path::path()
101 return boost::any_cast<P>(m_path);
106 #endif