PSCF v1.4.0
CountedReference.cpp
1/*
2* Util Package - C++ Utilities for Scientific Computation
3*
4* Copyright 2010 - 2026, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8
9#include "CountedReference.h"
10#include "ReferenceCounter.h"
11#include <util/global.h>
12
13namespace Util {
14
15 /*
16 * Default constructor.
17 */
19 : ptr_(nullptr)
20 {}
21
22 /*
23 * Create an association with a ReferenceCounter.
24 */
26 {
28 ptr_ = &owner;
29 ++(ptr_->nRef_);
30 }
31
32 /*
33 * Destroy an association with a ReferenceCounter.
34 */
36 {
38 UTIL_CHECK(ptr_->nRef_ > 0);
39 --(ptr_->nRef_);
40 ptr_ = nullptr;
41 }
42
43} // namespace Util
void associate(ReferenceCounter &counter)
Create an association with a ReferenceCounter.
bool isAssociated() const
Is this associated with a ReferenceCounter?
void dissociate()
Destroy an association with a ReferenceCounter.
Reference counter.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Utility classes for scientific computation.