GEOS 3.14.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
33namespace geos {
34template<class T>
35void
36ignore_unused_variable_warning(T const &) {}
37
38namespace detail {
39using std::make_unique;
40
50template<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
64namespace util {
65
66template<typename T>
67void ensureNoCurvedComponents(const T& geom)
68{
69 if (geom.hasCurvedComponents()) {
70 throw UnsupportedOperationException("Curved geometry types are not supported.");
71 }
72}
73
74template<typename T>
75void 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 geos.h:39