]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Test/RuntimeForEngineIntegrationTest.cxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / Test / RuntimeForEngineIntegrationTest.cxx
1 #include "RuntimeForEngineIntegrationTest.hxx"
2 #include "ComponentInstanceTest.hxx"
3 #include "ToyNode.hxx"
4 #include <sstream>
5
6 using namespace std;
7 using namespace YACS::ENGINE;
8
9 void RuntimeForEngineIntegrationTest::setRuntime()
10 {
11   if (! Runtime::_singleton)
12     Runtime::_singleton = new RuntimeForEngineIntegrationTest;
13 }
14
15 ElementaryNode* RuntimeForEngineIntegrationTest::createNode(const string& implementation, const string& name) throw(Exception)
16 {
17   if (implementation == ToyNode::MY_IMPL_NAME)
18     return new ToyNode(name);
19   else if(implementation == LimitNode::MY_IMPL_NAME)
20     return new LimitNode(name);
21   string what="RuntimeForEngineIntegrationTest does not handle this implementation: " + implementation;
22   throw Exception(what);
23 }
24
25 InputPort* RuntimeForEngineIntegrationTest::createInputPort(const string& name, const string& impl, Node * node, TypeCode * type)
26 {
27   if(impl == ToyNode::MY_IMPL_NAME)
28     {
29       if(type->kind()!=Double)
30         throw Exception("Invalid type");
31       return new InputToyPort(name, node);
32     }
33   else if(impl == LimitNode::MY_IMPL_NAME)
34     throw Exception("InputPort creation not allowed for LimitNode");
35   ostringstream msg;
36   msg << "Cannot create " << impl << " OutputPort" ;
37   throw Exception(msg.str());
38 }
39
40 OutputPort* RuntimeForEngineIntegrationTest::createOutputPort(const string& name, const string& impl, Node * node, TypeCode * type)
41 {
42   if(impl == ToyNode::MY_IMPL_NAME)
43     {
44       if(type->kind()!=Double && type->kind()!=Int)
45         throw Exception("Invalid type");
46       return new OutputToyPort(name, node, type);
47     }
48   else if(impl == LimitNode::MY_IMPL_NAME)
49     throw Exception("OutputPort creation not allowed for LimitNode");
50   stringstream msg;
51   msg << "Cannot create " << impl << " OutputPort" ;
52   throw Exception(msg.str());
53 }
54
55 InputPort* RuntimeForEngineIntegrationTest::adapt(InputPort* source, const string& impl,TypeCode * type) throw (ConversionException)
56 {
57   return new ProxyPort(source);
58 }
59
60 ComponentInstance* RuntimeForEngineIntegrationTest::createComponentInstance(const std::string& name, const std::string& kind)
61 {
62   if(kind==ToyNode1S::KIND)
63     return new ComponentInstanceTest1(name);
64   else if(kind==ToyNode2S::KIND)
65     return new ComponentInstanceTest2(name);
66   else
67     {
68       string msg("RuntimeForEngineIntegrationTest::createComponentInstance : Unable to crate component with kind \"");
69       msg+=kind; msg+="\"";
70       throw Exception(msg);
71     }
72 }