AbstractCoupledModel.hpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. std::string var_name;
  51. std::string sub_var_name;
  52. Var (unsigned int index, std::string var_name,
  53. type* model, int sub_index, std::string sub_var_name) :
  54. index(index), model(model), sub_index(sub_index),
  55. var_name(var_name), sub_var_name(sub_var_name)
  56. { }
  57. };
  58. AbstractCoupledModel(const type* parent = 0) : type(parent)
  59. {
  60. #ifdef WITH_TRACE
  61. utils::Trace < utils::DoubleTime >::trace()
  62. << utils::TraceElement < utils::DoubleTime >(
  63. boost::core::demangle(typeid(T).name()).erase(0,6),
  64. utils::DoubleTime::null,
  65. utils::CONSTRUCT);
  66. utils::Trace < utils::DoubleTime >::trace().flush();
  67. #endif
  68. }
  69. virtual ~AbstractCoupledModel()
  70. {
  71. #ifdef WITH_TRACE
  72. trace_element(utils::DoubleTime::null,
  73. utils::DESTRUCT);
  74. #endif
  75. }
  76. virtual void after(typename U::type t)
  77. {
  78. #ifdef WITH_TRACE
  79. trace_element(t, utils::AFTER_COMPUTE);
  80. trace_internals(t, utils::AFTER_COMPUTE);
  81. #else
  82. (void) t;
  83. #endif
  84. }
  85. virtual const Node < U >* atomic(unsigned int index) const
  86. {
  87. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  88. submodel_internals.find(index);
  89. if (it == submodel_internals.end()) {
  90. return this;
  91. } else {
  92. return it->second.first->atomic(it->second.second);
  93. }
  94. }
  95. virtual void before(typename U::type t)
  96. {
  97. #ifdef WITH_TRACE
  98. trace_element(t, utils::BEFORE_COMPUTE);
  99. trace_internals(t, utils::BEFORE_COMPUTE);
  100. trace_externals(t, utils::BEFORE_COMPUTE);
  101. #else
  102. (void) t;
  103. #endif
  104. }
  105. virtual void build(W& /* parameters */)
  106. { }
  107. virtual void build(W& /* parameters */, const std::string& /* json */)
  108. { }
  109. virtual bool check(typename U::type t) const
  110. { return Externals < T, U, V >::check(t); }
  111. virtual void compute(typename U::type t, bool update) = 0;
  112. virtual const Any& get(typename U::type t, unsigned int index) const
  113. {
  114. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  115. submodel_internals.find(index);
  116. if (it == submodel_internals.end()) {
  117. if (type::last_time != t) {
  118. throw utils::InvalidGet("Variable not computed");
  119. }
  120. return Internals < T, U, V >::get(index);
  121. } else {
  122. return it->second.first->get(t, it->second.second);
  123. }
  124. }
  125. template < typename Z, typename K >
  126. Z get(typename U::type t, unsigned int index) const
  127. {
  128. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  129. submodel_internals.find(index);
  130. if (it == submodel_internals.end()) {
  131. if (type::last_time != t) {
  132. throw utils::InvalidGet("Variable not computed");
  133. }
  134. const Any& value = Internals < T, U, V >::get(index);
  135. return static_cast < const T* >(this)->*(value.get < T, Z >());
  136. } else {
  137. const Any& value = it->second.first->get(t, it->second.second);
  138. const Node < U >* object = it->second.first->atomic(
  139. it->second.second);
  140. return static_cast < const K* >(object)->*(value.get < K, Z >());
  141. }
  142. }
  143. virtual std::string get(const ValueType& value_type, typename U::type t,
  144. unsigned int index) const
  145. {
  146. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  147. submodel_internals.find(index);
  148. if (it == submodel_internals.end()) {
  149. Any value = Internals < T, U, V >::get(index);
  150. switch (value_type) {
  151. case DOUBLE:
  152. return std::to_string(
  153. static_cast < const T* >(this)->*(value.get < T,
  154. double >()));
  155. case INT:
  156. return std::to_string(
  157. static_cast < const T* >(this)->*(value.get < T, int >()));
  158. case BOOL:
  159. return std::to_string(
  160. static_cast < const T* >(this)->*(value.get < T, bool >()));
  161. default: return "NA";
  162. }
  163. } else {
  164. return it->second.first->get(value_type, t, it->second.second);
  165. }
  166. }
  167. virtual void init(typename U::type t, const V& parameters) = 0;
  168. virtual bool is_atomic() const
  169. { return false; }
  170. bool is_computed(typename U::type t, unsigned int index) const
  171. {
  172. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  173. submodel_internals.find(index);
  174. if (it == submodel_internals.end()) {
  175. return false;
  176. } else {
  177. return it->second.first->is_computed(t, it->second.second);
  178. }
  179. }
  180. bool is_stable(typename U::type t) const
  181. {
  182. typename AbstractCoupledModel::SubModelInternals::const_iterator it =
  183. submodel_internals.begin();
  184. bool stable = true;
  185. while (it != submodel_internals.end() and stable) {
  186. stable = it->second.first->is_stable(t);
  187. ++it;
  188. }
  189. return stable;
  190. }
  191. virtual bool is_updated() const
  192. { return Externals < T, U, V >::updated; }
  193. virtual const Node < U >* get_submodel(unsigned int index) const
  194. {
  195. typename AbstractCoupledModel::Submodels::const_iterator it =
  196. submodels.find(index);
  197. if (it != submodels.end()) {
  198. return it->second;
  199. } else {
  200. return 0;
  201. }
  202. }
  203. virtual const Node < U >* get_submodel(unsigned int index,
  204. unsigned int rank) const
  205. {
  206. typename AbstractCoupledModel::Setsubmodels::const_iterator it =
  207. setsubmodels.find(index);
  208. if (it != setsubmodels.end() and it->second.size() > rank) {
  209. return it->second.at(rank);
  210. } else {
  211. return 0;
  212. }
  213. }
  214. virtual std::string path_index(const AbstractModel < U, V >* child,
  215. int& index) const
  216. {
  217. typename Setsubmodels::const_iterator it = setsubmodels.begin();
  218. bool found = false;
  219. index = -1;
  220. while (not found and it != setsubmodels.end()) {
  221. typename std::vector < type* >::const_iterator itm =
  222. it->second.begin();
  223. index = 0;
  224. while (not found and itm != it->second.end()) {
  225. found = *itm == child;
  226. if (not found) {
  227. ++index;
  228. ++itm;
  229. }
  230. }
  231. index = found ? index : -1;
  232. ++it;
  233. }
  234. if (type::parent) {
  235. int i;
  236. std::string p = type::parent->path_index(this, i);
  237. if (i >= 0) {
  238. return p +
  239. "/[" + std::to_string(i) + "]" +
  240. boost::core::demangle(typeid(*this).name());
  241. } else {
  242. return p + "/" + boost::core::demangle(typeid(*this).name()).erase(0,6);
  243. }
  244. } else {
  245. return boost::core::demangle(typeid(*this).name()).erase(0,6);
  246. }
  247. }
  248. virtual void restore(const context::State < U >& state)
  249. {
  250. typename AbstractCoupledModel::Submodels::const_iterator it =
  251. submodels.begin();
  252. while (it != submodels.end()) {
  253. it->second->restore(state.get_substate(it->first));
  254. ++it;
  255. }
  256. States < T, U, V >::restore(this, state);
  257. Internals < T, U, V >::restore(this, state);
  258. Externals < T, U, V >::restore(this, state);
  259. }
  260. virtual void save(context::State < U >& state) const
  261. {
  262. typename AbstractCoupledModel::Submodels::const_iterator it =
  263. submodels.begin();
  264. while (it != submodels.end()) {
  265. context::State < U > substate;
  266. it->second->save(substate);
  267. state.add_substate(it->first, substate);
  268. ++it;
  269. }
  270. States < T, U, V >::save(this, state);
  271. Internals < T, U, V >::save(this, state);
  272. Externals < T, U, V >::save(this, state);
  273. }
  274. virtual void trace_element(typename U::type t, utils::TraceType type = utils::KERNEL, std::string comment = "") const
  275. {
  276. utils::Trace < utils::DoubleTime >::trace()
  277. << utils::TraceElement < utils::DoubleTime >(
  278. AbstractCoupledModel < T, U, V, W >::path(this),
  279. t, type)
  280. << comment;
  281. utils::Trace < utils::DoubleTime >::trace().flush();
  282. }
  283. virtual void trace_internals(typename U::type t, utils::TraceType type) const
  284. {
  285. for (size_t i = 0; i < Internals < T, U, V >::size(); ++i) {
  286. if (not Internals < T, U, V >::get(i).is_null()) {
  287. utils::Trace < utils::DoubleTime >::trace()
  288. << utils::TraceElement < utils::DoubleTime >(
  289. AbstractCoupledModel < T, U, V, W >::path(this),
  290. t, type)
  291. << utils::KernelInfo(
  292. Internals < T, U, V >::name(i), true,
  293. Internals < T, U, V >::get(i).to_string(
  294. dynamic_cast < const T* >(this))
  295. );
  296. utils::Trace < utils::DoubleTime >::trace().flush();
  297. }
  298. }
  299. }
  300. virtual void trace_externals(typename U::type t, utils::TraceType type = utils::KERNEL) const
  301. {
  302. for (size_t i = 0; i < Externals < T, U, V >::size(); ++i) {
  303. if (not Externals < T, U, V >::get(i).is_null()) {
  304. utils::Trace < utils::DoubleTime >::trace()
  305. << utils::TraceElement < utils::DoubleTime >(
  306. AbstractCoupledModel < T, U, V, W >::path(this),
  307. t, type)
  308. << utils::KernelInfo(
  309. Externals < T, U, V >::name(i), false,
  310. Externals < T, U, V >::get(i).to_string(
  311. dynamic_cast < const T* >(this))
  312. );
  313. utils::Trace < utils::DoubleTime >::trace().flush();
  314. }
  315. }
  316. }
  317. virtual void trace_model(typename U::type t, utils::TraceType type = utils::KERNEL) const
  318. {
  319. trace_element(t, type);
  320. trace_internals(t, type);
  321. trace_externals(t, type);
  322. typename AbstractCoupledModel::Submodels::const_iterator it =
  323. submodels.begin();
  324. while (it != submodels.end()) {
  325. it->second->trace_model(t, type);
  326. ++it;
  327. }
  328. }
  329. virtual void stable()
  330. { Externals < T, U, V >::updated = false; }
  331. void submodel(unsigned int index, type* model)
  332. {
  333. if (model) {
  334. submodels[index] = model;
  335. model->set_parent(this);
  336. } else {
  337. submodels[index] = 0;
  338. }
  339. }
  340. protected:
  341. // void change_internal(unsigned int index, double T::* var)
  342. // {
  343. // submodel_internals.erase(index);
  344. // Internals < T, U, V >::internal(index, var);
  345. // }
  346. // void change_internal(unsigned int index, int T::* var)
  347. // {
  348. // submodel_internals.erase(index);
  349. // Internals < T, U, V >::internalI(index, var);
  350. // }
  351. // void change_internal(unsigned int index, bool T::* var)
  352. // {
  353. // submodel_internals.erase(index);
  354. // Internals < T, U, V >::internalB(index, var);
  355. // }
  356. void link_internal_(unsigned int index, std::string var_name,
  357. type* model, int sub_index, std::string sub_var_name)
  358. {
  359. submodel_internals[index] =
  360. std::pair < type*, int >(model, sub_index);
  361. #ifdef WITH_TRACE
  362. utils::Trace < utils::DoubleTime >::trace()
  363. << utils::TraceElement < utils::DoubleTime >(
  364. AbstractCoupledModel < T, U, V, W >::path(this),
  365. utils::DoubleTime::null,
  366. utils::INTERNAL_LINK)
  367. << utils::KernelInfo(
  368. var_name,
  369. AbstractCoupledModel < T, U, V, W >::path(model),
  370. sub_var_name);
  371. utils::Trace < utils::DoubleTime >::trace().flush();
  372. #endif
  373. }
  374. void I_(std::initializer_list < Var > internals)
  375. {
  376. for (typename std::initializer_list < Var >::iterator it =
  377. internals.begin(); it != internals.end(); ++it) {
  378. submodel_internals[it->index] =
  379. std::pair < type*, int >(it->model, it->sub_index);
  380. #ifdef WITH_TRACE
  381. utils::Trace < utils::DoubleTime >::trace()
  382. << utils::TraceElement < utils::DoubleTime >(
  383. AbstractCoupledModel < T, U, V, W >::path(this),
  384. utils::DoubleTime::null,
  385. utils::INTERNAL_LINK)
  386. << utils::KernelInfo(
  387. it->var_name,
  388. AbstractCoupledModel < T, U, V, W >::path(it->model),
  389. it->sub_var_name);
  390. utils::Trace < utils::DoubleTime >::trace().flush();
  391. #endif
  392. }
  393. }
  394. void SM_(std::initializer_list < std::pair < unsigned int,
  395. type* > > models)
  396. {
  397. for (typename std::initializer_list < std::pair < unsigned int,
  398. type* > >::iterator it =
  399. models.begin(); it != models.end(); ++it) {
  400. submodels[it->first] = it->second;
  401. it->second->set_parent(this);
  402. #ifdef WITH_TRACE
  403. utils::Trace < utils::DoubleTime >::trace()
  404. << utils::TraceElement < utils::DoubleTime >(
  405. AbstractCoupledModel < T, U, V, W >::path(this),
  406. utils::DoubleTime::null,
  407. utils::SUBMODEL_ADD)
  408. << utils::KernelInfo(
  409. AbstractCoupledModel < T, U, V, W >::path(it->second));
  410. utils::Trace < utils::DoubleTime >::trace().flush();
  411. #endif
  412. }
  413. }
  414. void setsubmodel(unsigned int index, type* model)
  415. {
  416. if (setsubmodels.find(index) == setsubmodels.end()) {
  417. setsubmodels[index] = std::vector < type* >();
  418. }
  419. setsubmodels[index].push_back(model);
  420. model->set_parent(this);
  421. #ifdef WITH_TRACE
  422. utils::Trace < utils::DoubleTime >::trace()
  423. << utils::TraceElement < utils::DoubleTime >(
  424. AbstractCoupledModel < T, U, V, W >::path(this),
  425. utils::DoubleTime::null,
  426. utils::SUBMODEL_ADD)
  427. << utils::KernelInfo(
  428. AbstractCoupledModel < T, U, V, W >::path(model));
  429. utils::Trace < utils::DoubleTime >::trace().flush();
  430. #endif
  431. }
  432. private:
  433. SubModelInternals submodel_internals;
  434. Submodels submodels;
  435. Setsubmodels setsubmodels;
  436. };
  437. #define InternalS(index, var, sub_index) link_internal_(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index)))
  438. #define ITEM_S(index, var, sub_index) Var(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index)))
  439. #define UNWRAP_ITEM_S(...) ITEM_S __VA_ARGS__
  440. #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) }
  441. #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) }
  442. #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) }
  443. #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) }
  444. #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) }
  445. #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) }
  446. #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) }
  447. #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) }
  448. #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) }
  449. #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) }
  450. #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) }
  451. #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) }
  452. #define LIST_S_4(L1, L2, L3, L4) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4) }
  453. #define LIST_S_3(L1, L2, L3) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3) }
  454. #define LIST_S_2(L1, L2) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2) }
  455. #define LIST_S_1(L1) { UNWRAP_ITEM_S(L1) }
  456. #define LIST_S_(N) LIST_S_##N
  457. #define LIST_S_EVAL(N) LIST_S_(N)
  458. #define UNWRAP_S_2(...) EXPAND( LIST_S_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) )
  459. //#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__)
  460. #define InternalsS(L) I_(UNWRAP_S_2 L)
  461. #define ITEM_Sub(index, model) { index, model }
  462. #define UNWRAP_ITEM_Sub(...) ITEM_Sub __VA_ARGS__
  463. #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) }
  464. #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) }
  465. #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) }
  466. #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) }
  467. #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) }
  468. #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) }
  469. #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) }
  470. #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) }
  471. #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) }
  472. #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) }
  473. #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) }
  474. #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) }
  475. #define LIST_Sub_4(L1, L2, L3, L4) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4) }
  476. #define LIST_Sub_3(L1, L2, L3) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3) }
  477. #define LIST_Sub_2(L1, L2) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2) }
  478. #define LIST_Sub_1(L1) { UNWRAP_ITEM_Sub(L1) }
  479. #define LIST_Sub_(N) LIST_Sub_##N
  480. #define LIST_Sub_EVAL(N) LIST_Sub_(N)
  481. #define UNWRAP_Sub_2(...) EXPAND( LIST_Sub_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) )
  482. //#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__)
  483. #define Submodels(L) SM_(UNWRAP_Sub_2 L)
  484. } }
  485. #endif