RTXI  3.0.0
The Real-Time eXperiment Interface Reference Manual
io.hpp
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah,
4  Will Cornell Medical College
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #ifndef IO_H
22 #define IO_H
23 
24 #include <array>
25 #include <limits>
26 #include <string>
27 #include <vector>
28 
30 
39 namespace IO
40 {
41 
42 constexpr size_t INVALID_BLOCK_ID = std::numeric_limits<size_t>::max();
43 
51 enum flags_t : size_t
52 {
53  OUTPUT = 0,
55  UNKNOWN
56 };
57 
68 typedef struct channel_t
69 {
70  std::string name;
71  std::string description;
72  IO::flags_t flags = IO::UNKNOWN; // IO::INPUT or IO::OUTPUT
74 
78 class Block
79 {
80 public:
94  Block(std::string blockname,
95  const std::vector<channel_t>& channels,
96  bool isdependent); // default constructor
97  Block(const Block& block) = default; // copy constructor
98  Block& operator=(const Block& block) = default; // copy assignment operator
99  Block(Block&&) = delete; // move constructor
100  Block& operator=(Block&&) = delete; // move assignment operator
101  virtual ~Block() = default;
102 
108  std::string getName() const { return name; }
109 
116  size_t getCount(flags_t type) const;
117 
125  std::string getChannelName(IO::flags_t type, size_t index) const;
126 
133  std::string getChannelDescription(IO::flags_t type, size_t index) const;
134 
150  void writeinput(size_t index, const double& data);
151 
162  const double& readPort(IO::flags_t direction, size_t index);
163 
173  bool dependent() const { return this->isInputDependent; }
174 
180  bool getActive() const { return this->active; }
181 
188  void setActive(bool act) { this->active = act; }
189 
195  void assignID(size_t block_id) { this->id = block_id; }
196 
202  size_t getID() const { return this->id; }
203 
204 protected:
218  double& readinput(size_t index);
219 
226  void writeoutput(size_t index, const double& data);
227 
228 private:
229  size_t id = INVALID_BLOCK_ID;
230  typedef struct port_t
231  {
232  double buff_value = 0.0;
233  double value = 0.0;
234  IO::channel_t channel_info;
235  } port_t;
236  std::string name;
237  bool isInputDependent;
238  std::array<std::vector<port_t>, IO::UNKNOWN> ports;
239  bool active = false;
240 }; // class Block
241 
256 typedef struct endpoint
257 {
258  IO::Block* block = nullptr;
259  size_t port = 0;
261  bool operator==(const endpoint& rhs) const
262  {
263  return (this->block == rhs.block) && (this->port == rhs.port)
264  && (this->direction == rhs.direction);
265  }
266  bool operator!=(const endpoint& rhs) const { return !operator==(rhs); }
268 
269 } // namespace IO
270 
271 #endif // IO_H
Definition: io.hpp:79
double & readinput(size_t index)
Definition: io.cpp:70
void writeoutput(size_t index, const double &data)
Definition: io.cpp:80
Block & operator=(const Block &block)=default
Block(const Block &block)=default
bool dependent() const
Definition: io.hpp:173
Block(std::string blockname, const std::vector< channel_t > &channels, bool isdependent)
Definition: io.cpp:29
bool getActive() const
Definition: io.hpp:180
std::string getChannelName(IO::flags_t type, size_t index) const
Definition: io.cpp:52
size_t getID() const
Definition: io.hpp:202
std::string getChannelDescription(IO::flags_t type, size_t index) const
Definition: io.cpp:58
void setActive(bool act)
Definition: io.hpp:188
size_t getCount(flags_t type) const
Definition: io.cpp:46
Block(Block &&)=delete
virtual ~Block()=default
Block & operator=(Block &&)=delete
void writeinput(size_t index, const double &data)
Definition: io.cpp:65
void assignID(size_t block_id)
Definition: io.hpp:195
const double & readPort(IO::flags_t direction, size_t index)
Definition: io.cpp:85
std::string getName() const
Definition: io.hpp:108
Connection Oriented Classes.
Definition: io.hpp:40
flags_t
Definition: io.hpp:52
@ UNKNOWN
Definition: io.hpp:55
@ INPUT
Definition: io.hpp:54
@ OUTPUT
Definition: io.hpp:53
struct IO::channel_t channel_t
struct IO::endpoint endpoint
constexpr size_t INVALID_BLOCK_ID
Definition: io.hpp:42
IO::flags_t flags
Definition: io.hpp:72
std::string name
Definition: io.hpp:70
std::string description
Definition: io.hpp:71
IO::flags_t direction
Definition: io.hpp:260
size_t port
Definition: io.hpp:259
bool operator==(const endpoint &rhs) const
Definition: io.hpp:261
IO::Block * block
Definition: io.hpp:258
bool operator!=(const endpoint &rhs) const
Definition: io.hpp:266