vtk-dicom  0.8.17
vtkDICOMReferenceCount.h
1 /*=========================================================================
2 
3  Program: DICOM for VTK
4 
5  Copyright (c) 2012-2024 David Gobbi
6  All rights reserved.
7  See Copyright.txt or http://dgobbi.github.io/bsd3.txt for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef vtkDICOMReferenceCount_h
15 #define vtkDICOMReferenceCount_h
16 
17 #include "vtkSystemIncludes.h"
18 #include "vtkDICOMModule.h" // For export macro
19 
21 
26 class VTKDICOM_EXPORT vtkDICOMReferenceCount
27 {
28 public:
29  vtkDICOMReferenceCount(unsigned int i) : Counter(i) {}
30  vtkDICOMReferenceCount() : Counter(0) {}
31 
32  unsigned int operator--();
33  unsigned int operator++();
34 
35  bool operator==(unsigned int x) const {
36  return this->Counter == x; }
37  bool operator!=(unsigned int x) const {
38  return this->Counter != x; }
39 
40 private:
41  unsigned int Counter;
42 };
43 
44 #if !defined(_WIN32)
45 inline unsigned int vtkDICOMReferenceCount::operator--()
46 {
47 #if defined(VTK_HAVE_SYNC_BUILTINS)
48  return __sync_sub_and_fetch(&this->Counter, 1);
49 #else
50  return --this->Counter;
51 #endif
52 }
53 #endif
54 
55 #if !defined(_WIN32)
56 inline unsigned int vtkDICOMReferenceCount::operator++()
57 {
58 #if defined(VTK_HAVE_SYNC_BUILTINS)
59  return __sync_add_and_fetch(&this->Counter, 1);
60 #else
61  return ++this->Counter;
62 #endif
63 }
64 #endif
65 
66 #endif /* vtkDICOMReferenceCount_h */
67 // VTK-HeaderTest-Exclude: vtkDICOMReferenceCount.h
An object for holding an atomic reference count.
Definition: vtkDICOMReferenceCount.h:27