Salome HOME
234ff1ddc45ac8ebb3d091fcffb7e190a1d0f93c
[modules/yacs.git] / src / engine / Test / ContainerTest.cxx
1 #include "ContainerTest.hxx"
2 #include "ComponentInstance.hxx"
3 #include "ToyNode.hxx"
4 #include <sstream>
5
6 using namespace std;
7 using namespace YACS::ENGINE;
8
9 unsigned ContainerTest::_counter = 0;
10
11 const char ContainerTest::SUPPORTED_COMP_KIND[] = "TESTKIND1";
12
13 unsigned ContainerTest2::_counter = 0;
14
15 const char ContainerTest2::SUPPORTED_COMP_KIND[] = "TESTKIND2";
16
17 ContainerTest::ContainerTest():_alreadyStarted(false),_myCounter(_counter++)
18 {
19 }
20
21 std::string ContainerTest::getPlacementInfo() const
22 {
23   ostringstream stream;
24   stream << "Cont#_" << _myCounter;
25   return stream.str();
26 }
27
28 bool ContainerTest::isAlreadyStarted() const
29 {
30   return _alreadyStarted;
31 }
32
33 void ContainerTest::start() throw(Exception)
34 {
35   if(_alreadyStarted)
36     throw Exception("ContainerTest already started !!!!");
37   _alreadyStarted=true;
38 }
39
40 Container *ContainerTest::clone() const
41 {
42   if(_isAttachedOnCloning)
43     {
44       incrRef();
45       return (Container *) this;
46     }
47   else
48     return new ContainerTest;
49 }
50
51 void ContainerTest::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(Exception)
52 {
53   if(inst->getKind()!=SUPPORTED_COMP_KIND)
54     throw Exception("ContainerTest not compatible with this type of instance.");
55 }
56
57 void ContainerTest::initAllContainers()
58 {
59   _counter=0;
60 }
61
62 ContainerTest2::ContainerTest2():_alreadyStarted(false),_myCounter(_counter++)
63 {
64 }
65
66 bool ContainerTest2::isAlreadyStarted() const
67 {
68   return _alreadyStarted;
69 }
70
71 void ContainerTest2::start() throw(Exception)
72 {
73   if(_alreadyStarted)
74     throw Exception("ContainerTest already started !!!!");
75   _alreadyStarted=true;
76 }
77
78 Container *ContainerTest2::clone() const
79 {
80   if(_isAttachedOnCloning)
81     {
82       incrRef();
83       return (Container *) this;
84     }
85   else
86     return new ContainerTest2;
87 }
88
89 void ContainerTest2::initAllContainers()
90 {
91   _counter=0;
92 }
93
94 void ContainerTest2::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(Exception)
95 {
96   if(inst->getKind()!=SUPPORTED_COMP_KIND)
97     throw Exception("ContainerTest not compatible with this type of instance.");
98 }