The MAUVE Toolchain
Mux.hpp
1 /*
2  * Copyright 2017 ONERA
3  *
4  * This file is part of the MAUVE Base Components project.
5  *
6  * MAUVE Base Components 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 Base Components 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_BASE_MUX_HPP
19 #define MAUVE_BASE_MUX_HPP
20 
21 #include <array>
22 
23 #include <mauve/runtime.hpp>
24 
25 namespace mauve {
26  namespace base {
27 
33 template <typename T, int N>
36  runtime::Property<int> & select = mk_property("select", 1);
38  std::array< runtime::ReadPort<T>*, N> read_ports;
41 };
42 
48 template < typename T, int N >
49 struct MuxReadPortCore : public runtime::Core< MuxReadPortShell<T, N> > {
51  T read();
52 };
53 
59 template < typename T, int N >
60 struct MuxReadPortInterface : public runtime::Interface< MuxReadPortShell<T, N>,
61  MuxReadPortCore<T, N> >
62 {
65  runtime::ReadService<T> & read = this->template mk_read_service<T>("read", &CORE::read);
66 };
67 
68 template <typename T, int N>
71 
77 template <typename T, int N>
80  runtime::Property<int> & select = this->mk_property("select", 1);
82  runtime::WritePort<T> & write = mk_port< runtime::WritePort<T> >("write");
83 };
84 
90 template < typename T, int N >
91 struct MuxWriteServiceCore : public runtime::Core< MuxWriteServiceShell<T, N> >
92 {
98  void write(T value, int index) {
99  if (this->shell().select.get() == index)
100  this->shell().write.write(value);
101  };
102 };
103 
109 template < typename T, int N >
111  MuxWriteServiceShell<T, N>,
112  MuxWriteServiceCore<T, N> >
113 {
115  std::array< runtime::WriteService<T>*, N > write_services;
118 };
119 
120 template <typename T, int N>
123 
124  }
125 }
126 
127 #include "ipp/Mux.ipp"
128 
129 #endif // MAUVE_BASE_MUX_HPP
Definition: Interface.hpp:34
Multiplexer interface with read ports.
Definition: Mux.hpp:60
std::array< runtime::ReadPort< T > *, N > read_ports
Array of read ports.
Definition: Mux.hpp:38
Multiplexer core with read ports.
Definition: Mux.hpp:49
void write(T value, int index)
Write some data coming from a source.
Definition: Mux.hpp:98
Multiplexer shell with write services.
Definition: Mux.hpp:78
Definition: ReadPort.hpp:27
Multiplexer interface with write services.
Definition: Mux.hpp:110
Definition: HasPort.hpp:36
The MAUVE namespace.
Definition: tracing.hpp:24
MuxReadPortShell()
Constructor.
Definition: Mux.ipp:29
Multiplexer shell with read ports.
Definition: Mux.hpp:34
Definition: Architecture.hpp:38
Multiplexer core with write services.
Definition: Mux.hpp:91
A Shell is the interface of a component.
Definition: Shell.hpp:48
runtime::Property< int > & select
Property to select which input to forward.
Definition: Mux.hpp:36
The Core defines the methods of the component.
Definition: Core.hpp:38
std::array< runtime::WriteService< T > *, N > write_services
Array of write services.
Definition: Mux.hpp:115
Property< T > & mk_property(std::string const &name, T init_value)
Create a new property.
Definition: HasProperty.ipp:28