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
28namespace simics {
29namespace systemc {
30namespace simics2tlm {
31
40 public:
41 void addGasket(int id, GasketInterface::Ptr gasketInterface) {
42 FATAL_ERROR_IF(hasId(id),
43 "Cannot bind the same ID (%d) to multiple gaskets", id);
44 // TODO(ah): when we move to C++11 we can store the GasketOwner
45 // instance in the map instead of a pointer, in order to simplify this
46 // class a bit. In pre-11 we cannot do this as GasketOwner is
47 // non-copyable and there are no move-constructors in pre-11. As an
48 // alternative, we could use boost::shared_ptr to keep track of
49 // GasketOwner's resource pointer and make it copyable.
50 GasketOwner *gasket_owner = new GasketOwner;
51 *static_cast<ClassType *>(gasket_owner) =
52 *static_cast<ClassType *>(this);
53 gasket_owner->set_gasket(
54 gasketInterface); // coverity[copy_instead_of_move]
55 gasket_map_[id] = gasket_owner;
56 // Need to delete NullGasket if it exists
57 if (dynamic_cast<NullGasket*>(gasket_.get()))
58 gasket_ = NULL;
59 }
60
69 GasketOwnerMap::const_iterator it = gasket_map_.find(id);
70 if (it != gasket_map_.end()) {
71 return it->second->gasket();
72 } else if (!empty()) {
73 return gasket_map_.begin()->second->gasket();
74 } else {
75 return gasket();
76 }
77 }
78 std::set<int> keys() const {
79 std::set<int> k;
80 for (auto i = gasket_map_.begin(); i != gasket_map_.end(); ++i)
81 k.insert(i->first);
82
83 return k;
84 }
86 for (GasketOwnerMap::iterator it = gasket_map_.begin();
87 it != gasket_map_.end(); ++it) {
88 delete it->second;
89 }
90 }
91
92 protected:
93 bool hasId(int id) const {
94 return gasket_map_.count(id);
95 }
96 int empty() const {
97 return gasket_map_.empty();
98 }
99
100 private:
101 typedef std::map<int, GasketOwner*> GasketOwnerMap;
102 GasketOwnerMap gasket_map_;
103};
104
105} // namespace simics2tlm
106} // namespace systemc
107} // namespace simics
108
109#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:46
void set_gasket(GasketInterface::Ptr gasketInterface)
Definition: gasket_owner.h:39
GasketInterface::Ptr gasket_
Definition: gasket_owner.h:50
GasketOwner()
Definition: gasket_owner.h:34
Container class for multiple GasketOwners, each given a unique ID.
Definition: multi_gasket_owner.h:39
GasketInterface::Ptr findGasket(int id) const
Returns the gasket matching the ID given.
Definition: multi_gasket_owner.h:68
virtual ~MultiGasketOwner()
Definition: multi_gasket_owner.h:85
bool hasId(int id) const
Definition: multi_gasket_owner.h:93
std::set< int > keys() const
Definition: multi_gasket_owner.h:78
void addGasket(int id, GasketInterface::Ptr gasketInterface)
Definition: multi_gasket_owner.h:41
int empty() const
Definition: multi_gasket_owner.h:96
Definition: null_gasket.h:34
Definition: pci_bus_interface.h:24