Salome HOME
3736c5e7f585fe8b48ac3ac5945e7b480023c333
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_SComponentIterator.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDS_SComponentIterator.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDS_SComponentIterator.hxx"
25
26 #include "SALOMEDS.hxx"
27 #include "SALOMEDS_SComponent.hxx"
28 #include "SALOMEDSImpl_SComponent.hxx"
29
30 SALOMEDS_SComponentIterator::SALOMEDS_SComponentIterator(const SALOMEDSImpl_SComponentIterator& theIterator)
31 :_local_impl(theIterator)
32 {
33   _isLocal = true;
34   _corba_impl = SALOMEDS::SComponentIterator::_nil();
35 }
36
37 SALOMEDS_SComponentIterator::SALOMEDS_SComponentIterator(SALOMEDS::SComponentIterator_ptr theIterator)
38 {
39   _isLocal = false;
40   _corba_impl = SALOMEDS::SComponentIterator::_duplicate(theIterator);
41 }
42
43 SALOMEDS_SComponentIterator::~SALOMEDS_SComponentIterator()
44 {
45   if(!_isLocal) _corba_impl->Destroy(); 
46 }
47
48 void SALOMEDS_SComponentIterator::Init()
49 {
50   if (_isLocal) {
51     SALOMEDS::Locker lock; 
52     _local_impl.Init();
53   }
54   else _corba_impl->Init();
55 }
56
57 bool SALOMEDS_SComponentIterator::More()
58 {
59   bool ret;
60   if (_isLocal) {
61     SALOMEDS::Locker lock; 
62     ret = _local_impl.More();
63   }
64   else ret = _corba_impl->More();
65   return ret;
66 }
67
68 void SALOMEDS_SComponentIterator::Next()
69 {
70   if (_isLocal) {
71     SALOMEDS::Locker lock; 
72     _local_impl.Next();
73   }
74   else _corba_impl->Next();
75 }
76
77 _PTR(SComponent) SALOMEDS_SComponentIterator::Value()  
78 {
79   SALOMEDSClient_SComponent* aSCO = NULL;
80   if (_isLocal) {
81     SALOMEDS::Locker lock; 
82     aSCO = new SALOMEDS_SComponent(_local_impl.Value());
83   }
84   else aSCO = new SALOMEDS_SComponent(_corba_impl->Value());
85   return _PTR(SComponent)(aSCO);
86 }