16#ifndef SIMICS_DETAIL_ATTRIBUTE_SETTER_H
17#define SIMICS_DETAIL_ATTRIBUTE_SETTER_H
19#include <simics/base/log.h>
21#include "../conf-object.h"
22#include "../attribute-traits.h"
41#define _S_SINGLE(func_ptr) \
42 simics::detail::attr_setter_helper<decltype(&func_ptr)>::\
44#define _S_DUAL(cls, m) \
45 simics::detail::attr_setter_helper_dual<decltype(&cls::m), cls>::\
49template <
typename O,
typename T>
52 static_assert(
sizeof(T) == -1,
53 "Pass class member pointer as two arguments to the MACRO:"
57template <
typename O,
typename T>
60 static_assert(
sizeof(T) == -1,
61 "Pass class member pointer as two arguments to the MACRO:"
65template <
typename O,
typename T,
typename C>
67 static_assert(std::is_base_of<O, C>::value,
"C must be derived from O");
68 template <
void (O::*F)(T)>
70 O *o =
static_cast<O*
>(from_obj<C>(obj));
74 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
75 return Sim_Set_Interface_Not_Found;
77 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
78 return Sim_Set_Illegal_Type;
80 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
81 return Sim_Set_Not_Writable;
82 }
catch (
const std::exception &e) {
83 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
84 return Sim_Set_Illegal_Value;
90template <
typename O,
typename T,
typename C>
92 template <
void (O::*F)(T&)>
94 C *o = from_obj<C>(obj);
96 T tval = attr_to_std<T>(*val);
99 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
100 return Sim_Set_Interface_Not_Found;
102 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
103 return Sim_Set_Illegal_Type;
105 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
106 return Sim_Set_Not_Writable;
107 }
catch (
const std::exception &e) {
108 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
109 return Sim_Set_Illegal_Value;
116template <
typename O,
typename T>
119 static_assert(
sizeof(T) == -1,
120 "Pass class member pointer as two arguments to the MACRO:"
124template <
typename O,
typename T,
typename C>
128 template <T O::*R,
typename T1 = T>
static
129 typename std::enable_if<std::is_base_of<ConnectBase, T1>::value,
132 C *o = from_obj<C>(obj);
133 bool result = (o->*R).set(attr_to_std<ConfObjectRef>(*val));
134 if (result ==
false) {
135 return Sim_Set_Interface_Not_Found;
140 template <T O::*R,
typename T1 = T>
static
141 typename std::enable_if<!std::is_base_of<ConnectBase, T1>::value,
144 C *o = from_obj<C>(obj);
146 o->*R = attr_to_std<T1>(*val);
148 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
149 return Sim_Set_Interface_Not_Found;
151 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
152 return Sim_Set_Illegal_Type;
154 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
155 return Sim_Set_Not_Writable;
156 }
catch (
const std::exception &e) {
157 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
158 return Sim_Set_Illegal_Value;
165template <
typename O,
typename T>
167 template <
void (*F)(O&, T&)>
169 O *o = from_obj<O>(obj);
173 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
174 return Sim_Set_Interface_Not_Found;
176 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
177 return Sim_Set_Illegal_Type;
179 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
180 return Sim_Set_Not_Writable;
181 }
catch (
const std::exception &e) {
182 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
183 return Sim_Set_Illegal_Value;
190template <
typename O,
typename T>
192 template <
void (*F)(O&, T)>
194 O *o = from_obj<O>(obj);
198 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
199 return Sim_Set_Interface_Not_Found;
201 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
202 return Sim_Set_Illegal_Type;
204 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
205 return Sim_Set_Not_Writable;
206 }
catch (
const std::exception &e) {
207 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
208 return Sim_Set_Illegal_Value;
214template <
typename O,
typename T>
216 template <T& (*F)(O&)>
218 O *o = from_obj<O>(obj);
220 F(*o) = attr_to_std<T>(*val);
222 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
223 return Sim_Set_Interface_Not_Found;
225 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
226 return Sim_Set_Illegal_Type;
228 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
229 return Sim_Set_Not_Writable;
230 }
catch (
const std::exception &e) {
231 SIM_LOG_ERROR(obj, 0,
"%s", e.
what());
232 return Sim_Set_Illegal_Value;
struct conf_object conf_object_t
Definition: bank-issue-callbacks-interface.h:23
Definition: attribute-exceptions.h:38
Definition: attribute-exceptions.h:25
const char * what() const noexcept override
Definition: attribute-exceptions.h:30
Definition: attribute-exceptions.h:64
Definition: attr-value.h:23
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:142
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:217
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:168
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:193
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:131
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:143
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:93
static set_error_t f(conf_object_t *obj, attr_value_t *val)
Definition: attribute-setter.h:69
Definition: attribute-setter.h:28
Definition: attribute-setter.h:27