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