Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / engine / ComponentInstance.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 "ComponentInstance.hxx"
20 #include "Container.hxx"
21
22 #include <iostream>
23 #include <sstream>
24
25 //#define _DEVDEBUG_
26 #include "YacsTrace.hxx"
27
28 using namespace YACS::ENGINE;
29 using namespace std;
30
31 const char ComponentInstance::KIND[]="";
32 int ComponentInstance::_total = 0;
33
34
35 const char ComponentInstance::NULL_FILE_REPR[]="No repr specified for ComponentInstance";
36
37 void ComponentInstance::setContainer(Container *cont)
38 {
39   if (cont == _container) return;
40   
41   if(cont)
42     cont->checkCapabilityToDealWith(this);
43   if(_container)
44     _container->decrRef();
45   _container=cont;
46   if(_container)
47     _container->incrRef();
48 }
49
50 ComponentInstance::ComponentInstance(const std::string& name):_compoName(name),_isAttachedOnCloning(false),_container(0)
51 {
52   _numId = _total++;
53   stringstream instName;
54   instName << _compoName << "_" << _numId;
55   _instanceName = instName.str();
56 }
57
58 ComponentInstance::ComponentInstance(const ComponentInstance& other):_compoName(other._compoName),
59                                                                      _container(0),
60                                                                      _isAttachedOnCloning(other._isAttachedOnCloning)
61 {
62   _numId = _total++;
63   stringstream instName;
64   instName << _compoName << "_" << _numId;
65   _instanceName = instName.str();
66   if(other._container)
67     _container=other._container->clone();
68 }
69
70 ComponentInstance::~ComponentInstance()
71 {
72   if(_container)
73     _container->decrRef();
74 }
75
76 /*!
77  * By calling this method the current container 'this' is not destined to be deeply copied on clone call.
78  */
79 void ComponentInstance::attachOnCloning() const
80 {
81   _isAttachedOnCloning=true;
82 }
83
84 std::string ComponentInstance::getFileRepr() const
85 {
86   return NULL_FILE_REPR;
87 }
88
89 /*!
90  * By calling this method the current container 'this' will be deeply copied on clone call.
91  */
92 void ComponentInstance::dettachOnCloning() const
93 {
94   _isAttachedOnCloning=false;
95 }
96
97 bool ComponentInstance::isAttachedOnCloning() const
98 {
99   return _isAttachedOnCloning;
100 }
101
102 string ComponentInstance::getKind() const
103 {
104   return KIND;
105 }