Salome HOME
acc4d7cde579e2122eef795cb79040ac824b8cb7
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_ChildIterator.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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
23 //  File   : SALOMEDS_ChildIterator.cxx
24 //  Author : Sergey RUIN
25 //  Module : SALOME
26 //
27 #include "SALOMEDS_ChildIterator.hxx"
28 #include "SALOMEDS_SObject.hxx"
29 #include "SALOMEDS.hxx"
30
31 SALOMEDS_ChildIterator::SALOMEDS_ChildIterator(const SALOMEDSImpl_ChildIterator& theIterator)
32 {
33   SALOMEDS::Locker lock;
34
35   _isLocal = true;
36   _local_impl = theIterator.GetPersistentCopy();
37   _corba_impl = SALOMEDS::ChildIterator::_nil();
38 }
39
40 SALOMEDS_ChildIterator::SALOMEDS_ChildIterator(SALOMEDS::ChildIterator_ptr theIterator)
41 {
42   _isLocal = false;
43   _corba_impl = SALOMEDS::ChildIterator::_duplicate(theIterator);
44 }
45
46 SALOMEDS_ChildIterator::~SALOMEDS_ChildIterator()
47 {
48   if(!_isLocal) _corba_impl->UnRegister(); 
49   else if(_local_impl) delete _local_impl;
50 }
51
52 void SALOMEDS_ChildIterator::Init()
53 {
54   if (_isLocal) {
55     SALOMEDS::Locker lock;
56     _local_impl->Init();
57   }
58   else _corba_impl->Init();
59 }
60
61 void SALOMEDS_ChildIterator::InitEx(bool theAllLevels)
62 {
63   if (_isLocal) {
64     SALOMEDS::Locker lock;
65     _local_impl->InitEx(theAllLevels);
66   }
67   else _corba_impl->InitEx(theAllLevels);
68 }
69
70 bool SALOMEDS_ChildIterator::More()
71 {
72   bool ret = false;
73   if (_isLocal) {
74     SALOMEDS::Locker lock;
75     ret = _local_impl->More();
76   }
77   else ret = _corba_impl->More();
78   return ret;
79 }
80
81 void SALOMEDS_ChildIterator::Next() 
82 {
83   if (_isLocal) {
84     SALOMEDS::Locker lock;
85     _local_impl->Next();
86   }
87   else _corba_impl->Next();
88 }
89
90 _PTR(SObject) SALOMEDS_ChildIterator::Value()
91 {
92   SALOMEDSClient_SObject* aSO;
93   if (_isLocal) {
94     SALOMEDS::Locker lock;
95     aSO = new SALOMEDS_SObject(_local_impl->Value());
96   }
97   else {
98     SALOMEDS::SObject_var so=_corba_impl->Value();
99     aSO = new SALOMEDS_SObject(so);
100   }
101   return _PTR(SObject)(aSO);
102 }