Salome HOME
Updated copyright comment
[modules/yacs.git] / src / engine / Test / RuntimeForEngineIntegrationTest.cxx
1 // Copyright (C) 2006-2024  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 "RuntimeForEngineIntegrationTest.hxx"
21 #include "ComponentInstanceTest.hxx"
22 #include "Exception.hxx"
23 #include "ToyNode.hxx"
24 #include "TypeCode.hxx"
25 #include <sstream>
26 #include <string.h>
27
28
29 using namespace YACS::ENGINE;
30
31 void RuntimeForEngineIntegrationTest::setRuntime()
32 {
33   if (! Runtime::_singleton)
34     Runtime::_singleton = new RuntimeForEngineIntegrationTest;
35 }
36
37 std::vector< std::pair<std::string,int> > RuntimeForEngineIntegrationTest::getCatalogOfComputeNodes() const
38 {
39   return std::vector< std::pair<std::string,int> >();
40 }
41
42 ElementaryNode* RuntimeForEngineIntegrationTest::createNode(const std::string& implementation, const std::string& name)
43 {
44   if (implementation == ToyNode::MY_IMPL_NAME)
45     return new ToyNode(name);
46   else if(implementation == LimitNode::MY_IMPL_NAME)
47     return new LimitNode(name);
48   std::string what="RuntimeForEngineIntegrationTest does not handle this implementation: " + implementation;
49   throw YACS::Exception(what);
50 }
51
52 InputPort* RuntimeForEngineIntegrationTest::createInputPort(const std::string& name, const std::string& impl, Node * node, TypeCode * type)
53 {
54   if(impl == ToyNode::MY_IMPL_NAME)
55     {
56       if(type->kind()!=Double)
57         throw Exception("Invalid type");
58       return new InputToyPort(name, node);
59     }
60   else if(impl == LimitNode::MY_IMPL_NAME)
61     throw Exception("InputPort creation not allowed for LimitNode");
62   std::ostringstream msg;
63   msg << "Cannot create " << impl << " OutputPort" ;
64   throw YACS::Exception(msg.str());
65 }
66
67 OutputPort* RuntimeForEngineIntegrationTest::createOutputPort(const std::string& name, const std::string& impl, Node * node, TypeCode * type)
68 {
69   if(impl == ToyNode::MY_IMPL_NAME)
70     {
71       if(type->kind()!=Double && type->kind()!=Int)
72         throw Exception("Invalid type");
73       return new OutputToyPort(name, node, type);
74     }
75   else if(impl == LimitNode::MY_IMPL_NAME)
76     throw Exception("OutputPort creation not allowed for LimitNode");
77   std::stringstream msg;
78   msg << "Cannot create " << impl << " OutputPort" ;
79   throw Exception(msg.str());
80 }
81
82 InputPort* RuntimeForEngineIntegrationTest::adapt(InputPort* source, const std::string& impl,TypeCode * type,bool init)
83 {
84   return new ProxyPort(source);
85 }
86
87 InputPort* RuntimeForEngineIntegrationTest::adapt(InPropertyPort* source, const std::string& impl, TypeCode * type, bool init)
88 {
89   return adapt((InputPort *)source, impl, type, init);
90 }
91
92 ComponentInstance* RuntimeForEngineIntegrationTest::createComponentInstance(const std::string& name, const std::string& kind)
93 {
94   if(kind==ToyNode1S::KIND)
95     return new ComponentInstanceTest1(name);
96   else if(kind==ToyNode2S::KIND)
97     return new ComponentInstanceTest2(name);
98   else
99     {
100       std::string msg("RuntimeForEngineIntegrationTest::createComponentInstance : Unable to crate component with kind \"");
101       msg+=kind; msg+="\"";
102       throw Exception(msg);
103     }
104 }