Version: 9.16.0
CppNode.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
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.
7//
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.
12//
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
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
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"
27
28#include <iostream>
29#include <set>
30#include <sstream>
31
32//#define _DEVDEBUG_
33#include "YacsTrace.hxx"
34
35using namespace YACS::ENGINE;
36using namespace std;
37
38const char CppNode::IMPL_NAME[]="Cpp";
39const char CppNode::KIND[]="Cpp";
40
41CppNode::CppNode(const CppNode& other,ComposedNode *father):ServiceNode(other,father),
42 _run(other._run),
43 _componentName(other._componentName)
44{
45 DEBTRACE("CppNode::CppNode");
47}
48
49CppNode::CppNode(const std::string & name) : ServiceNode(name), _run(NULL)
50{
52}
53
54void CppNode::setCode(const std::string & componentName, const std::string & method)
55{
56 _method = method;
57 _componentName = componentName;
58 _run = NULL;
59}
60
62
63 if (_component)
64 {
66 _component = NULL;
67 _componentName = "";
68 _method = "";
69 _component = NULL;
70 }
71 _run = fonc;
72}
73
75{
76 if (_run) return;
77
78 if (!_component) {
80 }
82}
83
85{
86 std::list<InputPort *>::iterator iter1;
87 int nIn, nOut, it;
88
89 nIn = _setOfInputPort.size();
90 nOut = _setOfOutputPort.size();
91
92 Any ** In = new Any * [nIn], ** Out = new Any * [nOut];
93
94 try
95 {
96
97 for(iter1 = _setOfInputPort.begin(), it = 0; iter1 != _setOfInputPort.end();
98 iter1++, it++)
99 {
100 InputCppPort *p = dynamic_cast<InputCppPort *> (*iter1);
101 In[it] = p->getCppObj();
102 }
103
104 if (_component)
105 {
106 CppComponent * _componentC = dynamic_cast<CppComponent *>(_component);
107 if (!_componentC)
108 throw YACS::Exception("CppNode::execute : bad type of component");
109 _componentC->run(_method.c_str(), nIn, nOut, In, Out);
110 }
111 else if (_run)
112 _run(nIn, nOut, In, Out);
113
114 //output parameters
115 std::list<OutputPort *>::iterator iter2;
116 for(iter2 = _setOfOutputPort.begin(), it=0; iter2 != _setOfOutputPort.end(); iter2++, it++)
117 {
118 OutputCppPort *p = dynamic_cast<OutputCppPort *> (*iter2);
119 p->put(Out[it]);
120 //decref it, we don't need it more
121 Out[it]->decrRef();
122 DEBTRACE("ref count: " << Out[it]->getRefCnt());
123 }
124 }
125 catch (YACS::Exception & e) {
126 delete [] In;
127 delete [] Out;
128 throw e;
129 }
130
131 delete [] In;
132 delete [] Out;
133}
134
135ServiceNode* CppNode::createNode(const std::string& name)
136{
137 CppNode* node= new CppNode(name);
139 return node;
140}
141
143Node * CppNode::simpleClone(ComposedNode *father, bool editionOnly) const
144{
145 return new CppNode(*this,father);
146}
147
149CppNode* CppNode::cloneNode(const std::string& name)
150{
151 DEBTRACE("CppNode::cloneNode");
152 CppNode* n=new CppNode(name);
153
154 if (_run)
155 n->setFunc(_run);
156
157 if (_component)
158 n->setCode(_componentName, _method);
159
160 list<InputPort *>::iterator iter;
161 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
162 {
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());
167 }
168 list<OutputPort *>::iterator iter2;
169 for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
170 {
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());
175 }
176 return n;
177}
178
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
: Interface for management of storage of data formated dynamically in its TypeCode....
Definition: Any.hxx:79
Base class for all composed nodes.
std::string getName() const
void run(const char *service, int nbIn, int nbOut, Any **argIn, Any **argOut)
Class for C++ Nodes (in process component)
Definition: CppNode.hxx:47
void setFunc(MYRUN fonc)
Definition: CppNode.cxx:61
std::string _componentName
Definition: CppNode.hxx:65
void setCode(const std::string &componentName, const std::string &service)
Definition: CppNode.cxx:54
CppNode * cloneNode(const std::string &name)
Create a new node of same type with a given name.
Definition: CppNode.cxx:149
Node * simpleClone(ComposedNode *father, bool editionOnly) const
Clone the node : must also clone the component instance ?
Definition: CppNode.cxx:143
virtual void load()
Load the component associated to the node.
Definition: CppNode.cxx:74
CppNode(const CppNode &other, ComposedNode *father)
Definition: CppNode.cxx:41
virtual ServiceNode * createNode(const std::string &name)
Definition: CppNode.cxx:135
virtual void execute()
Definition: CppNode.cxx:84
static const char IMPL_NAME[]
Definition: CppNode.hxx:61
std::list< InputPort * > _setOfInputPort
std::list< OutputPort * > _setOfOutputPort
Class for C++ Ports.
Definition: CppPorts.hxx:40
Base class for all nodes.
Definition: Node.hxx:70
std::string _implementation
Definition: Node.hxx:97
Class for calculation node associated with a component service.
Definition: ServiceNode.hxx:35
virtual void setRef(const std::string &ref)
Associate a new component instance to this service node.
virtual void load()
Load the component associated to the node.
Definition: ServiceNode.cxx:90
ComponentInstance * _component
Definition: ServiceNode.hxx:60
virtual void setComponent(ComponentInstance *compo)
Associate an existing component instance to this service node AND check the consistency regarding the...
Proc * p
Definition: driver.cxx:216
void(* MYRUN)(int nbin, int nbout, YACS::ENGINE::Any **in, YACS::ENGINE::Any **out)
Definition: CppNode.hxx:36