/** * @file common/Model.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_MODEL #define COMMON_MODEL #include #include #include #include #include #include #include #include #include #include namespace artis { namespace common { template class ExternalEvent; template class InternalEvent; template class Bag; struct Port { unsigned int index; std::string name; }; typedef std::vector Ports; typedef std::map PortMap; template class Model { public: Model(const std::string &name) : _tl(0), _tn(0), _parent(0), _name(name), _inputs(0) {} virtual ~Model() { if (_inputs) { delete _inputs; } } // structure void add_in_port(const Port &port) { assert(not exist_in_port(port.index)); _in_ports.push_back(port.index); _in_port_map[port.index] = port.name; } void add_out_port(const Port &port) { assert(not exist_out_port(port.index)); _out_ports.push_back(port.index); _out_port_map[port.index] = port.name; } void delete_in_port(const Port &port) { assert(not exist_in_port(port.index)); _in_ports.erase(std::find(_in_ports.begin(), _in_ports.end(), port.index)); _in_port_map.erase(port.index); } void delete_out_port(const Port &port) { assert(not exist_out_port(port.index)); _out_ports.erase(std::find(_out_ports.begin(), _out_ports.end(), port.index)); _out_port_map.erase(port.index); } bool exist_in_port(unsigned int port_index) const { return _in_port_map.find(port_index) != _in_port_map.end(); } bool exist_out_port(unsigned int port_index) const { return _out_port_map.find(port_index) != _out_port_map.end(); } std::string get_in_port_name(unsigned int port_index) const { assert(exist_in_port(port_index)); return _in_port_map.find(port_index)->second; } size_t get_in_port_number() const { return _in_port_map.size(); } std::string get_out_port_name(unsigned int port_index) const { assert(exist_out_port(port_index)); return _out_port_map.find(port_index)->second; } size_t get_out_port_number() const { return _out_port_map.size(); } const std::string &get_name() const { return _name; } Model