| 1 | // ---------------------------------------------------------------------------- |
| 2 | // Copyright (C) 2002-2006 Marcin Kalicinski |
| 3 | // Copyright (C) 2009 Sebastian Redl |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // For more information, see www.boost.org |
| 10 | // ---------------------------------------------------------------------------- |
| 11 | #ifndef BOOST_PROPERTY_TREE_DETAIL_EXCEPTIONS_IMPLEMENTATION_HPP_INCLUDED |
| 12 | #define BOOST_PROPERTY_TREE_DETAIL_EXCEPTIONS_IMPLEMENTATION_HPP_INCLUDED |
| 13 | |
| 14 | #include <boost/property_tree/exceptions.hpp> |
| 15 | |
| 16 | #include <string> |
| 17 | |
| 18 | namespace boost { namespace property_tree |
| 19 | { |
| 20 | |
| 21 | namespace detail |
| 22 | { |
| 23 | |
| 24 | // Helper for preparing what string in ptree_bad_path exception |
| 25 | template<class P> inline |
| 26 | std::string prepare_bad_path_what(const std::string &what, |
| 27 | const P &path) |
| 28 | { |
| 29 | return what + " (" + path.dump() + ")" ; |
| 30 | } |
| 31 | |
| 32 | } |
| 33 | |
| 34 | /////////////////////////////////////////////////////////////////////////// |
| 35 | // ptree_error |
| 36 | |
| 37 | inline ptree_error::ptree_error(const std::string &w): |
| 38 | std::runtime_error(w) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | /////////////////////////////////////////////////////////////////////////// |
| 43 | // ptree_bad_data |
| 44 | |
| 45 | template<class D> inline |
| 46 | ptree_bad_data::ptree_bad_data(const std::string &w, const D &d): |
| 47 | ptree_error(w), m_data(d) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | template<class D> inline |
| 52 | D ptree_bad_data::data() const |
| 53 | { |
| 54 | return boost::any_cast<D>(m_data); |
| 55 | } |
| 56 | |
| 57 | /////////////////////////////////////////////////////////////////////////// |
| 58 | // ptree_bad_path |
| 59 | |
| 60 | template<class P> inline |
| 61 | ptree_bad_path::ptree_bad_path(const std::string &w, const P &p): |
| 62 | ptree_error(detail::prepare_bad_path_what(w, p)), m_path(p) |
| 63 | { |
| 64 | |
| 65 | } |
| 66 | |
| 67 | template<class P> inline |
| 68 | P ptree_bad_path::path() const |
| 69 | { |
| 70 | return boost::any_cast<P>(m_path); |
| 71 | } |
| 72 | |
| 73 | }} |
| 74 | |
| 75 | #endif |
| 76 | |