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