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