NSVD Reader  0.0.1
normalized_visitor.hpp
Go to the documentation of this file.
1 
63 /*
64  * These codes are licensed under CC0.
65  * http://creativecommons.org/publicdomain/zero/1.0/
66  */
67 
68 #ifndef __NODAMUSHI_SVD_NORMALIZED_VISITOR_HPP__
69 #define __NODAMUSHI_SVD_NORMALIZED_VISITOR_HPP__
70 
71 
72 # include <type_traits>
73 # include <cassert>
74 # include <memory>
76 
77 namespace nodamushi{
78 namespace svd{
79 namespace normalized{
80 
82 # define NORM_VISITOR_INIT \
83  VISITOR_INIT \
84  template<typename T> \
85  static void accept(T& t){ \
86  using namespace ::nodamushi::visitor; \
87  constexpr ::nodamushi::visitor::_visitor_member_type_ __member_type__= \
88  __NODAMUSHI_VISIT_ENUM__(VISITOR_MEMBER,mt); \
89  static_assert(is_static<T,__member_type__>::value,"static visitor"); \
90  ::nodamushi::svd::normalized::normvisitor<this_t>::visit(t); \
91  } \
92  template<typename T> \
93  static void accept(std::shared_ptr<T> t){ \
94  using namespace ::nodamushi::visitor; \
95  constexpr ::nodamushi::visitor::_visitor_member_type_ __member_type__= \
96  __NODAMUSHI_VISIT_ENUM__(VISITOR_MEMBER,mt); \
97  static_assert(is_static<T,__member_type__>::value,"static visitor");\
98  ::nodamushi::svd::normalized::normvisitor<this_t>::visit(*t); \
99  } \
100  template<typename T> \
101  static void accept(T& t,this_t& o){ \
102  using namespace ::nodamushi::visitor; \
103  constexpr ::nodamushi::visitor::_visitor_member_type_ __member_type__= \
104  __NODAMUSHI_VISIT_ENUM__(VISITOR_MEMBER,mt); \
105  static_assert(!is_static<T,__member_type__>::value,"instance visitor"); \
106  ::nodamushi::svd::normalized::normvisitor<this_t>::visit(t,o);} \
107  template<typename T> \
108  static void accept(std::shared_ptr<T> t,this_t& o){ \
109  using namespace ::nodamushi::visitor; \
110  constexpr ::nodamushi::visitor::_visitor_member_type_ __member_type__= \
111  __NODAMUSHI_VISIT_ENUM__(VISITOR_MEMBER,mt); \
112  static_assert(!is_static<T,__member_type__>::value,"instance visitor"); \
113  ::nodamushi::svd::normalized::normvisitor<this_t>::visit(*t,o);} \
114  template<typename T> \
115  static void accept(this_t& o,T& t){\
116  using namespace ::nodamushi::visitor; \
117  constexpr ::nodamushi::visitor::_visitor_member_type_ __member_type__= \
118  __NODAMUSHI_VISIT_ENUM__(VISITOR_MEMBER,mt); \
119  static_assert(!is_static<T,__member_type__>::value,"instance visitor"); \
120  ::nodamushi::svd::normalized::normvisitor<this_t>::visit(t,o);} \
121  template<typename T> \
122  static void accept(this_t& o,std::shared_ptr<T> t){ \
123  using namespace ::nodamushi::visitor; \
124  constexpr ::nodamushi::visitor::_visitor_member_type_ __member_type__= \
125  __NODAMUSHI_VISIT_ENUM__(VISITOR_MEMBER,mt); \
126  static_assert(!is_static<T,__member_type__>::value,"instance visitor"); \
127  ::nodamushi::svd::normalized::normvisitor<this_t>::visit(*t,o);} \
128 
129 
131 # define NORM_Visit_Device(v,...) template<typename S> \
132  VISITOR_MEMBER result visit(::nodamushi::svd::normalized::Device<S>__VA_ARGS__& v)
133 # define NORM_PostVisit_Device(v,...) template<typename S> \
135  VISITOR_MEMBER result postVisit(::nodamushi::svd::normalized::Device<S>__VA_ARGS__& v)
136 
138 # define NORM_Visit_Peripheral(v,...) template<typename S> \
139  VISITOR_MEMBER result visit(::nodamushi::svd::normalized::Peripheral<S>__VA_ARGS__& v)
140 # define NORM_PostVisit_Peripheral(v,...) template<typename S> \
142  VISITOR_MEMBER result postVisit(::nodamushi::svd::normalized::Peripheral<S>__VA_ARGS__& v)
143 
144 # define NORM_Visit_Interrupt(v,...) template<typename S> \
145  VISITOR_MEMBER result visit(::nodamushi::svd::normalized::Interrupt<S>__VA_ARGS__& v)
146 
147 # define NORM_Visit_AddressBlock(v,...) \
148  VISITOR_MEMBER result visit(::nodamushi::svd::normalized::AddressBlock __VA_ARGS__& v)
149 
150 
151 # define NORM_Visit_Cluster(v,...) template<typename S> \
152  VISITOR_MEMBER result visit(::nodamushi::svd::normalized::Cluster<S>__VA_ARGS__& v)
153 # define NORM_PostVisit_Cluster(v,...) template<typename S> \
154  VISITOR_MEMBER result postVisit(::nodamushi::svd::normalized::Cluster<S> __VA_ARGS__& v)
155 
156 # define NORM_Visit_Register(v,...) template<typename S> \
157  VISITOR_MEMBER result visit(::nodamushi::svd::normalized::Register<S> __VA_ARGS__ & v)
158 # define NORM_PostVisit_Register(v,...) template<typename S> \
159  VISITOR_MEMBER result postVisit(__VA_ARGS__ ::nodamushi::svd::normalized::Register<S>& v)
160 
161 # define NORM_Visit_Field(v,...) template<typename S> \
162  VISITOR_MEMBER result visit(__VA_ARGS__ ::nodamushi::svd::normalized::Field<S>& v)
163 # define NORM_PostVisit_Field(v,...) template<typename S> \
164  VISITOR_MEMBER result postVisit(::nodamushi::svd::normalized::Field<S> __VA_ARGS__ & v)
165 
166 # define NORM_Visit_EnumeratedValues(v,...) template<typename S> \
167  VISITOR_MEMBER result visit(__VA_ARGS__::nodamushi::svd::normalized::Enumeration<S>& v)
168 # define NORM_PostVisit_EnumeratedValues(v,...) template<typename S> \
169  VISITOR_MEMBER result postVisit(__VA_ARGS__ ::nodamushi::svd::normalized::Enumeration<S>& v)
170 # define NORM_Visit_EnumeratedValue(v,...) template<typename S> \
171  VISITOR_MEMBER result visit(__VA_ARGS__ ::nodamushi::svd::normalized::EnumeratedValue<S>& v)
172 
173 
174 template<typename CONTROLLER,typename VISITOR,typename T>
175 struct handleVisit{
176  template<typename T2,typename V>
178  return ::nodamushi::visitor::result::SKIP;}
179 };
180 
181 
182 template<typename VISITOR>
184 {
186 
189 
190  template<typename T>
191  static result visit(T& t)
192  {
193  return ::nodamushi::visitor::apply<this_t,VISITOR>(t) == result::BREAK?
194  result::BREAK : result::CONTINUE;
195  }
196  template<typename T>
197  static result visit(T& t,VISITOR& v)
198  {
199  return ::nodamushi::visitor::apply<this_t,VISITOR>(t,v) == result::BREAK?
200  result::BREAK : result::CONTINUE;
201  }
202 
203  template<typename T>
204  static result handleVisit(T& t)
205  {
206  using T2 =typename std::remove_const<T>::type;
207  __dummy_visitor_ dummy;
209  return ret;
210  }
211 
212  template<typename T>
213  static result handleVisit(T& t,VISITOR& v)
214  {
215  using T2 =typename std::remove_const<T>::type;
216  return ::nodamushi::svd::normalized::handleVisit<this_t,VISITOR,T2>::template visit<T>(t,v);
217  }
218 
219  template<typename T>
220  static result apply(T& t,VISITOR& v)
221  {
222  return ::nodamushi::visitor::applyController<this_t,VISITOR>(t,v);
223  }
224 
225  template<typename T>
226  static result apply(T& t,__dummy_visitor_& v)
227  {
228  return ::nodamushi::visitor::applyController<this_t,VISITOR>(t);
229  }
230 };
231 
232 
233 
234 
235 #define __NX_NORM_HANDLE_VISIT(type) \
236  template<typename CONTROLLER, \
237  typename VISITOR, \
238  class A> \
239  struct handleVisit<CONTROLLER,VISITOR,type<A>>{ \
240  template<typename T,typename V> \
241  static ::nodamushi::visitor::result visit(T& t,V&v) \
242 
243 
244 // ignore constant
245 template<typename T1,typename T2>struct is_same
246 {
247  static constexpr bool value =
248  std::is_same<
249  typename std::remove_const<T1>::type,
250  typename std::remove_const<T2>::type>::value;
251 };
252 
253 
254 
255 
256 
257 }}}// end namespace nodamushi::svd::normalized
258 #endif // __NODAMUSHI_SVD_NORMALIZED_VISITOR_HPP__
static result handleVisit(T &t, VISITOR &v)
::nodamushi::visitor::result visit(T2 &t, V &v)
static result visit(T &t, VISITOR &v)
static result apply(T &t, __dummy_visitor_ &v)
static result apply(T &t, VISITOR &v)
This class reperesents SVD(xml) element / attribute.
Definition: value.hpp:53