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