1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "CppNode.hxx"
20 #include "InputPort.hxx"
21 #include "OutputPort.hxx"
22 #include "CppPorts.hxx"
23 #include "CppContainer.hxx"
24 #include "CppComponent.hxx"
31 #include "YacsTrace.hxx"
33 using namespace YACS::ENGINE;
36 const char CppNode::IMPL_NAME[]="Cpp";
37 const char CppNode::KIND[]="Cpp";
39 CppNode::CppNode(const CppNode& other,ComposedNode *father):ServiceNode(other,father),
41 _componentName(other._componentName)
43 DEBTRACE("CppNode::CppNode");
44 _implementation=IMPL_NAME;
47 CppNode::CppNode(const std::string & name) : ServiceNode(name), _run(NULL)
49 _implementation=IMPL_NAME;
52 void CppNode::setCode(const std::string & componentName, const std::string & method)
55 _componentName = componentName;
59 void CppNode::setFunc(MYRUN fonc) {
63 _component->decrRef();
77 setRef(_componentName);
82 void CppNode::execute()
84 std::list<InputPort *>::iterator iter1;
87 nIn = _setOfInputPort.size();
88 nOut = _setOfOutputPort.size();
90 Any ** In = new Any * [nIn], ** Out = new Any * [nOut];
95 for(iter1 = _setOfInputPort.begin(), it = 0; iter1 != _setOfInputPort.end();
98 InputCppPort *p = dynamic_cast<InputCppPort *> (*iter1);
99 In[it] = p->getCppObj();
104 CppComponent * _componentC = dynamic_cast<CppComponent *>(_component);
106 throw YACS::Exception("CppNode::execute : bad type of component");
107 _componentC->run(_method.c_str(), nIn, nOut, In, Out);
110 _run(nIn, nOut, In, Out);
113 std::list<OutputPort *>::iterator iter2;
114 for(iter2 = _setOfOutputPort.begin(), it=0; iter2 != _setOfOutputPort.end(); iter2++, it++)
116 OutputCppPort *p = dynamic_cast<OutputCppPort *> (*iter2);
118 //decref it, we don't need it more
120 DEBTRACE("ref count: " << Out[it]->getRefCnt());
123 catch (YACS::Exception & e) {
133 ServiceNode* CppNode::createNode(const std::string& name)
135 CppNode* node= new CppNode(name);
136 node->setComponent(_component);
140 //! Clone the node : must also clone the component instance ?
141 Node * CppNode::simpleClone(ComposedNode *father, bool editionOnly) const
143 return new CppNode(*this,father);
146 //! Create a new node of same type with a given name
147 CppNode* CppNode::cloneNode(const std::string& name)
149 DEBTRACE("CppNode::cloneNode");
150 CppNode* n=new CppNode(name);
156 n->setCode(_componentName, _method);
158 list<InputPort *>::iterator iter;
159 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
161 InputCppPort *p=(InputCppPort *)*iter;
162 DEBTRACE("port name: " << p->getName());
163 DEBTRACE("port kind: " << p->edGetType()->kind());
164 n->edAddInputPort(p->getName(),p->edGetType());
166 list<OutputPort *>::iterator iter2;
167 for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
169 OutputCppPort *p=(OutputCppPort *)*iter2;
170 DEBTRACE("port name: " << p->getName());
171 DEBTRACE("port kind: " << p->edGetType()->kind());
172 n->edAddOutputPort(p->getName(),p->edGetType());