/** * @file artis/kernel/AbstractCoupledModel.hpp * @author See the AUTHORS file */ /* * Copyright (C) 2012-2019 ULCO http://www.univ-littoral.fr * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __ARTIS_KERNEL_ABSTRACT_COUPLED_MODEL_HPP #define __ARTIS_KERNEL_ABSTRACT_COUPLED_MODEL_HPP #include #include #include #include #include #include #include #include namespace artis { namespace kernel { template class Simulator; template class AbstractCoupledModel : public AbstractModel, public States, public Internals, public Externals { typedef AbstractModel type; typedef std::map Submodels; typedef std::map > Setsubmodels; typedef std::map > SubModelInternals; using Externals::restore; using Internals::restore; using States::restore; using Externals::save; using Internals::save; using States::save; #ifdef WITH_TRACE friend class Simulator; #endif public: struct Var { unsigned int index; type* model; int sub_index; std::string var_name; std::string sub_var_name; Var(unsigned int index, std::string var_name, type* model, int sub_index, std::string sub_var_name) : index(index), model(model), sub_index(sub_index), var_name(var_name), sub_var_name(sub_var_name) { } }; AbstractCoupledModel(const type* parent = 0) :type(parent) { #ifdef WITH_TRACE utils::Trace::trace() << utils::TraceElement( true, boost::core::demangle(typeid(T).name()), utils::DoubleTime::null, utils::CONSTRUCT); utils::Trace::trace().flush(); #endif } virtual ~AbstractCoupledModel() { #ifdef WITH_TRACE trace_element(true, utils::DoubleTime::null, utils::DESTRUCT); #endif } virtual void after(typename U::type t) { #ifdef WITH_TRACE trace_element(true, t, utils::AFTER_COMPUTE); trace_internals(true, t, utils::AFTER_COMPUTE); #else (void) t; #endif } virtual const Node* atomic(unsigned int index) const { typename AbstractCoupledModel::SubModelInternals::const_iterator it = submodel_internals.find(index); if (it == submodel_internals.end()) { return this; } else { return it->second.first->atomic(it->second.second); } } virtual void before(typename U::type t) { #ifdef WITH_TRACE trace_element(true, t, utils::BEFORE_COMPUTE); trace_internals(true, t, utils::BEFORE_COMPUTE); trace_externals(true, t, utils::BEFORE_COMPUTE); #else (void) t; #endif } virtual void build(W& /* parameters */) { } virtual void build(W& /* parameters */, const std::string& /* json */) { } virtual bool check(typename U::type t) const { return Externals::check(t); } virtual void compute(typename U::type t, bool update) = 0; virtual const Any& get(typename U::type t, unsigned int index) const { typename AbstractCoupledModel::SubModelInternals::const_iterator it = submodel_internals.find(index); if (it == submodel_internals.end()) { if (type::last_time != t) { throw utils::InvalidGet("Variable not computed"); } return Internals::get(index); } else { return it->second.first->get(t, it->second.second); } } template Z get(typename U::type t, unsigned int index) const { typename AbstractCoupledModel::SubModelInternals::const_iterator it = submodel_internals.find(index); if (it == submodel_internals.end()) { if (type::last_time != t) { throw utils::InvalidGet("Variable not computed"); } const Any& value = Internals::get(index); return static_cast < const T* >(this)->*(value.get()); } else { const Any& value = it->second.first->get(t, it->second.second); const Node* object = it->second.first->atomic( it->second.second); return static_cast < const K* >(object)->*(value.get()); } } virtual std::string get(const ValueTypeID& value_type, typename U::type t, unsigned int index) const { typename AbstractCoupledModel::SubModelInternals::const_iterator it = submodel_internals.find(index); if (it == submodel_internals.end()) { Any value = Internals::get(index); switch (value_type) { case DOUBLE: return std::to_string( static_cast < const T* >(this)->*(value.get())); case INT: return std::to_string( static_cast < const T* >(this)->*(value.get())); case BOOL: return std::to_string( static_cast < const T* >(this)->*(value.get())); default: return "NA"; } } else { return it->second.first->get(value_type, t, it->second.second); } } virtual void init(typename U::type t, const V& parameters) = 0; virtual bool is_atomic() const { return false; } bool is_computed(typename U::type t, unsigned int index) const { typename AbstractCoupledModel::SubModelInternals::const_iterator it = submodel_internals.find(index); if (it == submodel_internals.end()) { return false; } else { return it->second.first->is_computed(t, it->second.second); } } bool is_stable(typename U::type t) const { typename AbstractCoupledModel::SubModelInternals::const_iterator it = submodel_internals.begin(); bool stable = true; while (it != submodel_internals.end() and stable) { stable = it->second.first->is_stable(t); ++it; } return stable; } virtual bool is_updated() const { return Externals::updated; } virtual const Node* get_submodel(unsigned int index) const { typename AbstractCoupledModel::Submodels::const_iterator it = submodels.find(index); if (it != submodels.end()) { return it->second; } else { return 0; } } virtual const Node* get_submodel(unsigned int index, unsigned int rank) const { typename AbstractCoupledModel::Setsubmodels::const_iterator it = setsubmodels.find(index); if (it != setsubmodels.end() and it->second.size() > rank) { return it->second.at(rank); } else { return 0; } } virtual std::string path_index(const AbstractModel* child, int& index) const { typename Setsubmodels::const_iterator it = setsubmodels.begin(); bool found = false; index = -1; while (not found and it != setsubmodels.end()) { typename std::vector::const_iterator itm = it->second.begin(); index = 0; while (not found and itm != it->second.end()) { found = *itm == child; if (not found) { ++index; ++itm; } } index = found ? index : -1; ++it; } if (type::parent) { int i; std::string p = type::parent->path_index(this, i); if (i >= 0) { return p + "/[" + std::to_string(i) + "]" + boost::core::demangle(typeid(*this).name()); } else { return p + "/" + boost::core::demangle(typeid(*this).name()); } } else { return boost::core::demangle(typeid(*this).name()); } } virtual void restore(const context::State& state) { typename AbstractCoupledModel::Submodels::const_iterator it = submodels.begin(); while (it != submodels.end()) { it->second->restore(state.get_substate(it->first)); ++it; } States::restore(this, state); Internals::restore(this, state); Externals::restore(this, state); } virtual void save(context::State& state) const { typename AbstractCoupledModel::Submodels::const_iterator it = submodels.begin(); while (it != submodels.end()) { context::State substate; it->second->save(substate); state.add_substate(it->first, substate); ++it; } States::save(this, state); Internals::save(this, state); Externals::save(this, state); } virtual void stable() { Externals::updated = false; } void submodel(unsigned int index, type* model) { if (model) { submodels[index] = model; model->set_parent(this); } else { submodels[index] = 0; } } virtual void trace_element(typename U::type t, utils::TraceType type = utils::NONE, std::string comment = "") const { trace_element(false, t, type, comment); } virtual void trace_internals(typename U::type t, utils::TraceType type) const { trace_internals(false, t, type); } virtual void trace_externals(typename U::type t, utils::TraceType type = utils::NONE) const { trace_externals(false, t, type); } virtual void trace_model(typename U::type t, utils::TraceType type = utils::NONE) const { trace_model(false, t, type); } private: void trace_element(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE, std::string comment = "") const { utils::Trace::trace() << utils::TraceElement( from_kernel, AbstractCoupledModel::path(this), t, type) << comment; utils::Trace::trace().flush(); } void trace_internals(bool from_kernel, typename U::type t, utils::TraceType type) const { for (size_t i = 0; i < Internals::size(); ++i) { if (not Internals::get(i).is_null()) { utils::Trace::trace() << utils::TraceElement( from_kernel, AbstractCoupledModel::path(this), t, type) << utils::KernelInfo( Internals::name(i), true, Internals::get(i).to_string( dynamic_cast < const T* >(this)) ); utils::Trace::trace().flush(); } } } void trace_externals(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE) const { for (size_t i = 0; i < Externals::size(); ++i) { if (not Externals::get(i).is_null()) { utils::Trace::trace() << utils::TraceElement( from_kernel, AbstractCoupledModel::path(this), t, type) << utils::KernelInfo( Externals::name(i), false, Externals::get(i).to_string( dynamic_cast < const T* >(this)) ); utils::Trace::trace().flush(); } } } void trace_model(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE) const { trace_element(from_kernel, t, type); trace_internals(from_kernel, t, type); trace_externals(from_kernel, t, type); // typename AbstractCoupledModel::Submodels::const_iterator it = // submodels.begin(); // while (it != submodels.end()) { // it->second->trace_model(from_kernel, t, type); // ++it; // } } protected: void link_internal_(unsigned int index, std::string var_name, type* model, int sub_index, std::string sub_var_name) { #ifndef WITH_TRACE (void) sub_var_name; #endif submodel_internals[index] = std::pair(model, sub_index); #ifdef WITH_TRACE utils::Trace::trace() << utils::TraceElement( true, AbstractCoupledModel::path(this), utils::DoubleTime::null, utils::INTERNAL_LINK) << utils::KernelInfo( var_name, AbstractCoupledModel::path(model), sub_var_name); utils::Trace::trace().flush(); #endif } void I_(std::initializer_list internals) { for (typename std::initializer_list::iterator it = internals.begin(); it != internals.end(); ++it) { submodel_internals[it->index] = std::pair(it->model, it->sub_index); #ifdef WITH_TRACE utils::Trace::trace() << utils::TraceElement( true, AbstractCoupledModel::path(this), utils::DoubleTime::null, utils::INTERNAL_LINK) << utils::KernelInfo( it->var_name, AbstractCoupledModel::path(it->model), it->sub_var_name); utils::Trace::trace().flush(); #endif } } void SM_(std::initializer_list > models) { for (typename std::initializer_list >::iterator it = models.begin(); it != models.end(); ++it) { submodels[it->first] = it->second; it->second->set_parent(this); #ifdef WITH_TRACE utils::Trace::trace() << utils::TraceElement( true, AbstractCoupledModel::path(this), utils::DoubleTime::null, utils::SUBMODEL_ADD) << utils::KernelInfo( AbstractCoupledModel::path(it->second)); utils::Trace::trace().flush(); #endif } } void setsubmodel(unsigned int index, type* model) { if (setsubmodels.find(index) == setsubmodels.end()) { setsubmodels[index] = std::vector(); } setsubmodels[index].push_back(model); model->set_parent(this); #ifdef WITH_TRACE utils::Trace::trace() << utils::TraceElement( true, AbstractCoupledModel::path(this), utils::DoubleTime::null, utils::SUBMODEL_ADD) << utils::KernelInfo( AbstractCoupledModel::path(model)); utils::Trace::trace().flush(); #endif } private: SubModelInternals submodel_internals; Submodels submodels; Setsubmodels setsubmodels; }; #define InternalS(index, var, sub_index) link_internal_(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index))) #define ITEM_S(index, var, sub_index) Var(index, std::string(ESCAPEQUOTE(index)), var, sub_index, std::string(ESCAPEQUOTE(index))) #define UNWRAP_ITEM_S(...) ITEM_S __VA_ARGS__ #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #define LIST_S_4(L1, L2, L3, L4) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3), UNWRAP_ITEM_S(L4) } #define LIST_S_3(L1, L2, L3) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2), UNWRAP_ITEM_S(L3) } #define LIST_S_2(L1, L2) { UNWRAP_ITEM_S(L1), UNWRAP_ITEM_S(L2) } #define LIST_S_1(L1) { UNWRAP_ITEM_S(L1) } #define LIST_S_(N) LIST_S_##N #define LIST_S_EVAL(N) LIST_S_(N) #define UNWRAP_S_2(...) EXPAND( LIST_S_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) ) //#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__) #define InternalsS(L) I_(UNWRAP_S_2 L) #define ITEM_Sub(index, model) { index, model } #define UNWRAP_ITEM_Sub(...) ITEM_Sub __VA_ARGS__ #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #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) } #define LIST_Sub_4(L1, L2, L3, L4) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3), UNWRAP_ITEM_Sub(L4) } #define LIST_Sub_3(L1, L2, L3) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2), UNWRAP_ITEM_Sub(L3) } #define LIST_Sub_2(L1, L2) { UNWRAP_ITEM_Sub(L1), UNWRAP_ITEM_Sub(L2) } #define LIST_Sub_1(L1) { UNWRAP_ITEM_Sub(L1) } #define LIST_Sub_(N) LIST_Sub_##N #define LIST_Sub_EVAL(N) LIST_Sub_(N) #define UNWRAP_Sub_2(...) EXPAND( LIST_Sub_EVAL(EXPAND( PP_NARG(__VA_ARGS__) ))(__VA_ARGS__) ) //#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__) #define Submodels(L) SM_(UNWRAP_Sub_2 L) } } #endif