Salome HOME
cf7d9551eae608846b3447b534ac066ba418cc6d
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_UseCaseIterator.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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_UseCaseIterator.cxx
24 //  Author : Sergey RUIN
25 //  Module : SALOME
26 //
27 #include "SALOMEDS_UseCaseIterator.hxx"
28
29 #include "SALOMEDS.hxx"
30 #include "SALOMEDS_SObject.hxx"
31
32 SALOMEDS_UseCaseIterator::SALOMEDS_UseCaseIterator(const SALOMEDSImpl_UseCaseIterator& theIterator)
33 {
34   _isLocal = true;
35   _local_impl = theIterator.GetPersistentCopy();
36   _corba_impl = SALOMEDS::UseCaseIterator::_nil();
37 }
38
39 SALOMEDS_UseCaseIterator::SALOMEDS_UseCaseIterator(SALOMEDS::UseCaseIterator_ptr theIterator)
40 {
41   _isLocal = false;
42   _corba_impl = SALOMEDS::UseCaseIterator::_duplicate(theIterator);
43 }
44
45 SALOMEDS_UseCaseIterator::~SALOMEDS_UseCaseIterator()
46 {
47   if(!_isLocal) _corba_impl->UnRegister();    
48   else if(_local_impl) delete _local_impl;
49 }
50
51 void SALOMEDS_UseCaseIterator::Init(bool theAllLevels)
52 {
53   if (_isLocal) {
54     SALOMEDS::Locker lock;
55     if(_local_impl) _local_impl->Init(theAllLevels);
56   }
57   else _corba_impl->Init(theAllLevels);
58 }
59
60 bool SALOMEDS_UseCaseIterator::More()
61 {
62   bool ret = false;
63   if (_isLocal) {
64     SALOMEDS::Locker lock;
65     if(_local_impl) ret = _local_impl->More();
66   }
67   else ret = _corba_impl->More();
68   return ret;
69 }
70
71 void SALOMEDS_UseCaseIterator::Next()
72 {
73   if (_isLocal) {
74     SALOMEDS::Locker lock;
75     if(_local_impl) _local_impl->Next();
76   }
77   else _corba_impl->Next();
78 }
79
80 _PTR(SObject) SALOMEDS_UseCaseIterator::Value()
81 {
82   SALOMEDS_SObject* aSO = NULL;
83   if (_isLocal) {
84     SALOMEDS::Locker lock;
85     if(_local_impl) aSO = new SALOMEDS_SObject(_local_impl->Value());
86   }
87   else aSO = new SALOMEDS_SObject(_corba_impl->Value());
88   return _PTR(SObject)(aSO);
89 }