The MAUVE Toolchain
HasPort.hpp
1 /*
2  * Copyright 2017 ONERA
3  *
4  * This file is part of the MAUVE Runtime project.
5  *
6  * MAUVE Runtime is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License version 3 as
8  * published by the Free Software Foundation.
9  *
10  * MAUVE Runtime is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with MAUVE. If not, see <https://www.gnu.org/licenses/lgpl-3.0>.
17  */
18 #ifndef MAUVE_RUNTIME_HAS_PORT_HPP
19 #define MAUVE_RUNTIME_HAS_PORT_HPP
20 
21 #include "Configurable.hpp"
22 #include <string>
23 #include <vector>
24 
25 namespace mauve {
26  namespace runtime {
27 
28  class AbstractPort;
29 
30  class EventPort;
31 
32  template <typename T>
33  class ReadPort;
34 
35  template <typename T>
36  class WritePort;
37 
38  template <typename R, typename ...P>
39  class CallPort;
40 
41  class HasPort : virtual public Configurable {
42  public:
43  HasPort();
44  virtual ~HasPort() noexcept;
45 
50  const std::vector<AbstractPort*> get_ports() const;
51 
52  AbstractPort* get_port(std::string const & name) const;
53 
54  std::size_t get_ports_size() const { return ports.size(); }
55 
56  AbstractPort* get_port(int index) const;
57 
58  void disconnect();
59 
60  protected:
69  template <typename PORT, typename ... PARAM>
70  PORT & mk_port(std::string const & name, PARAM ... parameters);
71 
72  EventPort & mk_event_port(std::string const & name);
73 
74  template <typename T>
75  ReadPort<T> & mk_read_port(std::string const & name, T default_value);
76 
77  template <typename T>
78  WritePort<T> & mk_write_port(std::string const & name);
79 
80  template <typename R, typename ...P>
81  CallPort<R, P...> mk_call_port(std::string const & name, R default_value);
82 
83  private:
84  std::vector<AbstractPort *> ports;
85  };
86 
87  // -------------------- Exceptions --------------------
89  struct AlreadyDefinedPort: public std::exception {
90  AlreadyDefinedPort(std::string const & name) throw() : name(name) {}
92  const std::string name;
94  virtual const char* what() const throw() {
95  std::string message = "Already Defined Port " + name;
96  return message.c_str();
97  }
98  };
99 
100  }
101 }
102 
103 #include "mauve/runtime/ipp/HasPort.ipp"
104 
105 #endif
const std::vector< AbstractPort * > get_ports() const
Get the ports of the shell.
const std::string name
Exception name.
Definition: HasPort.hpp:92
Definition: HasPort.hpp:33
virtual const char * what() const
Exception explanation.
Definition: HasPort.hpp:94
Definition: EventPort.hpp:28
Abstract Port class.
Definition: AbstractPort.hpp:35
Definition: HasPort.hpp:36
Definition: HasPort.hpp:41
The MAUVE namespace.
Definition: tracing.hpp:24
Configurable trait.
Definition: Configurable.hpp:25
PORT & mk_port(std::string const &name, PARAM...parameters)
Create a new port in this shell.
Definition: HasPort.ipp:30
Exception for Already Defined Ports.
Definition: HasPort.hpp:89
A Port to call a service.
Definition: CallPort.hpp:31