AbstractCoupledModel.hpp 25 KB

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