SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
multi_gasket_owner.h
Go to the documentation of this file.
1/*
2 © 2013 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_SIMICS2TLM_MULTI_GASKET_OWNER_H
15#define SIMICS_SYSTEMC_SIMICS2TLM_MULTI_GASKET_OWNER_H
16
17
18
22
23#include <map>
24#include <set>
25#include <utility> // piecewise_construct
26
27namespace simics {
28namespace systemc {
29namespace simics2tlm {
30
39 public:
40 virtual ~MultiGasketOwner() = default;
41
42 void addGasket(int id, GasketInterface::Ptr gasketInterface) {
43 FATAL_ERROR_IF(hasId(id),
44 "Cannot bind the same ID (%d) to multiple gaskets", id);
45 gasket_map_.emplace(std::piecewise_construct,
46 std::forward_as_tuple(id),
47 std::forward_as_tuple());
48 // Workaround: Set ClassType::implementor_ using this class's value
49 gasket_map_[id].ClassType::operator=(*static_cast<ClassType *>(this));
50 gasket_map_[id].set_gasket(std::move(gasketInterface));
51 // Need to delete NullGasket if it exists
52 if (dynamic_cast<NullGasket*>(gasket_.get()))
53 gasket_ = NULL;
54 }
55
64 GasketOwnerMap::const_iterator it = gasket_map_.find(id);
65 if (it != gasket_map_.end()) {
66 return it->second.gasket();
67 } else if (!empty()) {
68 return gasket_map_.begin()->second.gasket();
69 } else {
70 return gasket();
71 }
72 }
73 std::set<int> keys() const {
74 std::set<int> k;
75 for (auto i = gasket_map_.begin(); i != gasket_map_.end(); ++i)
76 k.insert(i->first);
77
78 return k;
79 }
80
81 protected:
82 bool hasId(int id) const {
83 return gasket_map_.count(id);
84 }
85 int empty() const {
86 return gasket_map_.empty();
87 }
88
89 private:
90 typedef std::map<int, GasketOwner> GasketOwnerMap;
91 GasketOwnerMap gasket_map_;
92};
93
94} // namespace simics2tlm
95} // namespace systemc
96} // namespace simics
97
98#endif
Definition: class_type.h:23
std::shared_ptr< GasketInterface > Ptr
Definition: gasket_interface.h:35
Base class, responsible for handling a gasket.
Definition: gasket_owner.h:30
GasketInterface::Ptr gasket() const
Definition: gasket_owner.h:47
GasketInterface::Ptr gasket_
Definition: gasket_owner.h:51
Container class for multiple GasketOwners, each given a unique ID.
Definition: multi_gasket_owner.h:38
GasketInterface::Ptr findGasket(int id) const
Returns the gasket matching the ID given.
Definition: multi_gasket_owner.h:63
bool hasId(int id) const
Definition: multi_gasket_owner.h:82
std::set< int > keys() const
Definition: multi_gasket_owner.h:73
void addGasket(int id, GasketInterface::Ptr gasketInterface)
Definition: multi_gasket_owner.h:42
int empty() const
Definition: multi_gasket_owner.h:85
Definition: null_gasket.h:40
Definition: adapter.h:79