exception.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Boost.Geometry
  2. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017, 2018.
  4. // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_PROJECTIONS_EXCEPTION_HPP
  10. #define BOOST_GEOMETRY_PROJECTIONS_EXCEPTION_HPP
  11. #include <boost/geometry/core/exception.hpp>
  12. #include <boost/geometry/srs/projections/impl/projects.hpp>
  13. #include <boost/geometry/srs/projections/impl/pj_strerrno.hpp>
  14. #include <boost/throw_exception.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. // TODO: make more for forward/inverse/init/setup
  18. class projection_exception : public geometry::exception
  19. {
  20. public:
  21. explicit projection_exception(int code = 0)
  22. : m_code(code)
  23. , m_msg(projections::detail::pj_strerrno(code))
  24. {}
  25. explicit projection_exception(std::string const& msg)
  26. : m_code(0)
  27. , m_msg(msg)
  28. {}
  29. projection_exception(int code, std::string const& msg)
  30. : m_code(code)
  31. , m_msg(msg)
  32. {}
  33. virtual char const* what() const throw()
  34. {
  35. //return "Boost.Geometry Projection exception";
  36. return m_msg.what();
  37. }
  38. int code() const { return m_code; }
  39. private :
  40. int m_code;
  41. std::runtime_error m_msg;
  42. };
  43. struct projection_not_named_exception
  44. : projection_exception
  45. {
  46. projection_not_named_exception()
  47. : projection_exception(projections::detail::error_proj_not_named)
  48. {}
  49. };
  50. struct projection_unknown_id_exception
  51. : projection_exception
  52. {
  53. projection_unknown_id_exception(std::string const& proj_name)
  54. : projection_exception(projections::detail::error_unknown_projection_id,
  55. msg(proj_name))
  56. {}
  57. private:
  58. static std::string msg(std::string const& proj_name)
  59. {
  60. using namespace projections::detail;
  61. return pj_strerrno(error_unknown_projection_id) + " (" + proj_name + ")";
  62. }
  63. };
  64. struct projection_not_invertible_exception
  65. : projection_exception
  66. {
  67. // NOTE: There is no error code in proj4 which could be used here
  68. // Proj4 sets points as invalid (HUGE_VAL) and last errno to EINVAL
  69. // in pj_inv() if inverse projection is not available.
  70. projection_not_invertible_exception(std::string const& proj_name)
  71. : projection_exception(projections::detail::error_non_conv_inv_meri_dist,
  72. msg(proj_name))
  73. {}
  74. private:
  75. static std::string msg(std::string const& proj_name)
  76. {
  77. return std::string("projection (") + proj_name + ") is not invertible";
  78. }
  79. };
  80. }} // namespace boost::geometry
  81. #endif // BOOST_GEOMETRY_PROJECTIONS_EXCEPTION_HPP