exception_implementation.hpp 2.1 KB

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