Vuo  2.0.0
VuoCompilerCable.cc
Go to the documentation of this file.
1 
10 #include <sstream>
11 
12 #include "VuoCable.hh"
13 #include "VuoCompilerCable.hh"
15 #include "VuoCompilerNode.hh"
16 #include "VuoCompilerPortClass.hh"
17 #include "VuoNode.hh"
18 #include "VuoNodeClass.hh"
19 #include "VuoPort.hh"
20 
24 VuoCompilerCable::VuoCompilerCable(VuoCompilerNode * fromNode, VuoCompilerPort * fromPort, VuoCompilerNode * toNode, VuoCompilerPort * toPort, bool addCableToPorts)
25  : VuoBaseDetail<VuoCable>("VuoCompilerCable",
26  new VuoCable( fromNode? fromNode->getBase() : NULL,
27  fromPort? fromPort->getBase() : NULL,
28  toNode? toNode->getBase() : NULL,
29  toPort? toPort->getBase() : NULL,
30  addCableToPorts))
31 {
32  getBase()->setCompiler(this);
33  isAlwaysEventOnly = false;
34  isHidden = false;
35 }
36 
42 {
43  this->isAlwaysEventOnly = isEventOnly;
44 }
45 
51 {
52  return this->isAlwaysEventOnly;
53 }
54 
58 void VuoCompilerCable::setHidden(bool hidden)
59 {
60  this->isHidden = hidden;
61 }
62 
67 {
68  return this->isHidden;
69 }
70 
74 bool VuoCompilerCable::portHasData(VuoPort *port)
75 {
76  return (port &&
78  (port->getClass()->hasCompiler() && static_cast<VuoCompilerPortClass *>(port->getClass()->getCompiler())->getDataVuoType())));
79 }
80 
86 {
87  ostringstream declaration;
88 
89  VuoNode *fromNode = getBase()->getFromNode();
90  VuoPort *fromPort = getBase()->getFromPort();
91  VuoNode *toNode = getBase()->getToNode();
92  VuoPort *toPort = getBase()->getToPort();
93 
94  if ((fromNode || getBase()->isPublishedInputCable())
95  && (toNode || getBase()->isPublishedOutputCable())
96  && fromPort && toPort)
97  {
98  string fromNodeIdentifier = (getBase()->isPublishedInputCable() ?
100  (fromNode->hasCompiler() ?
101  fromNode->getCompiler()->getGraphvizIdentifier() :
102  fromNode->getRawGraphvizIdentifier()));
103  string toNodeIdentifier = (getBase()->isPublishedOutputCable() ?
105  (toNode->hasCompiler() ?
106  toNode->getCompiler()->getGraphvizIdentifier() :
107  toNode->getRawGraphvizIdentifier()));
108 
109  declaration << fromNodeIdentifier << ":" << fromPort->getClass()->getName() << " -> "
110  << toNodeIdentifier << ":" << toPort->getClass()->getName();
111 
112  // Cable attributes
113  bool isExplicitlyEventOnly = (isAlwaysEventOnly && portHasData( getBase()->getFromPort() ) && portHasData( getBase()->getToPort() ));
114  if (isExplicitlyEventOnly || isHidden)
115  {
116  declaration << " [";
117 
118  if (isExplicitlyEventOnly)
119  declaration << "event=true";
120 
121  if (isExplicitlyEventOnly && isHidden)
122  declaration << " ";
123 
124  if (isHidden)
125  declaration << "style=invis";
126 
127  declaration << "]";
128  }
129 
130  declaration << ";";
131  }
132 
133  return declaration.str();
134 }
135 
140 {
141  if (isAlwaysEventOnly)
142  return false;
143 
144  VuoPort *fromPort = getBase()->getFromPort();
145  VuoPort *toPort = getBase()->getToPort();
146 
147  bool fromPortHasData = portHasData(fromPort);
148  bool toPortHasData = portHasData(toPort);
149 
150  // If not currently connected to a 'From' port, decide on the basis of the 'To' port alone.
151  if (! fromPort)
152  return toPortHasData;
153 
154  // If not currently connected to a 'To' port, decide on the basis of the 'From' port alone.
155  else if (! toPort)
156  return fromPortHasData;
157 
158  // If connected at both ends, the cable carries data if and only if each of its connected ports contain data.
159  else
160  return (fromPortHasData && toPortHasData);
161 }
162 
166 void VuoCompilerCable::generateTransmission(Module *module, BasicBlock *block, Value *toNodeContextValue, Value *toPortContextValue,
167  Value *outputDataValue, bool shouldTransmitEvent)
168 {
169  VuoCompilerInputEventPort *inputEventPort = static_cast<VuoCompilerInputEventPort *>(getBase()->getToPort()->getCompiler());
170 
171  if (outputDataValue)
172  inputEventPort->generateReplaceData(module, block, toNodeContextValue, outputDataValue, toPortContextValue);
173 
174  if (shouldTransmitEvent)
175  inputEventPort->generateStoreEvent(module, block, toNodeContextValue, true, toPortContextValue);
176 }