libMesh
reference_counted_object.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
29 namespace libMesh
30 {
31 
64 template <typename T>
66 {
67 protected:
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 
96 #ifdef LIBMESH_HAVE_CXX11_MOVE_CONSTRUCTORS
97 
101  : ReferenceCounter(std::move(other))
102  {
103 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
104 
105  increment_constructor_count(typeid(T).name());
106 
107 #endif
108  }
109 #endif
110 
119  {
120  return *this;
121  }
122 
123 
124 public:
125 
130  {
131 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
132 
133  increment_destructor_count(typeid(T).name());
134 
135 #endif
136  }
137 };
138 
139 
140 } // namespace libMesh
141 
142 
143 #endif // LIBMESH_REFERENCE_COUNTED_OBJECT_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
ReferenceCountedObject(ReferenceCountedObject &&other) noexcept
Move constructor, must be declared noexcept.
void increment_constructor_count(const std::string &name)
Increments the construction counter.
ReferenceCountedObject & operator=(const ReferenceCountedObject &)
Copy assignment operator does nothing - we&#39;re copying an already-allocated object over an already-all...
The libMesh namespace provides an interface to certain functionality in the library.
This is the base class for enabling reference counting.
ReferenceCountedObject(const ReferenceCountedObject &other)
Also, increment the counter if the copy-constructor is called.
void increment_destructor_count(const std::string &name)
Increments the destruction counter.
This class implements reference counting.