GEOS 3.9.1
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 <geos/util/AssertionFailedException.h>
25#include <geos/util/GEOSException.h>
26#include <geos/util/IllegalArgumentException.h>
27#include <geos/util/TopologyException.h>
28//#include <geos/util/UnsupportedOperationException.h>
29//#include <geos/util/CoordinateArrayFilter.h>
30//#include <geos/util/UniqueCoordinateArrayFilter.h>
31#include <geos/util/GeometricShapeFactory.h>
32//#include <geos/util/math.h>
33
34#include <memory>
35#include <type_traits>
36
37//
38// Private macros definition
39//
40
41namespace geos {
42template<class T>
43void
44ignore_unused_variable_warning(T const &) {}
45
46namespace detail {
47#if __cplusplus >= 201402L
48using std::make_unique;
49#else
50// Backport of std::make_unique to C++11
51// Source: https://stackoverflow.com/a/19472607
52template<class T>
53struct _Unique_if {
54 typedef std::unique_ptr<T> _Single_object;
55};
56
57template<class T>
58struct _Unique_if<T[]> {
59 typedef std::unique_ptr<T[]> _Unknown_bound;
60};
61
62template<class T, size_t N>
63struct _Unique_if<T[N]> {
64 typedef void _Known_bound;
65};
66
67template<class T, class... Args>
68typename _Unique_if<T>::_Single_object
69make_unique(Args &&... args) {
70 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
71}
72
73template<class T>
74typename _Unique_if<T>::_Unknown_bound
75make_unique(size_t n) {
76 typedef typename std::remove_extent<T>::type U;
77 return std::unique_ptr<T>(new U[n]());
78}
79
80template<class T, class... Args>
81typename _Unique_if<T>::_Known_bound
82make_unique(Args &&...) = delete;
83
84#endif
85
95template<typename To, typename From> inline To down_cast(From* f)
96{
97 static_assert(
98 (std::is_base_of<From,
99 typename std::remove_pointer<To>::type>::value),
100 "target type not derived from source type");
101#if GEOS_DEBUG
102 assert(f == nullptr || dynamic_cast<To>(f) != nullptr);
103#endif
104 return static_cast<To>(f);
105}
106
107} // namespace detail
108} // namespace geos
109
110#endif // GEOS_UTIL_H
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26