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-2023 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 protected:
58 
59  // Constructors
60 
61  //- Construct null initialising count to 0
62  refCount()
63  :
64  count_(0)
65  {}
66 
67  //- Disallow copy
68  refCount(const refCount&) = delete;
69 
70 
71 public:
72 
73  // Member Functions
74 
75  //- Return the current reference count
76  int count() const
77  {
78  return count_;
79  }
80 
81  //- Return true if the reference count is zero
82  bool unique() const
83  {
84  return count_ == 0;
85  }
86 
87 
88  // Member Operators
89 
90  //- Increment the reference count
91  void operator++()
92  {
93  count_++;
94  }
95 
96  //- Increment the reference count
97  void operator++(int)
98  {
99  count_++;
100  }
101 
102  //- Decrement the reference count
103  void operator--()
104  {
105  count_--;
106  }
107 
108  //- Decrement the reference count
109  void operator--(int)
110  {
111  count_--;
112  }
113 
114  //- Disallow bitwise assignment
115  void operator=(const refCount&) = delete;
116 };
117 
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 } // End namespace Foam
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 
125 #endif
126 
127 // ************************************************************************* //
System bool.
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
void operator++()
Increment the reference count.
Definition: refCount.H:90
void operator=(const refCount &)=delete
Disallow bitwise assignment.
int count() const
Return the current reference count.
Definition: refCount.H:75
bool unique() const
Return true if the reference count is zero.
Definition: refCount.H:81
refCount()
Construct null initialising count to 0.
Definition: refCount.H:61
void operator--()
Decrement the reference count.
Definition: refCount.H:102
Namespace for OpenFOAM.