9 #ifndef __NODAMUSHI_SVD_BITRANGE_HPP__ 10 #define __NODAMUSHI_SVD_BITRANGE_HPP__ 35 return lsb == b.lsb &&
msb == b.msb;
38 return lsb != b.lsb ||
msb != b.msb;
46 template<
typename STR>
bool set(
const STR& src)
49 size_t l = src.length();
50 if(l <5||src[0] !=
'[' ||src[l-1] !=
']'){
return false;}
52 size_t msb_b=1,msb_e,colon,lsb_b,lsb_e;
53 while(is_space(src[msb_b]))
57 while(!is_space(src[msb_e]) && src[msb_e] !=
':' )
60 while(src[colon] !=
':' )
63 while(is_space(src[lsb_b]))
66 while(!is_space(src[lsb_e]) && src[lsb_e] !=
']' )
70 const char* ptr = src.data();
71 if(!to_int(ptr + msb_b, ptr + msb_e,
msb)){
74 if(!to_int(ptr + lsb_b, ptr + lsb_e,
lsb)){
84 static constexpr
bool is_space(
char c)
86 return ' ' == c ||
'\t' == c ||
'\r' == c ||
'\n' == c;
88 static constexpr
bool to_int(
const char* begin,
const char*
const end,uint32_t& i)
94 if(
'0' <= c && c <=
'9')
95 i = i * 10 + (c -
'0');
110 # if __cplusplus >= 201703 111 static bool set(std::string_view src,
bitRange& dst){
return dst.
set(src);}
125 o <<
'['<<r.
msb <<
':' <<r.
lsb<<
']';
130 #endif // __NODAMUSHI_SVD_BITRANGE_HPP__
ostream & operator<<(std::ostream &os, const ::nodamushi::svd::Access &value)
<field>.<bitRange> element
uint32_t msb
msb: the bit position of the most significant bit within the register.
bool operator==(const bitRange &b) const noexcept
bool operator!=(const bitRange &b) const noexcept
uint32_t lsb
lsb: the bit position of the least significant bit within the register.
static bool set(const std::string &src, bitRange &dst)
This class reperesents SVD(xml) element / attribute.
bitRange(uint32_t l, uint32_t m)