throw_on_empty_input.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2015.
  7. // Modifications copyright (c) 2015, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  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. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_THROW_ON_EMPTY_INPUT_HPP
  13. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_THROW_ON_EMPTY_INPUT_HPP
  14. #include <boost/geometry/core/exception.hpp>
  15. #include <boost/geometry/algorithms/is_empty.hpp>
  16. #include <boost/throw_exception.hpp>
  17. // BSG 2012-02-06: we use this currently only for distance.
  18. // For other scalar results area,length,perimeter it is commented on purpose.
  19. // Reason is that for distance there is no other choice. distance of two
  20. // empty geometries (or one empty) should NOT return any value.
  21. // But for area it is no problem to be 0.
  22. // Suppose: area(intersection(a,b)). We (probably) don't want a throw there...
  23. // So decided that at least for Boost 1.49 this is commented for
  24. // scalar results, except distance.
  25. #if defined(BOOST_GEOMETRY_EMPTY_INPUT_NO_THROW)
  26. #include <boost/core/ignore_unused.hpp>
  27. #endif
  28. namespace boost { namespace geometry
  29. {
  30. #ifndef DOXYGEN_NO_DETAIL
  31. namespace detail
  32. {
  33. template <typename Geometry>
  34. inline void throw_on_empty_input(Geometry const& geometry)
  35. {
  36. #if ! defined(BOOST_GEOMETRY_EMPTY_INPUT_NO_THROW)
  37. if (geometry::is_empty(geometry))
  38. {
  39. BOOST_THROW_EXCEPTION(empty_input_exception());
  40. }
  41. #else
  42. boost::ignore_unused(geometry);
  43. #endif
  44. }
  45. } // namespace detail
  46. #endif // DOXYGEN_NO_DETAIL
  47. }} // namespace boost::geometry
  48. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_THROW_ON_EMPTY_INPUT_HPP