refCount.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::refCount
26 
27 Description
28  Reference counter for various OpenFOAM components.
29 
30 See also
31  Foam::tmp
32  Foam::token::compound
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef refCount_H
37 #define refCount_H
38 
39 #include "bool.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class refCount Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class refCount
51 {
52  // Private Data
53 
54  int count_;
55 
56 
57  // Private Member Functions
58 
59  //- Disallow copy
60  refCount(const refCount&);
61 
62  //- Disallow bitwise assignment
63  void operator=(const refCount&);
64 
65 
66 protected:
67 
68  // Constructors
69 
70  //- Construct null initialising count to 0
71  refCount()
72  :
73  count_(0)
74  {}
75 
76 
77 public:
78 
79  // Member Functions
80 
81  //- Return the current reference count
82  int count() const
83  {
84  return count_;
85  }
86 
87  //- Return true if the reference count is zero
88  bool unique() const
89  {
90  return count_ == 0;
91  }
92 
93 
94  // Member Operators
95 
96  //- Increment the reference count
97  void operator++()
98  {
99  count_++;
100  }
101 
102  //- Increment the reference count
103  void operator++(int)
104  {
105  count_++;
106  }
107 
108  //- Decrement the reference count
109  void operator--()
110  {
111  count_--;
112  }
113 
114  //- Decrement the reference count
115  void operator--(int)
116  {
117  count_--;
118  }
119 };
120 
121 
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 
124 } // End namespace Foam
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 #endif
129 
130 // ************************************************************************* //
void operator++()
Increment the reference count.
Definition: refCount.H:96
Reference counter for various OpenFOAM components.
Definition: refCount.H:49
refCount()
Construct null initialising count to 0.
Definition: refCount.H:70
bool unique() const
Return true if the reference count is zero.
Definition: refCount.H:87
int count() const
Return the current reference count.
Definition: refCount.H:81
void operator--()
Decrement the reference count.
Definition: refCount.H:108
System bool.
Namespace for OpenFOAM.