Referenced.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011, SRI International (R)
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <iostream>
19 
20 #ifdef USE_TBB
21 #include <tbb/mutex.h>
22 #endif
23 
24 #include <OpenKarto/Referenced.h>
25 
26 namespace karto
27 {
28 
32 
34  {
35 #ifdef USE_TBB
36  tbb::mutex m_Mutex;
37 #endif
38 
40 
42  : m_Counter(0)
43  {
44  }
45  };
46 
50 
52  : m_pReferencedPrivate(new ReferencedPrivate())
53  {
54  }
55 
56  Referenced::~Referenced()
57  {
59  {
60  std::cerr << "Deleting referenced object!!" << std::endl;
61  assert(false);
62  }
63 
64  delete m_pReferencedPrivate;
65  m_pReferencedPrivate = NULL;
66  }
67 
69  {
70 #ifdef USE_TBB
71  tbb::mutex::scoped_lock lock(m_pReferencedPrivate->m_Mutex);
72 #endif
73 
75  }
76 
78  {
79  kt_int32s count = 0;
80  bool deleteMe = false;
81 
82  {
83 #ifdef USE_TBB
84  tbb::mutex::scoped_lock lock(m_pReferencedPrivate->m_Mutex);
85 #endif
86 
88  deleteMe = count <= 0;
89  }
90 
91  if (deleteMe)
92  {
93  delete this;
94  }
95 
96  return count;
97  }
98 
100  {
101  {
102 #ifdef USE_TBB
103  tbb::mutex::scoped_lock lock(m_pReferencedPrivate->m_Mutex);
104 #endif
105 
107  }
108  }
109 
111  {
113  }
114 
115 }
kt_int32s GetReferenceCount()
Definition: Referenced.cpp:110
kt_int32s Unreference() const
Definition: Referenced.cpp:77
ReferencedPrivate * m_pReferencedPrivate
Definition: Referenced.h:91
kt_int32s UnreferenceNoDelete() const
Definition: Referenced.cpp:99
int32_t kt_int32s
Definition: Types.h:106
kt_int32s Reference() const
Definition: Referenced.cpp:68
Definition: Any.cpp:20


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Tue Nov 7 2017 06:02:36