1 // Copyright (C) 2006-2020 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, or (at your option) any later version.
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
20 #include "CppNode.hxx"
21 #include "InputPort.hxx"
22 #include "OutputPort.hxx"
23 #include "CppPorts.hxx"
24 #include "CppContainer.hxx"
25 #include "CppComponent.hxx"
26 #include "TypeCode.hxx"
33 #include "YacsTrace.hxx"
35 using namespace YACS::ENGINE;
38 const char CppNode::IMPL_NAME[]="Cpp";
39 const char CppNode::KIND[]="Cpp";
41 CppNode::CppNode(const CppNode& other,ComposedNode *father):ServiceNode(other,father),
43 _componentName(other._componentName)
45 DEBTRACE("CppNode::CppNode");
46 _implementation=IMPL_NAME;
49 CppNode::CppNode(const std::string & name) : ServiceNode(name), _run(NULL)
51 _implementation=IMPL_NAME;
54 void CppNode::setCode(const std::string & componentName, const std::string & method)
57 _componentName = componentName;
61 void CppNode::setFunc(MYRUN fonc) {
65 _component->decrRef();
79 setRef(_componentName);
84 void CppNode::execute()
86 std::list<InputPort *>::iterator iter1;
89 nIn = _setOfInputPort.size();
90 nOut = _setOfOutputPort.size();
92 Any ** In = new Any * [nIn], ** Out = new Any * [nOut];
97 for(iter1 = _setOfInputPort.begin(), it = 0; iter1 != _setOfInputPort.end();
100 InputCppPort *p = dynamic_cast<InputCppPort *> (*iter1);
101 In[it] = p->getCppObj();
106 CppComponent * _componentC = dynamic_cast<CppComponent *>(_component);
108 throw YACS::Exception("CppNode::execute : bad type of component");
109 _componentC->run(_method.c_str(), nIn, nOut, In, Out);
112 _run(nIn, nOut, In, Out);
115 std::list<OutputPort *>::iterator iter2;
116 for(iter2 = _setOfOutputPort.begin(), it=0; iter2 != _setOfOutputPort.end(); iter2++, it++)
118 OutputCppPort *p = dynamic_cast<OutputCppPort *> (*iter2);
120 //decref it, we don't need it more
122 DEBTRACE("ref count: " << Out[it]->getRefCnt());
125 catch (YACS::Exception & e) {
135 ServiceNode* CppNode::createNode(const std::string& name)
137 CppNode* node= new CppNode(name);
138 node->setComponent(_component);
142 //! Clone the node : must also clone the component instance ?
143 Node * CppNode::simpleClone(ComposedNode *father, bool editionOnly) const
145 return new CppNode(*this,father);
148 //! Create a new node of same type with a given name
149 CppNode* CppNode::cloneNode(const std::string& name)
151 DEBTRACE("CppNode::cloneNode");
152 CppNode* n=new CppNode(name);
158 n->setCode(_componentName, _method);
160 list<InputPort *>::iterator iter;
161 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
163 InputCppPort *p=(InputCppPort *)*iter;
164 DEBTRACE("port name: " << p->getName());
165 DEBTRACE("port kind: " << p->edGetType()->kind());
166 n->edAddInputPort(p->getName(),p->edGetType());
168 list<OutputPort *>::iterator iter2;
169 for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
171 OutputCppPort *p=(OutputCppPort *)*iter2;
172 DEBTRACE("port name: " << p->getName());
173 DEBTRACE("port kind: " << p->edGetType()->kind());
174 n->edAddOutputPort(p->getName(),p->edGetType());