AbstractCoupledModel.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /**
  2. * @file artis/kernel/AbstractCoupledModel.hpp
  3. * @author See the AUTHORS file
  4. */
  5. /*
  6. * Copyright (C) 2012-2017 ULCO http://www.univ-littoral.fr
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef __ARTIS_KERNEL_ABSTRACT_COUPLED_MODEL_HPP
  22. #define __ARTIS_KERNEL_ABSTRACT_COUPLED_MODEL_HPP
  23. #include <artis/kernel/AbstractModel.hpp>
  24. #include <artis/kernel/Externals.hpp>
  25. #include <artis/kernel/Internals.hpp>
  26. #include <artis/kernel/States.hpp>
  27. #include <artis/utils/DateTime.hpp>
  28. #include <artis/utils/Trace.hpp>
  29. #include <functional>
  30. #include <vector>
  31. namespace artis { namespace kernel {
  32. template < typename T, typename U, typename V, typename W >
  33. class AbstractCoupledModel : public AbstractModel < U, V >,
  34. public States < T, U, V >,
  35. public Internals < T, U, V >,
  36. public Externals < T, U, V >
  37. {
  38. typedef AbstractModel < U, V > type;
  39. typedef std::map < int, type* > Submodels;
  40. typedef std::map < int,
  41. std::vector < type* > > Setsubmodels;
  42. typedef std::map < int, std::pair < type*,
  43. int > > SubModelInternals;
  44. public:
  45. struct Var
  46. {
  47. unsigned int index;
  48. type* model;
  49. int sub_index;
  50. Var (unsigned int index, type* model, int sub_index) :
  51. index(index), model(model), sub_index(sub_index)
  52. { }
  53. };
  54. AbstractCoupledModel(const type* parent = 0) : type(parent)
  55. {
  56. #ifdef WITH_TRACE
  57. utils::Trace < utils::DoubleTime >::trace()
  58. << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
  59. utils::KERNEL)
  60. << "NEW COUPLED MODEL - "
  61. << typeid(T).name();
  62. utils::Trace < utils::DoubleTime >::trace().flush();
  63. #endif
  64. }
  65. virtual ~AbstractCoupledModel()
  66. {
  67. #ifdef WITH_TRACE
  68. utils::Trace < utils::DoubleTime >::trace()
  69. << utils::TraceElement < utils::DoubleTime >("KERNEL", 0,
  70. utils::KERNEL)
  71. << "DESTRUCTION - "
  72. << AbstractCoupledModel < T, U, V, W >::path(this);
  73. utils::Trace < utils::DoubleTime >::trace().flush();
  74. #endif
  75. }
  76. virtual void after(typename U::type t)
  77. {
  78. #ifdef WITH_TRACE
  79. utils::Trace < utils::DoubleTime >::trace()
  80. << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
  81. utils::KERNEL)
  82. << "AFTER - "
  83. << AbstractCoupledModel < T, U, V, W >::path(this);
  84. utils::Trace < utils::DoubleTime >::trace().flush();
  85. for (size_t i = 0; i < Internals < T, U, V >::size(); ++i) {
  86. if (not Internals < T, U, V >::get(i).is_null()) {
  87. utils::Trace < utils::DoubleTime >::trace()
  88. << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
  89. utils::KERNEL)
  90. << Internals < T, U, V >::name(i) << " = "
  91. << Internals < T, U, V >::get(i).to_string(
  92. dynamic_cast < const T* >(this));
  93. utils::Trace < utils::DoubleTime >::trace().flush();
  94. }
  95. }
  96. #else
  97. (void) t;
  98. #endif
  99. }
  100. virtual const Node < U >* atomic(unsigned int index) const
  101. {
  102. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  103. submodel_internals.find(index);
  104. if (it == submodel_internals.end()) {
  105. return this;
  106. } else {
  107. return it->second.first->atomic(it->second.second);
  108. }
  109. }
  110. virtual void before(typename U::type t)
  111. {
  112. #ifdef WITH_TRACE
  113. utils::Trace < utils::DoubleTime >::trace()
  114. << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
  115. utils::KERNEL)
  116. << "BEFORE - "
  117. << AbstractCoupledModel < T, U, V, W >::path(this);
  118. utils::Trace < utils::DoubleTime >::trace().flush();
  119. for (size_t i = 0; i < Internals < T, U, V >::size(); ++i) {
  120. if (not Internals < T, U, V >::get(i).is_null()) {
  121. utils::Trace < utils::DoubleTime >::trace()
  122. << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
  123. utils::KERNEL)
  124. << Internals < T, U, V >::name(i) << " = "
  125. << Internals < T, U, V >::get(i).to_string(
  126. dynamic_cast < const T* >(this));
  127. utils::Trace < utils::DoubleTime >::trace().flush();
  128. }
  129. }
  130. #else
  131. (void) t;
  132. #endif
  133. }
  134. virtual void build(const W& /* parameters */)
  135. { }
  136. virtual void build(const W& /* parameters */,
  137. const std::string& /* json */)
  138. { }
  139. virtual bool check(typename U::type t) const
  140. { return Externals < T, U, V >::check(t); }
  141. virtual void compute(typename U::type t, bool update) = 0;
  142. virtual const Any& get(typename U::type t, unsigned int index) const
  143. {
  144. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  145. submodel_internals.find(index);
  146. if (it == submodel_internals.end()) {
  147. if (type::last_time != t) {
  148. throw utils::InvalidGet("Variable not computed");
  149. }
  150. return Internals < T, U, V >::get(index);
  151. } else {
  152. return it->second.first->get(t, it->second.second);
  153. }
  154. }
  155. template < typename Z, typename K >
  156. Z get(typename U::type t, unsigned int index) const
  157. {
  158. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  159. submodel_internals.find(index);
  160. if (it == submodel_internals.end()) {
  161. if (type::last_time != t) {
  162. throw utils::InvalidGet("Variable not computed");
  163. }
  164. const Any& value = Internals < T, U, V >::get(index);
  165. return static_cast < const T* >(this)->*(value.get < T, Z >());
  166. } else {
  167. const Any& value = it->second.first->get(t, it->second.second);
  168. const Node < U >* object = it->second.first->atomic(
  169. it->second.second);
  170. return static_cast < const K* >(object)->*(value.get < K, Z >());
  171. }
  172. }
  173. virtual std::string get(const ValueType& value_type, typename U::type t,
  174. unsigned int index) const
  175. {
  176. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  177. submodel_internals.find(index);
  178. if (it == submodel_internals.end()) {
  179. Any value = Internals < T, U, V >::get(index);
  180. switch (value_type) {
  181. case DOUBLE:
  182. return std::to_string(
  183. static_cast < const T* >(this)->*(value.get < T,
  184. double >()));
  185. case INT:
  186. return std::to_string(
  187. static_cast < const T* >(this)->*(value.get < T, int >()));
  188. case BOOL:
  189. return std::to_string(
  190. static_cast < const T* >(this)->*(value.get < T, bool >()));
  191. default: return "NA";
  192. }
  193. } else {
  194. return it->second.first->get(value_type, t, it->second.second);
  195. }
  196. }
  197. virtual void init(typename U::type t, const V& parameters) = 0;
  198. virtual bool is_atomic() const
  199. { return false; }
  200. bool is_computed(typename U::type t, unsigned int index) const
  201. {
  202. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  203. submodel_internals.find(index);
  204. if (it == submodel_internals.end()) {
  205. return false;
  206. } else {
  207. return it->second.first->is_computed(t, it->second.second);
  208. }
  209. }
  210. bool is_stable(typename U::type t) const
  211. {
  212. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  213. submodel_internals.begin();
  214. bool stable = true;
  215. while (it != submodel_internals.end() and stable) {
  216. stable = it->second.first->is_stable(t);
  217. ++it;
  218. }
  219. return stable;
  220. }
  221. virtual bool is_updated() const
  222. { return Externals < T, U, V >::updated; }
  223. virtual const Node < U >* get_submodel(unsigned int index) const
  224. {
  225. typename AbstractCoupledModel::Submodels::const_iterator it =
  226. submodels.find(index);
  227. if (it != submodels.end()) {
  228. return it->second;
  229. } else {
  230. return 0;
  231. }
  232. }
  233. virtual const Node < U >* get_submodel(unsigned int index,
  234. unsigned int rank) const
  235. {
  236. typename AbstractCoupledModel::Setsubmodels::const_iterator it =
  237. setsubmodels.find(index);
  238. if (it != setsubmodels.end() and it->second.size() > rank) {
  239. return it->second.at(rank);
  240. } else {
  241. return 0;
  242. }
  243. }
  244. virtual std::string path_index(const AbstractModel < U, V >* child,
  245. int& index) const
  246. {
  247. typename Setsubmodels::const_iterator it = setsubmodels.begin();
  248. bool found = false;
  249. index = -1;
  250. while (not found and it != setsubmodels.end()) {
  251. typename std::vector < type* >::const_iterator itm =
  252. it->second.begin();
  253. index = 0;
  254. while (not found and itm != it->second.end()) {
  255. found = *itm == child;
  256. if (not found) {
  257. ++index;
  258. ++itm;
  259. }
  260. }
  261. index = found ? index : -1;
  262. ++it;
  263. }
  264. if (type::parent) {
  265. int i;
  266. std::string p = type::parent->path_index(this, i);
  267. if (i >= 0) {
  268. return p +
  269. "/[" + std::to_string(i) + "]" +
  270. boost::core::demangle(typeid(*this).name());
  271. } else {
  272. return p + "/" + boost::core::demangle(typeid(*this).name());
  273. }
  274. } else {
  275. return boost::core::demangle(typeid(*this).name());
  276. }
  277. }
  278. virtual void restore(const context::State < U >& state)
  279. {
  280. typename AbstractCoupledModel::Submodels::const_iterator it =
  281. submodels.begin();
  282. while (it != submodels.end()) {
  283. it->second->restore(state.get_substate(it->first));
  284. ++it;
  285. }
  286. States < T, U, V >::restore(this, state);
  287. Internals < T, U, V >::restore(this, state);
  288. Externals < T, U, V >::restore(this, state);
  289. }
  290. virtual void save(context::State < U >& state) const
  291. {
  292. typename AbstractCoupledModel::Submodels::const_iterator it =
  293. submodels.begin();
  294. while (it != submodels.end()) {
  295. context::State < U > substate;
  296. it->second->save(substate);
  297. state.add_substate(it->first, substate);
  298. ++it;
  299. }
  300. States < T, U, V >::save(this, state);
  301. Internals < T, U, V >::save(this, state);
  302. Externals < T, U, V >::save(this, state);
  303. }
  304. virtual void stable()
  305. { Externals < T, U, V >::updated = false; }
  306. void submodel(unsigned int index, type* model)
  307. {
  308. if (model) {
  309. submodels[index] = model;
  310. model->set_parent(this);
  311. } else {
  312. submodels[index] = 0;
  313. }
  314. }
  315. protected:
  316. void change_internal(unsigned int index, double T::* var)
  317. {
  318. submodel_internals.erase(index);
  319. Internals < T, U, V >::internal(index, var);
  320. }
  321. void change_internal(unsigned int index, int T::* var)
  322. {
  323. submodel_internals.erase(index);
  324. Internals < T, U, V >::internalI(index, var);
  325. }
  326. void change_internal(unsigned int index, bool T::* var)
  327. {
  328. submodel_internals.erase(index);
  329. Internals < T, U, V >::internalB(index, var);
  330. }
  331. void internal_(unsigned int index, type* model, int sub_index)
  332. {
  333. submodel_internals[index] =
  334. std::pair < type*, int >(model, sub_index);
  335. }
  336. void I_(std::initializer_list < Var > internals)
  337. {
  338. for (typename std::initializer_list < Var >::iterator it =
  339. internals.begin(); it != internals.end(); ++it) {
  340. submodel_internals[it->index] =
  341. std::pair < type*, int >(it->model, it->sub_index);
  342. }
  343. }
  344. void SM_(std::initializer_list < std::pair < unsigned int,
  345. type* > > models)
  346. {
  347. for (typename std::initializer_list < std::pair < unsigned int,
  348. type* > >::iterator it =
  349. models.begin(); it != models.end(); ++it) {
  350. submodels[it->first] = it->second;
  351. it->second->set_parent(this);
  352. #ifdef WITH_TRACE
  353. utils::Trace < utils::DoubleTime >::trace()
  354. << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
  355. utils::KERNEL)
  356. << "ADD SUBMODEL - "
  357. << AbstractCoupledModel < T, U, V, W >::path(it->second)
  358. << " to "
  359. << AbstractCoupledModel < T, U, V, W >::path(this);
  360. utils::Trace < utils::DoubleTime >::trace().flush();
  361. #endif
  362. }
  363. }
  364. void setsubmodel(unsigned int index, type* model)
  365. {
  366. if (setsubmodels.find(index) == setsubmodels.end()) {
  367. setsubmodels[index] = std::vector < type* >();
  368. }
  369. setsubmodels[index].push_back(model);
  370. model->set_parent(this);
  371. #ifdef WITH_TRACE
  372. utils::Trace < utils::DoubleTime >::trace()
  373. << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
  374. utils::KERNEL)
  375. << "ADD SUBMODEL - "
  376. << AbstractCoupledModel < T, U, V, W >::path(model)
  377. << " to "
  378. << AbstractCoupledModel < T, U, V, W >::path(this);
  379. utils::Trace < utils::DoubleTime >::trace().flush();
  380. #endif
  381. }
  382. private:
  383. SubModelInternals submodel_internals;
  384. Submodels submodels;
  385. Setsubmodels setsubmodels;
  386. };
  387. #define InternalS(index, var, sub_index) internal_(index, var, sub_index)
  388. #define ITEM_S(index, var, sub_index) Var(index, var, sub_index)
  389. #define UNWRAP_ITEM_S(...) ITEM_S __VA_ARGS__
  390. #define LIST_S_16(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15, L16) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13), UNWRAP_ITEM_S(L14), UNWRAP_ITEM_S(L15), UNWRAP_ITEM_S(L16) }
  391. #define LIST_S_15(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13), UNWRAP_ITEM_S(L14), UNWRAP_ITEM_S(L15) }
  392. #define LIST_S_14(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13), UNWRAP_ITEM_S(L14) }
  393. #define LIST_S_13(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12), UNWRAP_ITEM_S(L13) }
  394. #define LIST_S_12(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11), UNWRAP_ITEM_S(L12) }
  395. #define LIST_S_11(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10), UNWRAP_ITEM_S(L11) }
  396. #define LIST_S_10(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9), UNWRAP_ITEM_S(L10) }
  397. #define LIST_S_9(L1, L2, L3, L4, L5, L6, L7, L8, L9) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8), UNWRAP_ITEM_S(L9) }
  398. #define LIST_S_8(L1, L2, L3, L4, L5, L6, L7, L8) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7), UNWRAP_ITEM_S(L8) }
  399. #define LIST_S_7(L1, L2, L3, L4, L5, L6, L7) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6), UNWRAP_ITEM_S(L7) }
  400. #define LIST_S_6(L1, L2, L3, L4, L5, L6) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5), UNWRAP_ITEM_S(L6) }
  401. #define LIST_S_5(L1, L2, L3, L4, L5) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4), UNWRAP_ITEM_S(L5) }
  402. #define LIST_S_4(L1, L2, L3, L4) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4) }
  403. #define LIST_S_3(L1, L2, L3) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3) }
  404. #define LIST_S_2(L1, L2) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2) }
  405. #define LIST_S_1(L1) { UNWRAP_ITEM_S(L1) }
  406. #define LIST_S_(N) LIST_S_##N
  407. #define LIST_S_EVAL(N) LIST_S_(N)
  408. #define UNWRAP_S_2(...) EXPAND( LIST_S_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) )
  409. //#define UNWRAP_S_2(...) GET_MACRO(__VA_ARGS__, LIST_S_16, LIST_S_15, LIST_S_14, LIST_S_13, LIST_S_12, LIST_S_11, LIST_S_10, LIST_S_9, LIST_S_8, LIST_S_7, LIST_S_6, LIST_S_5, LIST_S_4, LIST_S_3, LIST_S_2, LIST_S_1)(__VA_ARGS__)
  410. #define InternalsS(L) I_(UNWRAP_S_2 L)
  411. #define ITEM_Sub(index, model) { index, model }
  412. #define UNWRAP_ITEM_Sub(...) ITEM_Sub __VA_ARGS__
  413. #define LIST_Sub_16(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15, L16) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12), UNWRAP_ITEM_Sub(L13), UNWRAP_ITEM_Sub(L14), UNWRAP_ITEM_Sub(L15), UNWRAP_ITEM_Sub(L16) }
  414. #define LIST_Sub_15(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12), UNWRAP_ITEM_Sub(L13), UNWRAP_ITEM_Sub(L14), UNWRAP_ITEM_Sub(L15) }
  415. #define LIST_Sub_14(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12), UNWRAP_ITEM_Sub(L13), UNWRAP_ITEM_Sub(L14) }
  416. #define LIST_Sub_13(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12), UNWRAP_ITEM_Sub(L13) }
  417. #define LIST_Sub_12(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11), UNWRAP_ITEM_Sub(L12) }
  418. #define LIST_Sub_11(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10), UNWRAP_ITEM_Sub(L11) }
  419. #define LIST_Sub_10(L1, L2, L3, L4, L5, L6, L7, L8, L9, L10) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9), UNWRAP_ITEM_Sub(L10) }
  420. #define LIST_Sub_9(L1, L2, L3, L4, L5, L6, L7, L8, L9) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8), UNWRAP_ITEM_Sub(L9) }
  421. #define LIST_Sub_8(L1, L2, L3, L4, L5, L6, L7, L8) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7), UNWRAP_ITEM_Sub(L8) }
  422. #define LIST_Sub_7(L1, L2, L3, L4, L5, L6, L7) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6), UNWRAP_ITEM_Sub(L7) }
  423. #define LIST_Sub_6(L1, L2, L3, L4, L5, L6) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5), UNWRAP_ITEM_Sub(L6) }
  424. #define LIST_Sub_5(L1, L2, L3, L4, L5) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4), UNWRAP_ITEM_Sub(L5) }
  425. #define LIST_Sub_4(L1, L2, L3, L4) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4) }
  426. #define LIST_Sub_3(L1, L2, L3) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3) }
  427. #define LIST_Sub_2(L1, L2) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2) }
  428. #define LIST_Sub_1(L1) { UNWRAP_ITEM_Sub(L1) }
  429. #define LIST_Sub_(N) LIST_Sub_##N
  430. #define LIST_Sub_EVAL(N) LIST_Sub_(N)
  431. #define UNWRAP_Sub_2(...) EXPAND( LIST_Sub_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) )
  432. //#define UNWRAP_Sub_2(...) GET_MACRO(__VA_ARGS__, LIST_Sub_16, LIST_Sub_15, LIST_Sub_14, LIST_Sub_13, LIST_Sub_12, LIST_Sub_11, LIST_Sub_10, LIST_Sub_9, LIST_Sub_8, LIST_Sub_7, LIST_Sub_6, LIST_Sub_5, LIST_Sub_4, LIST_Sub_3, LIST_Sub_2, LIST_Sub_1)(__VA_ARGS__)
  433. #define Submodels(L) SM_(UNWRAP_Sub_2 L)
  434. } }
  435. #endif