exception_implementation.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include <boost/property_tree/exceptions.hpp>
  14. #include <string>
  15. namespace boost { namespace property_tree
  16. {
  17. namespace detail
  18. {
  19. // Helper for preparing what string in ptree_bad_path exception
  20. template<class P> inline
  21. std::string prepare_bad_path_what(const std::string &what,
  22. const P &path)
  23. {
  24. return what + " (" + path.dump() + ")";
  25. }
  26. }
  27. ///////////////////////////////////////////////////////////////////////////
  28. // ptree_error
  29. inline ptree_error::ptree_error(const std::string &w):
  30. std::runtime_error(w)
  31. {
  32. }
  33. ///////////////////////////////////////////////////////////////////////////
  34. // ptree_bad_data
  35. template<class D> inline
  36. ptree_bad_data::ptree_bad_data(const std::string &w, const D &d):
  37. ptree_error(w), m_data(d)
  38. {
  39. }
  40. template<class D> inline
  41. D ptree_bad_data::data() const
  42. {
  43. return boost::any_cast<D>(m_data);
  44. }
  45. ///////////////////////////////////////////////////////////////////////////
  46. // ptree_bad_path
  47. template<class P> inline
  48. ptree_bad_path::ptree_bad_path(const std::string &w, const P &p):
  49. ptree_error(detail::prepare_bad_path_what(w, p)), m_path(p)
  50. {
  51. }
  52. template<class P> inline
  53. P ptree_bad_path::path() const
  54. {
  55. return boost::any_cast<P>(m_path);
  56. }
  57. }}
  58. #endif