libMesh
Loading...
Searching...
No Matches
reference_counted_object.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20#ifndef LIBMESH_REFERENCE_COUNTED_OBJECT_H
21#define LIBMESH_REFERENCE_COUNTED_OBJECT_H
22
23// Local includes
24#include "libmesh/reference_counter.h"
25
26// C++ includes
27#include <typeinfo>
28
29namespace libMesh
30{
31
64template <typename T>
66{
67protected:
68
75 {
76#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
77
78 increment_constructor_count(typeid(T).name());
79
80#endif
81 }
82
87 : ReferenceCounter(other)
88 {
89#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
90
91 increment_constructor_count(typeid(T).name());
92
93#endif
94 }
95
100 : ReferenceCounter(std::move(other))
101 {
102#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
103
104 increment_constructor_count(typeid(T).name());
105
106#endif
107 }
108
117 {
118 return *this;
119 }
120
121
122public:
123
128 {
129#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
130
131 increment_destructor_count(typeid(T).name());
132
133#endif
134 }
135};
136
137
138} // namespace libMesh
139
140
141#endif // LIBMESH_REFERENCE_COUNTED_OBJECT_H
This class implements reference counting.
ReferenceCountedObject & operator=(const ReferenceCountedObject &)
Copy assignment operator does nothing - we're copying an already-allocated object over an already-all...
ReferenceCountedObject(const ReferenceCountedObject &other)
Also, increment the counter if the copy-constructor is called.
ReferenceCountedObject(ReferenceCountedObject &&other) noexcept
Move constructor, must be declared noexcept.
This is the base class for enabling reference counting.
void increment_destructor_count(const std::string &name) noexcept
Increments the destruction counter.
void increment_constructor_count(const std::string &name) noexcept
Increments the construction counter.
The libMesh namespace provides an interface to certain functionality in the library.