Salome HOME
On the road of homogeneous containers.
[modules/yacs.git] / src / engine / Test / ContainerTest.cxx
1 // Copyright (C) 2006-2014  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, 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 "ContainerTest.hxx"
21 #include "ComponentInstance.hxx"
22 #include "ToyNode.hxx"
23 #include <sstream>
24
25 using namespace std;
26 using namespace YACS::ENGINE;
27
28 unsigned ContainerTest::_counter = 0;
29
30 const char ContainerTest::SUPPORTED_COMP_KIND[] = "TESTKIND1";
31
32 unsigned ContainerTest2::_counter = 0;
33
34 const char ContainerTest2::SUPPORTED_COMP_KIND[] = "TESTKIND2";
35
36 ContainerTest::ContainerTest():_alreadyStarted(false),_myCounter(_counter++)
37 {
38 }
39
40 std::string ContainerTest::getPlacementInfo() const
41 {
42   ostringstream stream;
43   stream << "Cont#_" << _myCounter;
44   return stream.str();
45 }
46
47 bool ContainerTest::isAlreadyStarted(const ComponentInstance *inst) const
48 {
49   return _alreadyStarted;
50 }
51
52 void ContainerTest::start(const ComponentInstance *inst) throw(YACS::Exception)
53 {
54   if(_alreadyStarted)
55     throw Exception("ContainerTest already started !!!!");
56   _alreadyStarted=true;
57 }
58
59 Container *ContainerTest::clone() const
60 {
61   if(_isAttachedOnCloning)
62     {
63       incrRef();
64       return (Container *) this;
65     }
66   else
67     return new ContainerTest;
68 }
69
70 Container *ContainerTest::cloneAlways() const
71 {
72   return new ContainerTest;
73 }
74
75 void ContainerTest::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
76 {
77   if(inst->getKind()!=SUPPORTED_COMP_KIND)
78     throw Exception("ContainerTest not compatible with this type of instance.");
79 }
80
81 void ContainerTest::initAllContainers()
82 {
83   _counter=0;
84 }
85
86 ContainerTest2::ContainerTest2():_alreadyStarted(false),_myCounter(_counter++)
87 {
88 }
89
90 bool ContainerTest2::isAlreadyStarted(const ComponentInstance *inst) const
91 {
92   return _alreadyStarted;
93 }
94
95 void ContainerTest2::start(const ComponentInstance *inst) throw(YACS::Exception)
96 {
97   if(_alreadyStarted)
98     throw Exception("ContainerTest already started !!!!");
99   _alreadyStarted=true;
100 }
101
102 Container *ContainerTest2::clone() const
103 {
104   if(_isAttachedOnCloning)
105     {
106       incrRef();
107       return (Container *) this;
108     }
109   else
110     return new ContainerTest2;
111 }
112
113 Container *ContainerTest2::cloneAlways() const
114 {
115   return new ContainerTest2;
116 }
117
118 void ContainerTest2::initAllContainers()
119 {
120   _counter=0;
121 }
122
123 void ContainerTest2::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
124 {
125   if(inst->getKind()!=SUPPORTED_COMP_KIND)
126     throw Exception("ContainerTest not compatible with this type of instance.");
127 }