1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOME_GenericObj_wrap.hxx
23 // Created : Fri Dec 7 11:32:45 2012
24 // Author : Edward AGAPOV (eap)
27 #ifndef __SALOME_GenericObj_wrap_HXX__
28 #define __SALOME_GenericObj_wrap_HXX__
32 // call UnRegister on each element in a sequence of SALOME::GenericObj's
33 template< class SEQ_OF_GENOBJ >
34 void UnRegister( SEQ_OF_GENOBJ& seq )
36 for ( size_t i = 0; i < seq->length(); ++i )
37 if ( !CORBA::is_nil( seq[i] ))
41 // This class is intended to free the user of objects, iherited from SALOME::GenericObj,
42 // from a need to call UnRegister() after having finished using the object.
43 // The behavior of this class is similar to that of var CORBA class and thus it
44 // can replace var types of wrapped CORBA classes in some code like follows:
48 // typedef SALOME::GenericObj_wrap< SObject > SObject_wrap;
49 // typedef SALOME::GenericObj_wrap< ChildIterator > ChildIterator_wrap;
52 // SALOMEDS::ChildIterator_wrap anIter = aStudy->NewChildIterator( mainSO );
53 // for ( ; anIter->More(); anIter->Next() ) {
54 // SALOMEDS::SObject_wrap so = anIter->Value();
57 // Note that the need to call UnRegister(), and thus to use GenericObj_wrap, depends on
58 // implementation of a method returning a GenericObj servant. If the method creates a
59 // servant, than UnRegister() must be called. If the method retrieves a servant from
60 // some storage, then it's wrong to call UnRegister().
62 // A pleasant additional feature privided by this class is that one can assign
63 // GenericObj_wrap< BASE_CLASS > to GenericObj_wrap< CHILD_CLASS > without
64 // calling CHILD_CLASS::_narrow().
66 template< class GENOBJ >
70 typedef typename GENOBJ::_ptr_type TPtr;
71 typedef typename GENOBJ::_var_type TVar;
78 GenericObj_wrap( const TPtr& obj )
79 : _obj( obj ), _isOwn( true )
81 GenericObj_wrap( const TVar& obj )
82 : _obj( obj ), _isOwn( true )
84 GenericObj_wrap( const GenericObj_wrap& wrap )
85 : _obj( wrap._obj ), _isOwn( wrap._getIsOwn() )
89 template< class BASE_GENOBJ >
90 GenericObj_wrap( const GenericObj_wrap<BASE_GENOBJ>& wrap )
91 : _obj( GENOBJ::_narrow( wrap.in() )), _isOwn( wrap._getIsOwn() )
101 GenericObj_wrap& operator=( const TPtr& obj )
108 GenericObj_wrap& operator=( const TVar& obj )
115 GenericObj_wrap& operator=( const GenericObj_wrap& wrap )
118 _obj = wrap._obj;//wrap.in();
119 _isOwn = wrap._getIsOwn();
123 template< class BASE_GENOBJ >
124 GenericObj_wrap& operator=( const GenericObj_wrap<BASE_GENOBJ>& wrap )
127 _obj = GENOBJ::_narrow( wrap.in() );
128 _isOwn = wrap._getIsOwn();
151 _release(); // returned reference to _obj will be initialized with another object
161 bool _getIsOwn() const { return _isOwn; }
166 if ( _isOwn && !CORBA::is_nil( _obj ))
171 if ( _isOwn && !CORBA::is_nil( _obj ))
178 } // namespace SALOME