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#if defined _MSVC_LANG
20#if _MSVC_LANG < 201402L
21#error "The C++ compiler version is not supported (C++ API v2 requires C++14)"
22#endif
23#elif defined __cplusplus
24#if __cplusplus < 201402L
25#error "The C++ compiler version is not supported (C++ API v2 requires C++14)"
26#endif
27#endif
28
29#include <simics/base/conf-object.h> // attr_attr_t
30#include <string>
31#include <type_traits> // add_pointer_t
32
36
40#define GET_MACRO(_1, _2, NAME, ...) NAME
41
45#define IMPL(str) str
46
51#define ATTR_GETTER(...) \
52 IMPL(GET_MACRO(__VA_ARGS__, _G_DUAL, _G_SINGLE)(__VA_ARGS__))
53#define ATTR_SETTER(...) \
54 IMPL(GET_MACRO(__VA_ARGS__, _S_DUAL, _S_SINGLE)(__VA_ARGS__))
55#define ATTR_CLS_VAR(CLASS, VAR) \
56 simics::AttributeAccessor<CLASS, decltype(&CLASS::VAR), &CLASS::VAR>()
58#define ATTR_TYPE_STR(VAR) simics::attr_type_str<decltype(VAR)>()
59
60namespace simics {
61
62using attr_getter = std::add_pointer_t<attr_value_t(conf_object_t *)>;
63using attr_setter = std::add_pointer_t<set_error_t(conf_object_t *,
64 attr_value_t *)>;
65
69template <typename CLASS, typename MEMBER, MEMBER m>
71 static_assert(std::is_member_object_pointer<MEMBER>::value,
72 "type MEMBER is not a member object pointer type");
73
75 : getter(detail::attr_getter_helper_dual<
76 MEMBER, CLASS>::template f<m>),
77 setter(detail::attr_setter_helper_dual<
78 MEMBER, CLASS>::template f<m>) {}
79
82};
83
88class Attribute {
89 public:
101 Attribute(const std::string &name, const std::string &type,
102 const std::string &desc, attr_getter getter, attr_setter setter,
103 attr_attr_t attr)
104 : name_(name), type_(type), desc_(desc), getter_(getter),
105 setter_(setter), attr_(attr) {}
106
107 Attribute(const std::string &name, const std::string &type,
108 const std::string &desc, attr_getter getter, attr_setter setter)
110 (getter && setter) ? Sim_Attr_Optional : Sim_Attr_Pseudo) {}
111
115 template <typename CLASS, typename MEMBER, MEMBER m>
116 Attribute(const std::string &name, const std::string &type,
117 const std::string &desc, AttributeAccessor<CLASS, MEMBER, m> ref,
118 attr_attr_t attr = Sim_Attr_Optional)
119 : Attribute(name, type, desc, ref.getter, ref.setter, attr) {}
120
121 virtual ~Attribute() = default;
122 // destructor definition implicit deprecate move, force it here
123 Attribute(Attribute&&) = default;
124
125 virtual const std::string &name() const {
126 return name_;
127 }
128
129 virtual const std::string &type() const {
130 return type_;
131 }
132
133 virtual const std::string &desc() const {
134 return desc_;
135 }
136
137 virtual attr_getter getter() const {
138 return getter_;
139 }
140
141 virtual attr_setter setter() const {
142 return setter_;
143 }
144
145 virtual attr_attr_t attr() const {
146 return attr_;
147 }
148
149 private:
150 std::string name_;
151 std::string type_;
152 std::string desc_;
153 attr_getter getter_;
154 attr_setter setter_;
155 attr_attr_t attr_;
156};
157
158} // namespace simics
159
160#endif
struct conf_object conf_object_t
Definition: bank-issue-callbacks-interface.h:23
Represents a Simics attribute.
Definition: attribute.h:88
virtual attr_setter setter() const
Definition: attribute.h:141
virtual const std::string & name() const
Definition: attribute.h:125
virtual const std::string & desc() const
Definition: attribute.h:133
virtual attr_getter getter() const
Definition: attribute.h:137
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:116
virtual ~Attribute()=default
virtual attr_attr_t attr() const
Definition: attribute.h:145
virtual const std::string & type() const
Definition: attribute.h:129
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:101
Attribute(const std::string &name, const std::string &type, const std::string &desc, attr_getter getter, attr_setter setter)
Definition: attribute.h:107
Definition: attr-value.h:23
std::add_pointer_t< attr_value_t(conf_object_t *)> attr_getter
Definition: attribute.h:62
std::add_pointer_t< set_error_t(conf_object_t *, attr_value_t *)> attr_setter
Definition: attribute.h:64
A container of get and set callbacks for a class member variable.
Definition: attribute.h:70
attr_setter setter
Definition: attribute.h:81
attr_getter getter
Definition: attribute.h:80
AttributeAccessor()
Definition: attribute.h:74