Numerical C++ Library Concepts
TWiki Guest (guest)
Logout
Numerical C++ Library Concepts
IT Services
ISG Blog
IntraMATH
Contact
Login
Keyword or person
News
About us
People
People
Publications
Gallery
Applications
Installation
How to get started
Tutorials
Class documentation
ETH Zurich
D-MATH
wiki@math
Concepts
sharedPointer.hh
Go to the documentation of this file.
1
4
#pragma once
5
6
// The contens of original sharedPointer.hh is in sharedPointer_boost.hh
7
// Due to C++11 standard there is no need to use boost::shared_ptr.
8
// We take std::shared_ptr, if the compiler supports C++11.
9
10
#if __cplusplus>=201103L
11
#include "
sharedPointer_std.hh
"
12
13
#else
14
#include "
sharedPointer_boost.hh
"
15
16
#endif
17
18
19
20
// namespace concepts {
21
22
// // ********************************************************** null_deleter **
23
24
// struct null_deleter
25
// {
26
// void operator()(void const *) const
27
// {
28
// }
29
// };
30
31
// // ******************************************************************* RCP **
32
33
// /** Reference-counting pointer
34
35
// @author Kersten Schmidt, 2010
36
// Holger Brandsmeier, 2010
37
// */
38
// template<class T>
39
// class RCP : public std::shared_ptr<T>
40
// {
41
// public:
42
// /// Default constructor
43
// RCP() : std::shared_ptr<T>() {}
44
45
// /** Constructor for a simple pointer, which will be deleted by the RCP
46
47
// It should be only called with pointer to dynamic variables, e.g.
48
// <pre>RCP p(new int(4));</pre>
49
50
// Do NOT use it with pointers to variables in the stack. Do not
51
// <pre>int i = 4; RCP p(&i); // <-- DO NOT -- </pre>
52
53
// Use instead the function \c makeRCP_weak for weak RCPs, where
54
// the pointer is not deleted.
55
// <pre>int i = 4; RCP p = makeRCP_weak(&i);</pre>
56
// */
57
// explicit RCP(T* x) : std::shared_ptr<T>(x) {}
58
59
// RCP(std::shared_ptr<T>& x) : std::shared_ptr<T>(x) {}
60
61
// template<class F>
62
// RCP(const std::shared_ptr<F>& x) : std::shared_ptr<T>(x) {}
63
64
// /// Constructor which includes the deleter G
65
// template<class F, class G>
66
// RCP(F x, G y) : std::shared_ptr<T>(x, y) {}
67
68
// RCP<T>& operator=(const RCP<T> x)
69
// {
70
// RCP<T>(x).swap(*this);
71
// return *this;
72
// }
73
74
// template<class F>
75
// RCP<T>& operator=(const std::shared_ptr<F> x)
76
// {
77
// RCP<T>(x).swap(*this);
78
// return *this;
79
// }
80
81
// // this conversion operator is already implemented for shared_ptr
82
// #if 0
83
// // template function for implicit conversion ops.
84
// template<class NewType>
85
// operator RCP<NewType>()
86
// {
87
// return RCP<NewType>( std::shared_ptr<NewType>(*this) );
88
// }
89
// #endif
90
// };
91
92
// // *************************************************************** makeRCP **
93
94
// /** Function to create a RCP which deletes the object when no RCP
95
// points on it anymore.
96
97
// The function has to be used, if the object is created with new.
98
99
// For example:
100
// <pre>
101
// RCP<int>::Type iP = makeRCP(new int(2));
102
// iP.reset(); // deletes the integer 2
103
// </pre>
104
105
// Second example:
106
// <pre>
107
// RCP<int>::Type iP = makeRCP(new int(3)), jP = iP;
108
// jP.reset(); // does not delete the integer 3, as jP points still on it
109
// iP.reset(); // deletes the integer 3, no RCP points on it
110
// </pre>
111
// */
112
// template <class T>
113
// RCP<T> makeRCP(T* x)
114
// {
115
// return RCP<T>(x);
116
// }
117
118
// // ********************************************************** makeRCP_weak **
119
120
// /** Function to create a RCP without deleting the object in the destructor
121
122
// The function has to be used, if the object remains externally,
123
// e.g., in the heap.
124
125
// For example:
126
// <pre>
127
// int i = 1;
128
// RCP<int>::Type iP = makeRCP_weak(&i);
129
// iP.reset(); // will not delete the integer 1
130
// </pre>
131
// */
132
// template<class T>
133
// RCP<T> makeRCP_weak(T* x)
134
// {
135
// return RCP<T>(x, null_deleter());
136
// }
137
138
// #if 1
139
// template<class T>
140
// RCP<const T> makecRCP_weak(T* x) // create a const pointer
141
// {
142
// return RCP<const T>(x, null_deleter());
143
// }
144
// #endif
145
146
147
// } // namespace concepts
sharedPointer_boost.hh
sharedPointer_std.hh
Page URL:
http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020
Eidgenössische Technische Hochschule Zürich