scc  2022.4.0
SystemC components library
tlm_gp_shared.h
1 /*******************************************************************************
2  * Copyright 2021-2022 MINRES Technologies GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************/
16 
17 #ifndef _SYSC_TLM_TLM_GP_SHARED_H_
18 #define _SYSC_TLM_TLM_GP_SHARED_H_
19 
20 #include <tlm>
21 
23 namespace tlm {
25 namespace scc {
26 
28  tlm::tlm_generic_payload* ptr{nullptr};
29 
30 public:
32  tlm_gp_shared_ptr() noexcept = default;
33 
35  inline tlm_gp_shared_ptr(tlm::tlm_generic_payload* p) noexcept
36  : ptr(p) {
37  if(ptr && ptr->has_mm())
38  ptr->acquire();
39  }
41  inline tlm_gp_shared_ptr(tlm_gp_shared_ptr const& p) noexcept
42  : ptr(p.ptr) {
43  if(ptr && ptr->has_mm())
44  ptr->acquire();
45  }
47  inline tlm_gp_shared_ptr(tlm_gp_shared_ptr&& p) noexcept
48  : ptr(std::move(p.ptr)) {
49  p.ptr = nullptr;
50  }
53  if(ptr && ptr->has_mm())
54  ptr->release();
55  }
58  if(ptr && ptr->has_mm())
59  ptr->release();
60  ptr = p.ptr;
61  if(ptr && ptr->has_mm())
62  ptr->acquire();
63  return *this;
64  }
67  if(ptr && ptr->has_mm())
68  ptr->release();
69  ptr = p.ptr;
70  p.ptr = nullptr;
71  return *this;
72  }
73 
75  tlm_gp_shared_ptr& operator=(tlm::tlm_generic_payload* p) noexcept {
76  if(ptr && ptr->has_mm())
77  ptr->release();
78  ptr = p;
79  if(ptr && ptr->has_mm())
80  ptr->acquire();
81  return *this;
82  }
83 
85  inline tlm::tlm_generic_payload& operator*() const noexcept { return *ptr; }
86 
88  inline tlm::tlm_generic_payload* operator->() const noexcept { return ptr; }
89 
91  inline tlm::tlm_generic_payload* get() const noexcept { return ptr; }
92 
93  inline operator bool() const noexcept { return ptr != nullptr; }
94 };
95 inline std::ostream& operator<<(std::ostream& os, tlm_gp_shared_ptr const& p) {
96  os << p.get();
97  return os;
98 }
99 inline bool operator==(tlm_gp_shared_ptr const& x, tlm_gp_shared_ptr const& y) noexcept { return x.get() == y.get(); }
100 
101 inline bool operator==(tlm_gp_shared_ptr const& x, tlm::tlm_generic_payload* y) noexcept { return x.get() == y; }
102 
103 inline bool operator!=(tlm_gp_shared_ptr const& x, tlm_gp_shared_ptr const& y) noexcept { return x.get() != y.get(); }
104 } // namespace scc
105 } // namespace tlm
106 #endif /* _SYSC_TLM_TLM_GP_SHARED_H_ */
tlm_gp_shared_ptr(tlm_gp_shared_ptr &&p) noexcept
Move constructor.ยด
Definition: tlm_gp_shared.h:47
tlm::tlm_generic_payload * get() const noexcept
Return the stored pointer.
Definition: tlm_gp_shared.h:91
tlm_gp_shared_ptr(tlm_gp_shared_ptr const &p) noexcept
Copy constructor.
Definition: tlm_gp_shared.h:41
tlm::tlm_generic_payload & operator*() const noexcept
Dereference the stored pointer.
Definition: tlm_gp_shared.h:85
tlm::tlm_generic_payload * operator->() const noexcept
Return the stored pointer.
Definition: tlm_gp_shared.h:88
tlm_gp_shared_ptr & operator=(tlm_gp_shared_ptr &&p) noexcept
Move assignment operator.
Definition: tlm_gp_shared.h:66
tlm_gp_shared_ptr & operator=(tlm::tlm_generic_payload *p) noexcept
raw pointer assignment operator.
Definition: tlm_gp_shared.h:75
tlm_gp_shared_ptr & operator=(tlm_gp_shared_ptr const &p) noexcept
Copy assignment operator.
Definition: tlm_gp_shared.h:57
tlm_gp_shared_ptr() noexcept=default
Default constructor, creates a unique_ptr that owns nothing.
SCC SystemC utilities.
SystemC TLM.