ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
CVShareable.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "CVShareable.h"
9 
10 #ifdef CV_TRACK_ALIVE_SHARED_OBJECTS
11 
12 #ifdef _MSC_VER
13 // To get rid of the really annoying warnings about template class exportation
14 #pragma warning(disable : 4530)
15 #endif
16 
17 // system
18 #include <vector>
19 
20 // set of all currently 'alived' shared objects
21 static std::vector<CCShareable*> s_aliveSharedObjects;
22 
23 unsigned CCShareable::GetAliveCount() { return s_aliveSharedObjects.size(); }
24 
25 #endif
26 
27 CCShareable::CCShareable() : m_linkCount(0) {
28 #ifdef CV_TRACK_ALIVE_SHARED_OBJECTS
29  s_aliveSharedObjects.push_back(this);
30 #endif
31 }
32 
34 
36  if (m_linkCount > 1)
37  --m_linkCount;
38  else
39  delete this;
40 }
41 
43 #ifdef CV_TRACK_ALIVE_SHARED_OBJECTS
44  std::vector<CCShareable*>::iterator it;
45  for (it = s_aliveSharedObjects.begin(); it != s_aliveSharedObjects.end();
46  ++it) {
47  if (*it == this) {
48  std::swap(*it, s_aliveSharedObjects.back());
49  s_aliveSharedObjects.pop_back();
50  return;
51  }
52  }
53 #endif
54 }
virtual void link()
Increase counter.
Definition: CVShareable.cpp:33
virtual void release()
Decrease counter and deletes object when 0.
Definition: CVShareable.cpp:35
virtual ~CCShareable()
Destructor.
Definition: CVShareable.cpp:42
unsigned m_linkCount
Links counter.
Definition: CVShareable.h:54
CCShareable()
Default constructor.
Definition: CVShareable.cpp:27
void swap(cloudViewer::core::SmallVectorImpl< T > &LHS, cloudViewer::core::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: SmallVector.h:1370