Line |
Branch |
Exec |
Source |
1 |
|
|
// ______ ______ _ _ _____ ______ |
2 |
|
|
// | ____| ____| | (_)/ ____| | ____| |
3 |
|
|
// | |__ | |__ | | _| (___ ___| |__ |
4 |
|
|
// | __| | __| | | | |\___ \ / __| __| |
5 |
|
|
// | | | |____| |____| |____) | (__| |____ |
6 |
|
|
// |_| |______|______|_|_____/ \___|______| |
7 |
|
|
// Finite Elements for Life Sciences and Engineering |
8 |
|
|
// |
9 |
|
|
// License: LGL2.1 License |
10 |
|
|
// FELiScE default license: LICENSE in root folder |
11 |
|
|
// |
12 |
|
|
// Main authors: https://www.boost.org/doc/libs/1_74_0/libs/smart_ptr/doc/html/smart_ptr.html#intrusive_ptr |
13 |
|
|
// |
14 |
|
|
|
15 |
|
|
#if !defined(FELISCE_MEMORY_H_INCLUDED ) |
16 |
|
|
#define FELISCE_MEMORY_H_INCLUDED |
17 |
|
|
|
18 |
|
|
/* System includes */ |
19 |
|
|
#include <iostream> |
20 |
|
|
#include <utility> |
21 |
|
|
#include <memory> |
22 |
|
|
|
23 |
|
|
/* External includes */ |
24 |
|
|
#include "intrusive_ptr/intrusive_ptr.hpp" |
25 |
|
|
|
26 |
|
|
namespace felisce { |
27 |
|
|
|
28 |
|
|
template<class T> |
29 |
|
|
using shared_ptr = std::shared_ptr<T>; |
30 |
|
|
|
31 |
|
|
template<class T> |
32 |
|
|
using weak_ptr = std::weak_ptr<T>; |
33 |
|
|
|
34 |
|
|
template<class T> |
35 |
|
|
using unique_ptr = std::unique_ptr<T>; |
36 |
|
|
|
37 |
|
|
template<typename C, typename...Args> |
38 |
|
1 |
intrusive_ptr<C> make_intrusive(Args &&...args) { |
39 |
|
1 |
return intrusive_ptr<C>(new C(std::forward<Args>(args)...)); |
40 |
|
|
} |
41 |
|
|
template<typename C, typename...Args> |
42 |
|
688030 |
shared_ptr<C> make_shared(Args &&...args) { |
43 |
|
688030 |
return std::make_shared<C>(std::forward<Args>(args)...); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
template<typename C, typename...Args> |
47 |
|
|
unique_ptr<C> make_unique(Args &&...args) { |
48 |
|
|
// Note: std::make_unique is C++14, this can be updated once we upgrade from C++11 |
49 |
|
|
return unique_ptr<C>(new C(std::forward<Args>(args)...)); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
template<class T> |
53 |
|
|
std::ostream& operator <<(std::ostream& rOStream, const felisce::weak_ptr<T>& rData) { |
54 |
|
|
|
55 |
|
|
if(!rData.expired()) |
56 |
|
|
rOStream << *rData.lock().get(); |
57 |
|
|
else |
58 |
|
|
rOStream <<" expired weak_ptr "; |
59 |
|
|
|
60 |
|
|
return rOStream; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
template<class T> |
64 |
|
|
std::ostream& operator <<(std::ostream& rOStream, const felisce::intrusive_ptr<T>& rData) { |
65 |
|
|
rOStream << *rData.get(); |
66 |
|
|
return rOStream; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
} // namespace felisce |
70 |
|
|
|
71 |
|
|
#define FELISCE_CLASS_POINTER_DEFINITION(a) typedef felisce::shared_ptr<a > Pointer; \ |
72 |
|
|
typedef felisce::shared_ptr<a > SharedPointer; \ |
73 |
|
|
typedef felisce::weak_ptr<a > WeakPointer; \ |
74 |
|
|
typedef felisce::unique_ptr<a > UniquePointer |
75 |
|
|
|
76 |
|
|
namespace felisce { |
77 |
|
|
template< class T > class GlobalPointer; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
#define FELISCE_CLASS_INTRUSIVE_POINTER_DEFINITION(a) typedef typename felisce::intrusive_ptr<a > Pointer; \ |
81 |
|
|
typedef felisce::GlobalPointer<a > WeakPointer; \ |
82 |
|
|
typedef felisce::unique_ptr<a > UniquePointer; \ |
83 |
|
|
typename a::Pointer shared_from_this(){ return a::Pointer(this); } |
84 |
|
|
|
85 |
|
|
#endif /* FELISCE_MEMORY_H_INCLUDED defined */ |
86 |
|
|
|