SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
sc_attribute.h
Go to the documentation of this file.
1/*
2 © 2019 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_AWARENESS_SC_ATTRIBUTE_H
15#define SIMICS_SYSTEMC_AWARENESS_SC_ATTRIBUTE_H
16
18
19#include <systemc>
20
21#include <string>
22
23namespace simics {
24namespace systemc {
25namespace awareness {
26
28 public:
30 virtual void init(sc_core::sc_object *object,
31 sc_core::sc_attr_base *attr) = 0;
32 virtual int key() const = 0;
33 virtual sc_core::sc_attr_base *attr() = 0;
34 virtual sc_core::sc_attr_base *attr() const = 0;
35};
36
37template<class A>
39 public:
40 explicit ScAttribute(int key) : Attribute(key), attr_(NULL) {}
41 // ScAttributeInterface
42 void init(sc_core::sc_object *object,
43 sc_core::sc_attr_base *attr) override {
44 object_name_ = object->name();
45 attr_name_ = attr->name();
46 attr_ = attr;
47 }
48 int key() const override {
49 return Attribute::key();
50 }
51 sc_core::sc_attr_base *attr() override {
52 return attr_;
53 }
54 sc_core::sc_attr_base *attr() const override {
55 return attr_;
56 }
57
58 // Attribute
59 Attribute *create() override {
60 sc_core::sc_object *obj = sc_core::sc_find_object(object_name_.c_str());
61 if (obj)
62 attr_ = obj->get_attribute(attr_name_);
63 else
64 attr_ = NULL;
65
66 return new ScAttribute<A>(*this);
67 }
68 set_error_t set(attr_value_t *val) override {
69 A access;
70 if (access.set(attr(), val))
71 return Sim_Set_Ok;
72
73 return Sim_Set_Illegal_Type;
74 }
75 attr_value_t get() const override {
76 A access;
77 return access.get(attr());
78 }
79
80 private:
81 std::string object_name_;
82 std::string attr_name_;
83 sc_core::sc_attr_base *attr_;
84};
85
86} // namespace awareness
87} // namespace systemc
88} // namespace simics
89
90#endif
Definition: attribute.h:24
int key() const
Definition: attribute.h:29
virtual sc_core::sc_attr_base * attr() const =0
virtual sc_core::sc_attr_base * attr()=0
virtual ~ScAttributeInterface()
Definition: sc_attribute.h:29
virtual void init(sc_core::sc_object *object, sc_core::sc_attr_base *attr)=0
Definition: sc_attribute.h:38
sc_core::sc_attr_base * attr() const override
Definition: sc_attribute.h:54
attr_value_t get() const override
Definition: sc_attribute.h:75
sc_core::sc_attr_base * attr() override
Definition: sc_attribute.h:51
Attribute * create() override
Definition: sc_attribute.h:59
int key() const override
Definition: sc_attribute.h:48
set_error_t set(attr_value_t *val) override
Definition: sc_attribute.h:68
void init(sc_core::sc_object *object, sc_core::sc_attr_base *attr) override
Definition: sc_attribute.h:42
ScAttribute(int key)
Definition: sc_attribute.h:40
Definition: adapter.h:79