SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
connector.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_CONNECTOR_H
17#define SIMICS_SYSTEMC_CONNECTOR_H
18
19#include <simics/connect.h>
21
22#include <map>
23#include <utility> // make_pair
24
25namespace simics {
26namespace systemc {
27
28class ConnectorBase : public ConnectBase {
29 protected:
30 static std::multimap<ConnectorBase *, ConnectorBase *> root_to_proxy_;
31};
32
40template<typename InterfaceProvider>
41class Connector : public ConnectorBase {
42 public:
43 enum { is_proxy = false };
44 Connector() = default;
45 Connector(const Connector &other) {
46 set(other.get());
47 }
48 Connector &operator=(const Connector &other) {
49 set(other.get());
50 return *this;
51 }
52
53 bool set(const ConfObjectRef &connect) override {
54 obj_ = connect;
55 provider_.set_target(obj_);
56
57 auto iterators = root_to_proxy_.equal_range(this);
58 for (auto i = iterators.first; i != iterators.second; ++i) {
59 if (!i->second->set(connect))
60 return false;
61 }
62 return true;
63 }
64
65 InterfaceProvider &provider() { return provider_; }
66 const InterfaceProvider &provider() const { return provider_; }
67 InterfaceProvider *operator->() { return &provider_; }
68 const InterfaceProvider *operator->() const { return &provider_; }
69
70 private:
71 InterfaceProvider provider_;
72};
73
74template<typename InterfaceProvider>
75class ConnectorProxy : public Connector<InterfaceProvider> {
76 public:
77 enum { is_proxy = true };
78 explicit ConnectorProxy(ConnectorBase *root) {
79 iterator_ = this->root_to_proxy_.emplace(std::make_pair(root, this));
80 }
82 this->root_to_proxy_.erase(iterator_);
83 }
84
85 private:
86 std::multimap<ConnectorBase *, ConnectorBase *>::iterator iterator_;
87};
88
89} // namespace systemc
90} // namespace simics
91
92#endif
Definition: connector.h:28
static std::multimap< ConnectorBase *, ConnectorBase * > root_to_proxy_
Definition: connector.h:30
Definition: connector.h:75
ConnectorProxy(ConnectorBase *root)
Definition: connector.h:78
@ is_proxy
Definition: connector.h:77
~ConnectorProxy()
Definition: connector.h:81
Provides get/set functionality for a connector attribute, typically registered by using the Connector...
Definition: connector.h:41
InterfaceProvider * operator->()
Definition: connector.h:67
InterfaceProvider & provider()
Definition: connector.h:65
const InterfaceProvider & provider() const
Definition: connector.h:66
bool set(const ConfObjectRef &connect) override
Definition: connector.h:53
@ is_proxy
Definition: connector.h:43
const InterfaceProvider * operator->() const
Definition: connector.h:68
Connector(const Connector &other)
Definition: connector.h:45
Connector & operator=(const Connector &other)
Definition: connector.h:48
Returns the interface provided by the associated Simics object.
Definition: interface_provider.h:32
virtual void set_target(const ConfObjectRef &obj)
Definition: interface_provider.h:58
Definition: pci_bus_interface.h:24