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