pimpl_ptr.cti
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief pimpl_ptr inline template implementation */
16 
17 //#include "pimpl_ptr.ih"
18 
19 // Custom includes
20 #include "IgnoreValue.hh"
21 
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::pimpl_ptr<T,CloneAllocator>
27 
28 template <typename T, class CloneAllocator>
29 prefix_ senf::pimpl_ptr<T,CloneAllocator>::pimpl_ptr(T* pointee)
30  : p (pointee)
31 {
32  // Is it fair to assume pointer assignment to be atomic on multi-threaded platforms ?
33  doCopy_ = &myCopyFn;
34  doDelete_ = &myDeleteFn;
35 }
36 
37 template <typename T, class CloneAllocator>
38 prefix_ senf::pimpl_ptr<T,CloneAllocator>::pimpl_ptr(const pimpl_ptr & rhs)
39  : p (doCopy_(rhs.p))
40 {}
41 
42 template <typename T, class CloneAllocator>
43 prefix_ senf::pimpl_ptr<T,CloneAllocator>::~pimpl_ptr()
44  throw()
45 {
46  doDelete_(p);
47 }
48 
49 template <typename T, class CloneAllocator>
50 prefix_ const T* senf::pimpl_ptr<T,CloneAllocator>::get()
51  const throw()
52 {
53  return p;
54 }
55 
56 template <typename T, class CloneAllocator>
57 prefix_ T* senf::pimpl_ptr<T,CloneAllocator>::get()
58  throw()
59 {
60  return p;
61 }
62 
63 template <typename T, class CloneAllocator>
64 prefix_ const T* senf::pimpl_ptr<T,CloneAllocator>::operator->()
65  const throw()
66 {
67  return p;
68 }
69 
70 template <typename T, class CloneAllocator>
71 prefix_ T* senf::pimpl_ptr<T,CloneAllocator>::operator->()
72  throw()
73 {
74  return p;
75 }
76 
77 template <typename T, class CloneAllocator>
78 prefix_ const T& senf::pimpl_ptr<T,CloneAllocator>::operator*()
79  const throw()
80 {
81  return *p;
82 }
83 
84 template <typename T, class CloneAllocator>
85 prefix_ T& senf::pimpl_ptr<T,CloneAllocator>::operator*()
86  throw()
87 {
88  return *p;
89 }
90 
91 template <typename T, class CloneAllocator>
92 prefix_ void senf::pimpl_ptr<T,CloneAllocator>::swap(pimpl_ptr & with)
93  throw()
94 {
95  std::swap(p, with.p);
96 }
97 
98 template <typename T, class CloneAllocator>
99 prefix_ senf::pimpl_ptr<T,CloneAllocator> &
100 senf::pimpl_ptr<T,CloneAllocator>::operator=(const pimpl_ptr & rhs)
101 {
102  T* pp = doCopy_(rhs.p);
103  doDelete_(p);
104  p = pp;
105  return *this;
106 }
107 
108 template <typename T, class CloneAllocator>
109 prefix_ void senf::pimpl_ptr<T,CloneAllocator>::myDeleteFn(T* p)
110 {
111  return CloneAllocator::deallocate_clone(p);
112 }
113 
114 template <typename T, class CloneAllocator>
115 prefix_ T* senf::pimpl_ptr<T,CloneAllocator>::myCopyFn(const T* p)
116 {
117  return CloneAllocator::allocate_clone(*p);
118 }
119 
120 //-/////////////////////////////////////////////////////////////////////////////////////////////////
121 
122 template <class T, class CloneAllocator>
123 prefix_ void std::swap(senf::pimpl_ptr<T,CloneAllocator> & lhs,
124  senf::pimpl_ptr<T,CloneAllocator> & rhs)
125  throw()
126 {
127  lhs.swap(rhs);
128 }
129 
130 template <class T, class CloneAllocator>
131 typename senf::pimpl_ptr<T,CloneAllocator>::Copier
132  senf::pimpl_ptr<T,CloneAllocator>::doCopy_ (0);
133 
134 template <class T, class CloneAllocator>
135 typename senf::pimpl_ptr<T,CloneAllocator>::Deleter
136  senf::pimpl_ptr<T,CloneAllocator>::doDelete_ (0);
137 
138 //-/////////////////////////////////////////////////////////////////////////////////////////////////
139 #undef prefix_
140 
141 
142 // Local Variables:
143 // mode: c++
144 // fill-column: 100
145 // comment-column: 40
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"
150 // End: