Developer Documentation
Loading...
Searching...
No Matches
SmartPointer.hh
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42#ifndef ACG_UTILS_SMARTPOINTER_HH
43#define ACG_UTILS_SMARTPOINTER_HH
44
45/*************************************************
46 * Warning! This header file is duplicated in *
47 * OpenVolumeMesh with the same header guard, *
48 * as src/OpenVolumeMesh/System/MemoryInclude.hh.*
49 * If you change this file, you should change *
50 * that file as well. *
51 *************************************************/
52
53#include <memory>
54
55// Default for C++ 11 and higher
56#if ((defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__))
57
58 // legacy code may depend on this define:
59 #define ACG_UNIQUE_POINTER_SUPPORTED 1
60
61 namespace ptr {
62 using std::shared_ptr;
63 using std::make_shared;
64 using std::unique_ptr;
65
66 #if __cplusplus >= 201402L
67 using std::make_unique;
68 #else
69 template<typename T, typename... Args>
70 std::unique_ptr<T>
71 make_unique(Args&&... args) {
72 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
73 }
74 #endif // C++14
75
76 } // namespace ptr
77
78
79#else // deprecated things
80
84 #if ( (__cplusplus >= 201103L) || (__STDC_VERSION__ >= 201112L) )
85 // C++11:
86 #include <memory>
87 namespace ptr = std;
88 #define ACG_UNIQUE_POINTER_SUPPORTED 1
89 #elif defined(__GXX_EXPERIMENTAL_CXX0X__)
90 // C++11 via -std=c++0x on gcc:
91 #include <memory>
92 namespace ptr = std;
93 #define ACG_UNIQUE_POINTER_SUPPORTED 1
94 #else
95 // C++98 and TR1:
96 #if (_MSC_VER >= 1600)
97 // VStudio 2010 supports some C++11 features
98 #include <memory>
99 namespace ptr = std;
100 #define ACG_UNIQUE_POINTER_SUPPORTED 1
101 #elif (_MSC_VER >= 1500)
102 // hope for TR1 equivalents
103 #if(_HAS_TR1)
104 #include <memory>
105 namespace ptr = std::tr1;
106 #define ACG_UNIQUE_POINTER_SUPPORTED 0
107 #else
108 #pragma warning "TR1 not available! Please install Visual Studio Service Pack 1!"
109 #endif
110 #else
111 // hope for TR1 equivalents
112 // check for clang5 but switch to tr1 if clang uses libstdc++
113 #if defined(__clang_major__) && (__clang_major__ >= 5) && !defined(__GLIBCXX__ )
114 // Mavericks special treatment
115 #include <memory>
116 namespace ptr = std;
117 #else
118 #include <tr1/memory>
119 namespace ptr = std::tr1;
120 #endif
121 #define ACG_UNIQUE_POINTER_SUPPORTED 0
122 #endif
123 #endif
124#endif
125
126
127
128
129#endif // ACG_UTILS_SMARTPOINTER_HH
130