Atoms Crowd  7.0.0
Port.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <AtomsGraph/Globals.h>
11 
12 #include <string>
13 #include <vector>
14 #include <set>
15 
16 namespace AtomsGraph
17 {
18 
19  class Node;
20 
22  /*
23  This is the base class of all the ports type
24  */
25  class ATOMSGRAPH_EXPORT Port
26  {
27  public:
28 
29  typedef std::vector<Port*>::iterator port_iterator;
30 
31  typedef std::vector<Port*>::const_iterator const_port_iterator;
32 
34 
38  virtual std::string typeStr() const;
39 
41 
44  explicit Port(const std::string& name);
45 
47  /*
48  BasePort destructor
49  */
50  virtual ~Port();
51 
53  /*
54  \return return the name as a std string
55  */
56  inline std::string name() const;
57 
59  /*
60  The life of the port is handled by the node. A port should always be parented to a node.
61  \param node pointer to the baseNode that has this port
62  */
63  inline void setNode(Node* node);
64 
66  /*
67  \return BaseNode* parent node
68  */
69  inline Node* node();
70 
72  /*
73  Connect this port to another port.
74  The only connections allowed are from a input port to an output port. The ports must not be on the same node.
75  \param port BasePort* to connect to
76  */
77  bool connectTo(Port* port);
78 
80  /*
81  \param BasePort* port to break the connection to
82  */
83  bool disconnectFrom(Port* port);
84 
86  /*
87  \param ports vector used to return the list of connections
88  */
89  inline const std::vector<Port*>& getConnections() const;
90  inline std::vector<Port*>& getConnections();
91 
93  /*
94  If the port is an int port, so only one incoming connection is allowed,
95  so this is return the port connected to the input side of the connection
96  \return BasePort* port on the input side of the connection
97  */
98  inline Port* input() const;
99 
101  /*
102  \return size_t number of connected ports
103  */
104  inline size_t numConnections() const;
105 
107  /*
108  \return bool true if it's an input port
109  */
110  inline bool isInput() const;
111 
113  /*
114  \return bool true if it's an output port
115  */
116  inline bool isOutput() const;
117 
119  inline port_iterator begin();
120 
122  inline port_iterator end();
123 
125  inline const_port_iterator cbegin() const;
126 
128  inline const_port_iterator cend() const;
129 
131  virtual void copyValue(Port *other);
132 
134  virtual void reset();
135 
136  protected:
137 
139  friend class Node;
140 
142  inline void setAsInput(bool value);
143 
144  private:
145 
147  /*
148  Copy constructor not implemented
149  */
150  Port(const Port& other);
151 
153  /*
154  Assign operator not implemented
155  */
156  Port& operator=(const Port& other);
157 
158  private:
159 
161  std::vector<Port*> m_vConnections;
162 
164  std::string m_sName;
165 
167  Node* m_node;
168 
170  bool m_bIsInput;
171 
172  };
173 
174 }
175 
176 #include "Port.impl.h"
Definition: Node.h:31
BasePort class.
Definition: Port.h:26
Port(const std::string &name)
Constructor.
virtual std::string typeStr() const
Class type string.
virtual void copyValue(Port *other)
Copy the data from another port.
virtual void reset()
Reset the port to default value.
bool connectTo(Port *port)
Connect a port to another port.
virtual ~Port()
virtual destructor
bool disconnectFrom(Port *port)
Breaks connection between ports.
AtomsGraph namespace.
Definition: PosePort.h:15