C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
attribute.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2021 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_ATTRIBUTE_H
17#define SIMICS_ATTRIBUTE_H
18
19#include <simics/base/conf-object.h> // attr_attr_t
20
21#include <string>
22#include <type_traits> // add_pointer_t
23
27
31#define GET_MACRO(_1, _2, NAME, ...) NAME
32
36#define IMPL(str) str
37
42#define ATTR_GETTER(...) \
43 IMPL(GET_MACRO(__VA_ARGS__, _G_DUAL, _G_SINGLE)(__VA_ARGS__))
44#define ATTR_SETTER(...) \
45 IMPL(GET_MACRO(__VA_ARGS__, _S_DUAL, _S_SINGLE)(__VA_ARGS__))
46#define ATTR_CLS_VAR(CLASS, VAR) \
47 simics::AttributeAccessor<CLASS, decltype(&CLASS::VAR), &CLASS::VAR>()
49#define ATTR_TYPE_STR(VAR) simics::attr_type_str<decltype(VAR)>()
50
51namespace simics {
52
53using attr_getter = std::add_pointer_t<attr_value_t(conf_object_t *)>;
54using attr_setter = std::add_pointer_t<set_error_t(conf_object_t *,
55 attr_value_t *)>;
56
60template <typename CLASS, typename MEMBER, MEMBER m>
62 static_assert(std::is_member_object_pointer<MEMBER>::value,
63 "type MEMBER is not a member object pointer type");
64
66 : getter(detail::attr_getter_helper_dual<
67 MEMBER, CLASS>::template f<m>),
68 setter(detail::attr_setter_helper_dual<
69 MEMBER, CLASS>::template f<m>) {}
70
73};
74
79class Attribute {
80 public:
92 Attribute(const std::string &name, const std::string &type,
93 const std::string &desc, attr_getter getter, attr_setter setter,
94 attr_attr_t attr)
95 : name_(name), type_(type), desc_(desc), getter_(getter),
96 setter_(setter), attr_(attr) {}
97
98 Attribute(const std::string &name, const std::string &type,
99 const std::string &desc, attr_getter getter, attr_setter setter)
101 (getter && setter) ? Sim_Attr_Optional : Sim_Attr_Pseudo) {}
102
106 template <typename CLASS, typename MEMBER, MEMBER m>
107 Attribute(const std::string &name, const std::string &type,
108 const std::string &desc, AttributeAccessor<CLASS, MEMBER, m> ref,
109 attr_attr_t attr = Sim_Attr_Optional)
110 : Attribute(name, type, desc, ref.getter, ref.setter, attr) {}
111
112 virtual ~Attribute() = default;
113 // destructor definition implicit deprecate move, force it here
114 Attribute(Attribute&&) = default;
115
116 virtual const std::string &name() const {
117 return name_;
118 }
119
120 virtual const std::string &type() const {
121 return type_;
122 }
123
124 virtual const std::string &desc() const {
125 return desc_;
126 }
127
128 virtual attr_getter getter() const {
129 return getter_;
130 }
131
132 virtual attr_setter setter() const {
133 return setter_;
134 }
135
136 virtual attr_attr_t attr() const {
137 return attr_;
138 }
139
140 private:
141 std::string name_;
142 std::string type_;
143 std::string desc_;
144 attr_getter getter_;
145 attr_setter setter_;
146 attr_attr_t attr_;
147};
148
153 public:
154 using cls_attr_getter = std::add_pointer_t<attr_value_t(conf_class_t *)>;
155 using cls_attr_setter = std::add_pointer_t<set_error_t(conf_class_t *,
156 attr_value_t *)>;
167 ClassAttribute(const std::string &name, const std::string &type,
168 const std::string &desc, cls_attr_getter getter,
169 cls_attr_setter setter, attr_attr_t attr)
170 : name_(name), type_(type), desc_(desc), getter_(getter),
171 setter_(setter), attr_(attr) {}
172
173 virtual const std::string &name() const {
174 return name_;
175 }
176
177 virtual const std::string &type() const {
178 return type_;
179 }
180
181 virtual const std::string &desc() const {
182 return desc_;
183 }
184
185 virtual cls_attr_getter getter() const {
186 return getter_;
187 }
188
189 virtual cls_attr_setter setter() const {
190 return setter_;
191 }
192
193 virtual attr_attr_t attr() const {
194 return attr_;
195 }
196
197 private:
198 std::string name_;
199 std::string type_;
200 std::string desc_;
201 cls_attr_getter getter_;
202 cls_attr_setter setter_;
203 attr_attr_t attr_;
204};
205
206} // namespace simics
207
208#endif
Represents a Simics attribute.
Definition: attribute.h:79
virtual attr_setter setter() const
Definition: attribute.h:132
virtual const std::string & name() const
Definition: attribute.h:116
virtual const std::string & desc() const
Definition: attribute.h:124
virtual attr_getter getter() const
Definition: attribute.h:128
Attribute(Attribute &&)=default
Attribute(const std::string &name, const std::string &type, const std::string &desc, AttributeAccessor< CLASS, MEMBER, m > ref, attr_attr_t attr=Sim_Attr_Optional)
Definition: attribute.h:107
virtual ~Attribute()=default
virtual attr_attr_t attr() const
Definition: attribute.h:136
virtual const std::string & type() const
Definition: attribute.h:120
Attribute(const std::string &name, const std::string &type, const std::string &desc, attr_getter getter, attr_setter setter, attr_attr_t attr)
Definition: attribute.h:92
Attribute(const std::string &name, const std::string &type, const std::string &desc, attr_getter getter, attr_setter setter)
Definition: attribute.h:98
Represents a Simics class attribute.
Definition: attribute.h:152
virtual cls_attr_setter setter() const
Definition: attribute.h:189
virtual const std::string & name() const
Definition: attribute.h:173
ClassAttribute(const std::string &name, const std::string &type, const std::string &desc, cls_attr_getter getter, cls_attr_setter setter, attr_attr_t attr)
Definition: attribute.h:167
std::add_pointer_t< set_error_t(conf_class_t *, attr_value_t *)> cls_attr_setter
Definition: attribute.h:156
virtual const std::string & desc() const
Definition: attribute.h:181
virtual const std::string & type() const
Definition: attribute.h:177
std::add_pointer_t< attr_value_t(conf_class_t *)> cls_attr_getter
Definition: attribute.h:154
virtual attr_attr_t attr() const
Definition: attribute.h:193
virtual cls_attr_getter getter() const
Definition: attribute.h:185
Definition: after-bank.h:33
std::add_pointer_t< attr_value_t(conf_object_t *)> attr_getter
Definition: attribute.h:53
std::add_pointer_t< set_error_t(conf_object_t *, attr_value_t *)> attr_setter
Definition: attribute.h:55
A container of get and set callbacks for a class member variable.
Definition: attribute.h:61
attr_setter setter
Definition: attribute.h:72
attr_getter getter
Definition: attribute.h:71
AttributeAccessor()
Definition: attribute.h:65