16#ifndef SIMICS_DETAIL_ATTRIBUTE_SETTER_H
17#define SIMICS_DETAIL_ATTRIBUTE_SETTER_H
19#include <simics/base/log.h>
43#define _S_SINGLE(func_ptr) \
44 simics::detail::attr_setter_helper<decltype(&func_ptr)>::\
46#define _S_DUAL(cls, m) \
47 simics::detail::attr_setter_helper_dual<decltype(&cls::m), cls>::\
51 SIM_attribute_error(e.what());
53 return Sim_Set_Interface_Not_Found;
55 return Sim_Set_Illegal_Type;
57 return Sim_Set_Not_Writable;
59 return Sim_Set_Illegal_Value;
64template <
typename O,
typename T>
67 static_assert(
sizeof(T) == -1,
68 "Pass class member pointer as two arguments to the MACRO:"
72template <
typename O,
typename T>
75 static_assert(
sizeof(T) == -1,
76 "Pass class member pointer as two arguments to the MACRO:"
80template <
typename O,
typename T,
typename C>
82 static_assert(std::is_base_of<O, C>::value,
"C must be derived from O");
83 template <
void (O::*F)(T)>
84 static set_error_t
f(conf_object_t *obj, attr_value_t *val) {
85 O *o =
static_cast<O*
>(from_obj<C>(obj));
88 }
catch (
const std::exception &e) {
95template <
typename O,
typename T,
typename C>
97 template <
void (O::*F)(T&)>
98 static set_error_t
f(conf_object_t *obj, attr_value_t *val) {
99 C *o = from_obj<C>(obj);
101 T tval = attr_to_std<T>(*val);
103 }
catch (
const std::exception &e) {
111template <
typename O,
typename T>
114 static_assert(
sizeof(T) == -1,
115 "Pass class member pointer as two arguments to the MACRO:"
119template <
typename O,
typename T,
typename C>
122 template <T O::*R,
typename T1 = T>
static
123 typename std::enable_if<std::is_base_of<ConnectBase, T1>::value,
125 f(conf_object_t *obj, attr_value_t *val) {
126 C *o = from_obj<C>(obj);
127 if ((o->*R).set(attr_to_std<ConfObjectRef>(*val)) ==
false) {
128 return Sim_Set_Interface_Not_Found;
135 template <T O::*R,
typename T1 = T>
static
136 typename std::enable_if<is_array_of_connectbase<T1>::value,
138 f(conf_object_t *obj, attr_value_t *val) {
139 C *o = from_obj<C>(obj);
140 auto it = (o->*R).begin();
141 for (
unsigned i = 0; it != (o->*R).end(); ++i, ++it) {
142 if (it->set(attr_to_std<ConfObjectRef>(
143 SIM_attr_list_item(*val, i))) ==
false) {
144 return Sim_Set_Interface_Not_Found;
152 template <T O::*R,
typename T1 = T>
static
153 typename std::enable_if<is_container_of_connectbase<T1>::value,
155 f(conf_object_t *obj, attr_value_t *val) {
156 C *o = from_obj<C>(obj);
157 T new_t(SIM_attr_list_size(*val),
typename T::value_type(obj));
158 auto it = new_t.begin();
159 for (
unsigned i = 0; it != new_t.end(); ++i, ++it) {
160 if (it->set(attr_to_std<ConfObjectRef>(
161 SIM_attr_list_item(*val, i))) ==
false) {
162 return Sim_Set_Interface_Not_Found;
165 o->*R = std::move(new_t);
170 template <T O::*R,
typename T1 = T>
static
171 typename std::enable_if<!is_container_of_connectbase<T1>::value
173 && !std::is_base_of<ConnectBase, T1>::value,
175 f(conf_object_t *obj, attr_value_t *val) {
176 C *o = from_obj<C>(obj);
178 o->*R = attr_to_std<T>(*val);
179 }
catch (
const std::exception &e) {
187template <
typename O,
typename T>
189 template <
void (*F)(O&, T&)>
190 static set_error_t
f(conf_object_t *obj, attr_value_t *val) {
191 O *o = from_obj<O>(obj);
194 }
catch (
const std::exception &e) {
202template <
typename O,
typename T>
204 template <
void (*F)(O&, T)>
205 static set_error_t
f(conf_object_t *obj, attr_value_t *val) {
206 O *o = from_obj<O>(obj);
209 }
catch (
const std::exception &e) {
216template <
typename O,
typename T>
218 template <T& (*F)(O&)>
219 static set_error_t
f(conf_object_t *obj, attr_value_t *val) {
220 O *o = from_obj<O>(obj);
222 F(*o) = attr_to_std<T>(*val);
223 }
catch (
const std::exception &e) {
Definition: attribute-exceptions.h:38
Definition: attribute-exceptions.h:25
Definition: attribute-exceptions.h:64
set_error_t handle_exception(const std::exception &e)
Definition: attribute-setter.h:50
Definition: after-bank.h:33
std::enable_if< std::is_enum< T >::value, T >::type attr_to_std(attr_value_t src)
Function transforms Simics attr_value_t to C++ enum type.
Definition: attribute-traits.h:207
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:219
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:190
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:205
static std::enable_if< is_container_of_connectbase< T1 >::value, set_error_t >::type f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:155
static std::enable_if< std::is_base_of< ConnectBase, T1 >::value, set_error_t >::type f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:125
static std::enable_if<!is_container_of_connectbase< T1 >::value &&!is_array_of_connectbase< T1 >::value &&!std::is_base_of< ConnectBase, T1 >::value, set_error_t >::type f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:175
static std::enable_if< is_array_of_connectbase< T1 >::value, set_error_t >::type f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:138
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:98
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:84
Definition: attribute-setter.h:30
Definition: attribute-setter.h:29
Definition: attribute-traits.h:151