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