9 #ifndef __NODAMUSHI_SVD_VALUE_VALUE_SETTER_HPP__ 10 #define __NODAMUSHI_SVD_VALUE_VALUE_SETTER_HPP__ 12 # include <type_traits> 27 template<
typename DST,
typename SRC>
36 template<
typename DST,
typename SVD>
38 ->typename std::enable_if<std::is_base_of<svd_node,DST>::value,
bool>::type
43 template<
typename DST,
typename SVD>
45 ->typename std::enable_if<!std::is_base_of<svd_node,DST>::value,
bool>::type
50 template<
typename DST,
typename SVD>
56 template<
typename DST,
typename SVD>
59 size_t s = dst.size();
68 template<
typename DST,
typename SVD>
74 dst.emplace_back(std::move(tmp));
81 template<
typename DST,
typename PTR,
typename SVD>
93 template<
typename DST,
typename SVD>
108 template<
typename I,
bool UNSIG>
struct irange;
109 template<
typename I>
struct irange<I,true>
112 static constexpr I MAX = limits::max();
113 static bool in_range(
unsigned long long v){
return v <= MAX;}
115 template<
typename I>
struct irange<I,false>
118 static constexpr I MAX = limits::max();
119 static constexpr I MIN = limits::min();
120 static bool in_range(
long long v){
return MIN <= v && v <= MAX;}
126 constexpr
bool unsig = std::is_unsigned<I>::value;
128 using LL = std::conditional_t<unsig, unsigned long long, long long>;
129 char *str_end=
nullptr;
130 LL v = static_cast<LL>(std::strtoll(
132 (length > 2 && *ptr ==
'0' &&
133 (ptr[1] ==
'x' || ptr[1] ==
'X'))? 16:10));
134 size_t use = str_end - ptr;
135 if(!ir::in_range(v) || use != length){
138 dst = static_cast<I>(v);
147 # if __cplusplus >= 201703 148 template<
typename I>
bool cast_integer(
const std::string_view& s,I& dst)
156 template<
typename DST>
158 ->
typename std::enable_if<
160 &&!std::is_same<DST,bool>::value
168 template<
typename DST>
170 ->
typename std::enable_if<enum_helper<DST>::HAS_HELPER ,
bool>::type
178 template<
typename DST>
180 ->
typename std::enable_if<value_setter_helper<DST>::value ,
bool>::type
182 bool b =value_setter_helper<DST>::set(src,dst);
187 template<
typename DST>
190 if(src ==
"true" || src ==
"1"){
193 }
else if(src ==
"false" || src ==
"0"){
200 # if __cplusplus >= 201703 203 template<
typename DST>
205 ->
typename std::enable_if<
207 &&!std::is_same<DST,bool>::value
216 template<
typename DST>
218 ->
typename std::enable_if<enum_helper<DST>::HAS_HELPER ,
bool>::type
221 bool b =enum_helper<DST>::get(src,dst);
226 template<
typename DST>
228 ->
typename std::enable_if<value_setter_helper<DST>::value ,
bool>::type
230 bool b =value_setter_helper<DST>::set(src,dst);
234 template<
typename DST>
241 }
else if(src ==
"false"){
258 static bool set(T& dst,
const T& src){
262 static bool move(T& dst,T&& src){dst =std::move(src);
return true;}
267 static bool set(DST& dst,
const std::string& src)
269 return details::value_setter_set<DST>(dst,src);
272 static auto move(DST& dst, std::string&& src)
274 return details::value_setter_set<DST>(dst,src);
280 static bool set(std::string& dst,
const std::string& src)
282 dst = src;
return true;
285 static bool move(std::string& dst,std::string&& src)
287 dst = std::move(src);
return true;
293 # if __cplusplus >= 201703 295 template<
typename DST>
struct value_setter<DST,
std::string_view>
297 static bool set(DST& dst,
const std::string_view& src)
299 return details::value_setter_set<DST>(dst,src);
302 static auto move(DST& dst, std::string_view&& src)
304 return details::value_setter_set<DST>(dst,src);
308 template<>
struct value_setter<
std::string_view,std::string_view>
310 static bool set(std::string_view& dst,
const std::string_view& src)
312 dst = src;
return true;
314 static bool move(std::string_view& dst, std::string_view&& src)
316 dst = src;
return true;
319 template<>
struct value_setter<
std::string,std::string_view>
321 static bool set(std::string& dst,
const std::string_view& src)
323 dst = std::string(src);
return true;
325 static bool move(std::string& dst,std::string_view&& src)
327 dst = std::string(src);
return true;
337 #endif // __NODAMUSHI_SVD_VALUE_VALUE_SETTER_HPP__ boxvec. vector<pointer<X>>
static bool move(std::string &dst, std::string &&src)
auto _value_try_set(DST &dst, SVD &src) -> typename std::enable_if< std::is_base_of< svd_node, DST >::value, bool >::type
box.std::unique_ptr wrapper
static bool in_range(unsigned long long v)
bool cast_integer(const char *const ptr, size_t length, I &dst)
static auto move(DST &dst, std::string &&src)
static bool set(T &dst, const T &src)
bool create(SVD &svd, AddressBlock &d)
build AddressBlock
bool apply_value_setter(DST &dst, const SRC &src)
void push_back(const T &t)
std::numeric_limits< I > limits
create fucntion decralation
bool value_try_set(DST &dst, SVD &src)
std::numeric_limits< I > limits
static bool set(std::string &dst, const std::string &src)
svd element marker interface
static bool set(DST &dst, const std::string &src)
auto value_setter_set(DST &dst, const std::string &src) -> typename std::enable_if< std::is_integral< DST >::value &&!enum_helper< DST >::HAS_HELPER &&!std::is_same< DST, bool >::value, bool >::type
static bool move(T &dst, T &&src)
static bool in_range(long long v)