ESyS-Particle  2.3.4
handle.hpp
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
12 
13 template<typename T>
14 T_Handle<T>::T_Handle(T* t): m_rep(t), m_count(new int(1))
15 {}
16 
17 template<typename T>
18 T_Handle<T>::T_Handle(const T_Handle& h): m_rep(h.m_rep), m_count(h.m_count)
19 {
20  (*m_count)++;
21 }
22 
23 template<typename T>
25 {
26  if(--(*m_count)==0){
27  delete m_rep;
28  delete m_count;
29  }
30 }
31 
32 template<typename T>
34 {
35  if(m_rep!=h.m_rep){
36  if(--(*m_count)==0){
37  delete m_rep;
38  delete m_count;
39  }
40  m_rep=h.m_rep;
41  m_count=h.m_count;
42  (*m_count)++;
43  }
44  return *this;
45 }
46 
47 /*template<typename T>
48 void T_Handle<T>::destroy()
49 {
50  if (m_count!=1) {
51  throw HandleException;
52  } else {
53 
54  }
55  }*/
T_Handle::m_count
int * m_count
Definition: handle.h:30
T_Handle::~T_Handle
~T_Handle()
Definition: handle.hpp:24
T_Handle::T_Handle
T_Handle(T *)
Definition: handle.hpp:14
T_Handle::m_rep
T * m_rep
Definition: handle.h:29
T_Handle
Template class for a handle/ref. counted pointer.
Definition: handle.h:27
T_Handle::operator=
T_Handle & operator=(const T_Handle &)
Definition: handle.hpp:33