10 #ifndef __NODAMUSHI_SVD_NORMALIZED_NORMALIZER_HPP__ 11 #define __NODAMUSHI_SVD_NORMALIZED_NORMALIZER_HPP__ 15 # include <type_traits> 18 # include <unordered_set> 40 namespace normalized {
47 static constexpr
const T1 *
of(
const T2 *t) {
return t; }
51 static constexpr
const T1 *
of(
const T2 *t) {
return nullptr; }
55 template <
typename T1,
typename T2>
58 static constexpr
const T1 *
value(
const T2 *ptr)
64 template<
typename STRREF,
typename STR,
typename V>
67 using names = std::unordered_set<::nodamushi::ref<std::string>,
79 using SD = const ::nodamushi::svd::Device<STR,V>;
80 using SP = const ::nodamushi::svd::Peripheral<STR>;
81 using SC = const ::nodamushi::svd::Cluster<STR>;
82 using SR = const ::nodamushi::svd::Register<STR>;
83 using SF = const ::nodamushi::svd::Field<STR>;
84 using SE = const ::nodamushi::svd::Enumeration<STR>;
88 template<
typename SVD>
struct base 99 base(
const SVD& s,
const std::string& n):
118 template <
typename ChildType,
typename Parent,
typename SVD,
typename PTR,
typename ERROR>
120 Parent &
p,
const SVD &s,
127 auto base_info =dimh.get_base_info();
128 for(
size_t i = 0;i < dimh.size;i++){
129 std::string ni = dimh.name(i);
132 ChildType::print_name(
e);
133 e <<
" " << ni <<
" already defined in " <<
p;
136 size_t size = v.
size();
140 n.emplace(v[size].name);
145 template <
typename ChildType,
typename Parent,
typename PTR,
typename ERROR>
147 Parent &
p,
const ChildType &
c,
152 if (n.count(
c.
name)){
154 ChildType::print_name(
e);
155 e<<
" " <<
c.
name <<
" already defined in " <<
p;
169 template <
typename ChildType,
typename Parent,
typename SVDChildren,
typename PTR,
typename ERROR>
174 for(
const auto& svd:vec){
175 emplace_child<ChildType>(
p, svd, dst,g, n,
e);
197 e(
const e &) =
default;
199 template <
typename ERROR>
205 template <
typename T>
225 template <
typename ERROR>
237 f(
const f &) =
default;
239 template<
typename ERROR>
250 template <
typename T>
273 template<
typename P,
typename ERROR>
284 const auto& v = s.
fields.get().field.get();
293 r(
const r &) =
default;
295 template <
typename ERROR>
304 for (
const auto &
c : df.
fields)
311 template <
typename T>
338 template<
typename P,
typename ERROR>
347 for(
const auto& _rc : s.
registers.registers){
348 if(_rc.is_register())
358 for(
const auto& _rc:s.
registers.registers){
359 if(_rc.is_register()){
360 auto& ss = _rc.get_register();
363 auto& ss = _rc.get_cluster();
370 c(
const c &) =
default;
373 template <
typename ERROR>
399 template <
typename T>
430 template<
typename ERROR>
440 for(
const auto& _rc : s.
registers.get().registers){
441 if(_rc.is_register())
451 for(
const auto& _rc:s.
registers.get().registers){
452 if(_rc.is_register()){
453 const auto& ss = _rc.get_register();
456 const auto& ss = _rc.get_cluster();
467 template <
typename ERROR>
507 template<
typename ERROR>
511 if(s.peripherals && s.peripherals.get().peripheral)
512 for(
const auto&
p:s.peripherals.get().peripheral.get())
516 emplace_children<p>(*
this,s.peripherals.get().peripheral.get(),
peripherals,
e);
522 template <
typename ERROR>
555 template<
typename T1,
typename T2>
579 if(t.parent)
find(name,*t.parent,ret);
595 template<
typename PSTR,
typename T>
598 const T *ret =
nullptr;
599 findp(name[0],t,&ret);
604 template<
typename PSTR,
typename PARENT,
typename T>
606 const PARENT& parent,
const T** ret)
608 const auto s =
p.size();
612 find(
p[0],parent,ret);
616 const r* reg =
nullptr;
617 find(
p[0],parent,®);
625 const f* fe =
nullptr;
633 template<
typename PSTR,
typename T>
635 const d&
d,
const T& t,
const T** ret)
638 const p* peri =
nullptr;
646 const c* clu =
nullptr;
671 template <
typename T,
typename ERROR>
674 if(t.svd.derivedFrom){
675 const auto& dp = *t.svd.derivedFrom;
676 const T *ret =
nullptr;
679 if(!ret)
return false;
681 t.set_derivedFrom(df, unresolved,
e);
685 template <
typename T,
typename ERROR>
688 if(unresolved.empty())
693 auto it = unresolved.begin();
694 while(it != unresolved.end()){
698 it = unresolved.erase(it);
702 }
while (found && unresolved.size() > 0);
703 return unresolved.empty();
706 template <
typename T,
typename ERROR>
715 for (
const auto *
c : v){
729 template <
typename ERROR>
733 ret |= _set_derivedFrom<p>(
d,
err);
734 ret |= _set_derivedFrom<c>(
d,
err);
735 ret |= _set_derivedFrom<r>(
d,
err);
736 ret |= _set_derivedFrom<f>(
d,
err);
737 ret |= _set_derivedFrom<e>(
d,
err);
748 std::stringstream
ss;
802 explicit operator bool()
const {
return ok; }
824 # if __cplusplus >= 201703 825 typename STRREF=std::string_view,
827 typename STRREF=std::string,
829 typename STR,
typename V>
830 static ::nodamushi::svd::normalized::node_ptr<::nodamushi::svd::normalized::Device<STRREF>>
833 namespace norm=::nodamushi::svd::normalized;
834 using D = norm::Device<STRREF>;
835 norm::normalizer<STRREF,STR,V> n(d);
837 auto ptr = norm::make_node_ptr<D>(n.device);
838 ptr->update_parent(ptr);
848 #endif // __NODAMUSHI_SVD_NORMALIZED_NORMALIZER_HPP__ boxvec. vector<pointer<X>>
Normalized enumerationValues element.
normalized peripheral element
static ::nodamushi::svd::normalized::node_ptr<::nodamushi::svd::normalized::Device< STRREF > > normalize(const ::nodamushi::svd::Device< STR, V > &d)
normalize nodamushi::svd::Device.
void set_derivedFrom(const d &, const std::vector< d * > &, ERROR &)
typename dim_info::id_t did_t
dim_info.id type
static void find(string_ref n, const r &s, const f **r)
base(const SVD &s, const std::string &n)
static constexpr const T1 * of(const T2 *t)
void collect_unresolved(std::vector< f * > &v)
static void _find(string_ref name, const LIST &list, const T **ret)
base(const SVD &s, const std::string &n, const dim_info &di)
indicate that the derivedFrom property is resolved
value< path< std::string >,ATTR > derivedFrom
derivedFrom attribute
void collect_unresolved(std::vector< r * > &v)
static void findp(string_ref name, const c &t, const c **ret)
error & operator<<(const e &p)
size_t size() const noexcept
value< Fields< STR >,ELEMENT > fields
<fields>
size_type size() const noexcept
void set_derivedFrom(const f &df, const std::vector< f * > &, ERROR &e)
void collect_unresolved(std::vector< c * > &v)
dim_helper< NODE > make_dim_helper(const NODE &n)
error & operator<<(const T &t)
static constexpr const T1 * of(const T2 *t)
const std::string & string_ref
void set_derivedFrom(const e &df, const std::vector< e * > &, ERROR &e)
void set_derivedFrom(const p &df, std::vector< p * > &, ERROR &e)
value< std::vector< Enumeration< STR > >,ELEMENT > enumeratedValues
<enumeration> minOccurs=0,maxOccurs=2
static void find(string_ref n, const c &s, const r **r)
boxvec< e > enumeratedValues
<enumeratedValues> element. iterable
id_t id
dimension group id.this value is unique in the parent.
static path< substring > get_path(const c &c)
static bool set_derivedFrom(d &d, T &t, std::vector< T * > &unresolved, ERROR &e)
path< STR > subpath(size_t from, size_t end=0) const
iterator emplace(const_iterator position, ARGS &&... args)
e(const f &r, const SE &s)
static void emplace_child(Parent &p, const SVD &s, boxvec< ChildType, PTR > &v, did_t g, names &n, ERROR &e)
enumerate
static bool set_derivedFrom_all(d &d, std::vector< T * > &unresolved, ERROR &e)
container class decralation
static const T * find_derivedFrom_s(const ::nodamushi::svd::path< PSTR > &name, const T &t)
size_t get_dim_count(const NODE &n)
get dim size. when dim is empty return 1.
static void find(string_ref n, const f &s, const e **r)
static void find_derivedFrom_m(const ::nodamushi::svd::path< PSTR > &path, const d &d, const T &t, const T **ret)
void collect_unresolved(std::vector< T * > &v)
static constexpr const T1 * value(const T2 *ptr)
f(const r &r, const SF &s, const std::string &n, const dim_info &i, ERROR &e)
std::string get_error() const
void collect_unresolved(std::vector< T * > &v)
static path< substring > get_path(const e &e)
static void find(string_ref n, const p &s, const r **r)
static void find(string_ref n, const p &s, const c **r)
void collect_unresolved(std::vector< T * > &v)
static path< substring > get_path(const p &p)
static bool _set_derivedFrom(d &d, ERROR &err)
static bool set_derivedFrom(d &d, ERROR &err)
This class reperesents SVD(xml) element / attribute.
dim,dimIndex,array information object.
static void find(string_ref name, const T1 &t, const T2 **ret)
void collect_unresolved(std::vector< e * > &v)
static void find_derivedFrom_r(const ::nodamushi::svd::path< PSTR > &p, const PARENT &parent, const T **ret)
static void print_name(T &o)
error & operator<<(const r &p)
void collect_unresolved(std::vector< p * > &v)
static void print_name(T &o)
static void findp(string_ref name, const P &t, const P **ret)
normalized peripheral element
c(const P &r, const SC &s, const std::string &n, const dim_info &i, ERROR &e)
std::unordered_set<::nodamushi::ref< std::string >, ::nodamushi::refhash< std::string > > names
Registers< STR > registers
<register> or <cluster>
static void print_name(T &o)
value< Registers< STR >,ELEMENT > registers
static void findp(string_ref name, const r &t, const r **ret)
static path< substring > get_path(const r &r)
names,dispalyNames->name0,displayName1
void collect_unresolved(std::vector< T * > &v)
static path< substring > get_path(const f &f)
static void print_name(T &o)
r(const P &r, const SR &s, const std::string &n, const dim_info &i, ERROR &e)
void set_derivedFrom(const r &df, const std::vector< r * > &, ERROR &e)
static void print_name(T &o)
static did_t copy_child(Parent &p, const ChildType &c, boxvec< ChildType, PTR > &v, did_t g, names &n, ERROR &e)
void collect_unresolved(std::vector< T * > &v)
static void find(string_ref n, const d &s, const p **r)
void set_derivedFrom(const c &df, std::vector< c * > &unresolved, ERROR &e)
static did_t emplace_children(Parent &p, const SVDChildren &vec, boxvec< ChildType, PTR > &dst, ERROR &e)
error & operator<<(const d &)
reference hash (pointer hasn)
normalized <enumeratedValues> element. iterable
static void find(string_ref n, const c &s, const c **r)
p(const d &r, const SP &s, const std::string &n, const dim_info &i, ERROR &e)
void emplace_back(ARGS &&... args)