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