GEOS  3.13.0dev
util.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2001-2002 Vivid Solutions Inc.
7  * Copyright (C) 2006 Refractions Research Inc.
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU Lesser General Public Licence as published
11  * by the Free Software Foundation.
12  * See the COPYING file for more information.
13  *
14  **********************************************************************
15  *
16  * Utility header to retain a bit of backward compatibility.
17  * Try to avoid including this header directly.
18  *
19  **********************************************************************/
20 
21 #ifndef GEOS_UTIL_H
22 #define GEOS_UTIL_H
23 
24 #include <cassert>
25 #include <memory>
26 #include <type_traits>
27 #include <geos/util/UnsupportedOperationException.h>
28 
29 //
30 // Private macros definition
31 //
32 
33 namespace geos {
34 template<class T>
35 void
36 ignore_unused_variable_warning(T const &) {}
37 
38 namespace detail {
39 using std::make_unique;
40 
50 template<typename To, typename From> inline To down_cast(From* f)
51 {
52  static_assert(
53  (std::is_base_of<From,
54  typename std::remove_pointer<To>::type>::value),
55  "target type not derived from source type");
56 #if GEOS_DEBUG
57  assert(f == nullptr || dynamic_cast<To>(f) != nullptr);
58 #endif
59  return static_cast<To>(f);
60 }
61 
62 } // namespace detail
63 
64 namespace util {
65 
66 template<typename T>
67 void ensureNoCurvedComponents(const T& geom)
68 {
69  if (geom.hasCurvedComponents()) {
70  throw UnsupportedOperationException("Curved geometry types are not supported.");
71  }
72 }
73 
74 template<typename T>
75 void ensureNoCurvedComponents(const T* geom)
76 {
77  ensureNoCurvedComponents(*geom);
78 }
79 
80 
81 }
82 
83 
84 } // namespace geos
85 
86 #endif // GEOS_UTIL_H
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25