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// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2013 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_SIMICS2TLM_MULTI_GASKET_OWNER_H
17#define SIMICS_SYSTEMC_SIMICS2TLM_MULTI_GASKET_OWNER_H
18
19
20
24
25#include <map>
26#include <set>
27#include <utility> // piecewise_construct
28
29namespace simics {
30namespace systemc {
31namespace simics2tlm {
32
41 public:
42 virtual ~MultiGasketOwner() = default;
43
44 void addGasket(int id, GasketInterface::Ptr gasketInterface) {
45 FATAL_ERROR_IF(hasId(id),
46 "Cannot bind the same ID (%d) to multiple gaskets", id);
47 gasket_map_.emplace(std::piecewise_construct,
48 std::forward_as_tuple(id),
49 std::forward_as_tuple());
50 // Workaround: Set ClassType::implementor_ using this class's value
51 gasket_map_[id].ClassType::operator=(*static_cast<ClassType *>(this));
52 // coverity[copy_instead_of_move]
53 gasket_map_[id].set_gasket(gasketInterface);
54 // Need to delete NullGasket if it exists
55 if (dynamic_cast<NullGasket*>(gasket_.get()))
56 gasket_ = NULL;
57 }
58
67 GasketOwnerMap::const_iterator it = gasket_map_.find(id);
68 if (it != gasket_map_.end()) {
69 return it->second.gasket();
70 } else if (!empty()) {
71 return gasket_map_.begin()->second.gasket();
72 } else {
73 return gasket();
74 }
75 }
76 std::set<int> keys() const {
77 std::set<int> k;
78 for (auto i = gasket_map_.begin(); i != gasket_map_.end(); ++i)
79 k.insert(i->first);
80
81 return k;
82 }
83
84 protected:
85 bool hasId(int id) const {
86 return gasket_map_.count(id);
87 }
88 int empty() const {
89 return gasket_map_.empty();
90 }
91
92 private:
93 typedef std::map<int, GasketOwner> GasketOwnerMap;
94 GasketOwnerMap gasket_map_;
95};
96
97} // namespace simics2tlm
98} // namespace systemc
99} // namespace simics
100
101#endif
Definition: class_type.h:25
std::shared_ptr< GasketInterface > Ptr
Definition: gasket_interface.h:37
Base class, responsible for handling a gasket.
Definition: gasket_owner.h:32
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:40
GasketInterface::Ptr findGasket(int id) const
Returns the gasket matching the ID given.
Definition: multi_gasket_owner.h:66
bool hasId(int id) const
Definition: multi_gasket_owner.h:85
std::set< int > keys() const
Definition: multi_gasket_owner.h:76
void addGasket(int id, GasketInterface::Ptr gasketInterface)
Definition: multi_gasket_owner.h:44
int empty() const
Definition: multi_gasket_owner.h:88
Definition: null_gasket.h:34
Definition: adapter.h:80