Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / engine / ComponentInstance.cxx
1 #include "ComponentInstance.hxx"
2 #include "Container.hxx"
3
4 #include <iostream>
5 #include <sstream>
6
7 //#define _DEVDEBUG_
8 #include "YacsTrace.hxx"
9
10 using namespace YACS::ENGINE;
11 using namespace std;
12
13 const char ComponentInstance::KIND[]="";
14 int ComponentInstance::_total = 0;
15
16
17 const char ComponentInstance::NULL_FILE_REPR[]="No repr specified for ComponentInstance";
18
19 void ComponentInstance::setContainer(Container *cont)
20 {
21   if (cont == _container) return;
22   
23   if(cont)
24     cont->checkCapabilityToDealWith(this);
25   if(_container)
26     _container->decrRef();
27   _container=cont;
28   if(_container)
29     _container->incrRef();
30 }
31
32 ComponentInstance::ComponentInstance(const std::string& name):_compoName(name),_isAttachedOnCloning(false),_container(0)
33 {
34   _numId = _total++;
35   stringstream instName;
36   instName << _compoName << "_" << _numId;
37   _instanceName = instName.str();
38 }
39
40 ComponentInstance::ComponentInstance(const ComponentInstance& other):_compoName(other._compoName),
41                                                                      _container(0),
42                                                                      _isAttachedOnCloning(other._isAttachedOnCloning)
43 {
44   _numId = _total++;
45   stringstream instName;
46   instName << _compoName << "_" << _numId;
47   _instanceName = instName.str();
48   if(other._container)
49     _container=other._container->clone();
50 }
51
52 ComponentInstance::~ComponentInstance()
53 {
54   if(_container)
55     _container->decrRef();
56 }
57
58 /*!
59  * By calling this method the current container 'this' is not destined to be deeply copied on clone call.
60  */
61 void ComponentInstance::attachOnCloning() const
62 {
63   _isAttachedOnCloning=true;
64 }
65
66 std::string ComponentInstance::getFileRepr() const
67 {
68   return NULL_FILE_REPR;
69 }
70
71 /*!
72  * By calling this method the current container 'this' will be deeply copied on clone call.
73  */
74 void ComponentInstance::dettachOnCloning() const
75 {
76   _isAttachedOnCloning=false;
77 }
78
79 bool ComponentInstance::isAttachedOnCloning() const
80 {
81   return _isAttachedOnCloning;
82 }
83
84 string ComponentInstance::getKind() const
85 {
86   return KIND;
87 }