SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
reference_counter.h
Go to the documentation of this file.
1/*
2 © 2014 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_REFERENCE_COUNTER_H
15#define SIMICS_SYSTEMC_REFERENCE_COUNTER_H
16
17#include <map>
18#include <string>
19
20namespace simics {
21namespace systemc {
22
24template <class T>
26 public:
27 ReferenceCounter(T *ptr) : ptr_(ptr) { // NOLINT(runtime/explicit)
28 ++references_[ptr];
29 }
31 ptr_ = reference.ptr_;
32 ++references_[ptr_];
33 }
35 --references_[ptr_];
36 // coverity[self_assign]
37 ptr_ = reference.ptr_;
38 ++references_[ptr_];
39 return *this;
40 }
42 return ptr_;
43 }
44 operator T *() const {
45 return ptr_;
46 }
48 --references_[ptr_];
49 }
50 int references() const {
51 return references_[ptr_];
52 }
53
54 private:
55 T *ptr_;
56 static std::map<T *, int> references_;
57};
58
59template<class T> std::map<T *, int> ReferenceCounter<T>::references_;
60
61} // namespace systemc
62} // namespace simics
63
64#endif
Definition: reference_counter.h:25
T * operator->()
Definition: reference_counter.h:41
int references() const
Definition: reference_counter.h:50
ReferenceCounter & operator=(const ReferenceCounter &reference)
Definition: reference_counter.h:34
ReferenceCounter(const ReferenceCounter &reference)
Definition: reference_counter.h:30
ReferenceCounter(T *ptr)
Definition: reference_counter.h:27
virtual ~ReferenceCounter()
Definition: reference_counter.h:47
Definition: adapter.h:79