forked from nical/kiwi
/
WriterOutputPort.hpp
168 lines (138 loc) · 5.08 KB
/
WriterOutputPort.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright (c) 2010 Nicolas Silva
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of the nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef KIWI_CORE_WRITEROUTPUTPORT_HPP
#define KIWI_CORE_WRITEROUTPUTPORT_HPP
#include <list>
#include "kiwi/core/Tags.hpp"
#include "kiwi/utils/UnorderedArray.hpp"
#include "kiwi/utils/Connector.hpp"
namespace kiwi{
namespace core{
class WriterInputPort;
class Node;
/**
* @brief Generic output port class for Writer and Writer interface.
*
* An instance of this class is hold by a Node for each of it's outputs.
* Port classes are designed to do most of the external actions on Node/Filter which are
* doning connections between Nodes and retrieving informations on their input/output data.
*
* Each port has a name which use is facultative has they are truely accessed using an integer index.
*/
class WriterOutputPort
: public kiwi::utils::Connector<WriterOutputPort, WriterInputPort, 100, WRITER>
{
friend class Node;
public:
friend class WriterInputPort;
typedef kiwi::utils::Connector<WriterOutputPort, WriterInputPort, 100, WRITER> PortConnector;
// --------------------------------------------------------------------
typedef std::list< WriterInputPort* > connectionList;
// --------------------------------------------------------------------
/**
* @brief Constructor.
* @todo The second argument will disapear in next version.
*/
WriterOutputPort(Node* myNode, Container* data = 0);
/**
* @brief Returns the index of this port.
*/
portIndex_t index() const ;
/**
* @brief Returns a pointer to the Node containing this port.
*/
Node* node() const ;
/**
* @brief Returns true if this port has sub-ports.
*
* This happens when the port is associated to a composite Container.
*/
bool isComposite() const;
WriterOutputPort& subPort(kiwi::uint32_t i){
if(i >= _subPorts.size() )
return *this;
return *_subPorts[i];
}
kiwi::uint32_t nbSubPorts() const { return _subPorts.size(); }
template<class T>
T* getContainer() { return dynamic_cast<T*>(_container); }
ReaderOutputPort* associatedReaderOutputPort(){
ScopedBlockMacro( ___scp, "WriterOutputPort::associatedReaderOutputPort");
if(!_associatedReaderOutputPort)
Debug::print() << "warning: no associated port\n";
return _associatedReaderOutputPort;
}
/**
* @brief Returns this port's Type as a string.
*/
string name() const;
/**
* @brief Returns this port's Type as a string.
*/
Tags tags() const;
/**
* @brief Port compatibility check based on the type string.
*/
bool isCompatible(WriterInputPort& input);
/**
* @brief returns true if this port is enabled.
*
* A port as to be enabloed to be connected.
* By default a port is enabled.
*/
bool isEnabled() const ;
/**
* @brief Returns a list of the connected input ports.
*
* Returns a std::list<kiwi::core::InputPort<T> of the port connected to this port
*/
connectionList connections() const ;
bool connect(WriterInputPort& inputPort);
bool connect(WriterInputPort* inputPort);
protected:
/**
* @brief Used internally by kiwi::core::Node to perform port binding.
*
* @see kiwi::core::Node::bindPort
*/
void bind( WriterOutputPort& port );
void unBind();
void setData( Container* data );
private:
Node* _node;
Container* _container;
// port binding
utils::UnorderedArray<WriterOutputPort*> _linkedOutputPorts;
// to use with composite containers
utils::UnorderedArray<WriterOutputPort*> _subPorts;
// to associate Writer and Reader of the same data
ReaderOutputPort* _associatedReaderOutputPort;
};
}// namespace
}// namespace
#endif