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