1 // Copyright (C) 2007-2024 CEA, EDF, 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
23 // File : SALOME_GenericObj_wrap.hxx
24 // Created : Fri Dec 7 11:32:45 2012
25 // Author : Edward AGAPOV (eap)
28 #ifndef __SALOME_GenericObj_wrap_HXX__
29 #define __SALOME_GenericObj_wrap_HXX__
33 // call UnRegister on each element in a sequence of SALOME::GenericObj's
34 template< class SEQ_OF_GENOBJ >
35 void UnRegister( SEQ_OF_GENOBJ& seq )
37 for ( size_t i = 0; i < seq->length(); ++i )
38 if ( !CORBA::is_nil( seq[i] ))
42 // This class is intended to free the user of objects, iherited from SALOME::GenericObj,
43 // from a need to call UnRegister() after having finished using the object.
44 // The behavior of this class is similar to that of var CORBA class and thus it
45 // can replace var types of wrapped CORBA classes in some code like follows:
49 // typedef SALOME::GenericObj_wrap< SObject > SObject_wrap;
50 // typedef SALOME::GenericObj_wrap< ChildIterator > ChildIterator_wrap;
53 // SALOMEDS::ChildIterator_wrap anIter = aStudy->NewChildIterator( mainSO );
54 // for ( ; anIter->More(); anIter->Next() ) {
55 // SALOMEDS::SObject_wrap so = anIter->Value();
58 // Note that the need to call UnRegister(), and thus to use GenericObj_wrap, depends on
59 // implementation of a method returning a GenericObj servant. If the method creates a
60 // servant, than UnRegister() must be called. If the method retrieves a servant from
61 // some storage, then it's wrong to call UnRegister().
63 // A pleasant additional feature privided by this class is that one can assign
64 // GenericObj_wrap< BASE_CLASS > to GenericObj_wrap< CHILD_CLASS > without
65 // calling CHILD_CLASS::_narrow().
67 template< class GENOBJ >
71 typedef typename GENOBJ::_ptr_type TPtr;
72 typedef typename GENOBJ::_var_type TVar;
79 GenericObj_wrap( const TPtr& obj )
80 : _obj( obj ), _isOwn( true )
82 GenericObj_wrap( const TVar& obj )
83 : _obj( obj ), _isOwn( true )
85 GenericObj_wrap( const GenericObj_wrap& wrap )
86 : _obj( wrap._obj ), _isOwn( wrap._getIsOwn() )
90 template< class BASE_GENOBJ >
91 GenericObj_wrap( const GenericObj_wrap<BASE_GENOBJ>& wrap )
92 : _obj( GENOBJ::_narrow( wrap.in() )), _isOwn( wrap._getIsOwn() )
102 GenericObj_wrap& operator=( const TPtr& obj )
109 GenericObj_wrap& operator=( const TVar& obj )
116 GenericObj_wrap& operator=( const GenericObj_wrap& wrap )
119 _obj = wrap._obj;//wrap.in();
120 _isOwn = wrap._getIsOwn();
124 template< class BASE_GENOBJ >
125 GenericObj_wrap& operator=( const GenericObj_wrap<BASE_GENOBJ>& wrap )
128 _obj = GENOBJ::_narrow( wrap.in() );
129 _isOwn = wrap._getIsOwn();
134 operator TPtr() const
138 operator TVar() const
142 TVar operator->() const
152 _release(); // returned reference to _obj will be initialized with another object
162 bool _getIsOwn() const { return _isOwn; }
167 if ( _isOwn && !CORBA::is_nil( _obj ))
172 if ( _isOwn && !CORBA::is_nil( _obj ))
179 } // namespace SALOME