/** * @file common/States.hpp * @author The ARTIS Development Team * See the AUTHORS or Authors.txt file */ /* * ARTIS - the multimodeling and simulation environment * This file is a part of the ARTIS environment * * Copyright (C) 2013-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 COMMON_STATES_HPP #define COMMON_STATES_HPP #include #include #include #include namespace artis { namespace common { template class States { public: template struct element { unsigned int index; const std::string name; W Dyn::* var; element(unsigned int index, const std::string &name, W Dyn::* var) : index(index), name(name), var(var) {} }; States() {} virtual ~States() {} common::Any &get(unsigned int index) { return states.at(index); } const common::Any &get(unsigned int index) const { return states.at(index); } unsigned int state_number() const { return states.size(); } template void S_(std::initializer_list > list) { for (typename std::initializer_list >::iterator it = list.begin(); it != list.end(); ++it) { if (states.size() <= it->index) { states.resize(it->index + 1, common::Any()); state_names.resize(it->index + 1, std::string()); } states[it->index] = it->var; state_names[it->index] = it->name; } } virtual void restore(Dyn *model, const common::context::State