1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unowcntr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <com/sun/star/lang/XComponent.hpp>
34 #include <tools/list.hxx>
36 #include <unowcntr.hxx>
38 using namespace ::rtl
;
39 using namespace ::com::sun::star
;
41 DECLARE_LIST( WeakRefList
, uno::WeakReference
< uno::XInterface
>* )
43 SvUnoWeakContainer::SvUnoWeakContainer() throw()
45 mpList
= new WeakRefList
;
48 SvUnoWeakContainer::~SvUnoWeakContainer() throw()
50 uno::WeakReference
< uno::XInterface
>* pRef
= mpList
->First();
53 delete mpList
->Remove();
54 pRef
= mpList
->GetCurObject();
59 /** inserts the given ref into this container */
60 void SvUnoWeakContainer::insert( uno::WeakReference
< uno::XInterface
> xRef
) throw()
62 uno::WeakReference
< uno::XInterface
>* pRef
= mpList
->First();
65 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xTestRef( *pRef
);
68 delete mpList
->Remove();
69 pRef
= mpList
->GetCurObject();
76 pRef
= mpList
->Next();
80 mpList
->Insert( new uno::WeakReference
< uno::XInterface
>( xRef
) );
83 /** removes the given ref from this container */
84 void SvUnoWeakContainer::remove( uno::WeakReference
< uno::XInterface
> xRef
) throw()
86 uno::WeakReference
< uno::XInterface
>* pRef
= mpList
->First();
89 uno::Reference
< uno::XInterface
> xTestRef( *pRef
);
92 delete mpList
->Remove();
93 pRef
= mpList
->GetCurObject();
99 delete mpList
->Remove();
103 pRef
= mpList
->Next();
108 /** searches the container for a ref that returns true on the given
111 sal_Bool
SvUnoWeakContainer::findRef( uno::WeakReference
< uno::XInterface
>& rRef
, void* pSearchData
, weakref_searchfunc pSearchFunc
)
113 uno::WeakReference
< uno::XInterface
>* pRef
= mpList
->First();
116 uno::Reference
< ::com::sun::star::uno::XInterface
> xTestRef( *pRef
);
119 delete mpList
->Remove();
120 pRef
= mpList
->GetCurObject();
124 if( (*pSearchFunc
)( *pRef
, pSearchData
) )
130 pRef
= mpList
->Next();
137 void SvUnoWeakContainer::dispose()
139 uno::WeakReference
< uno::XInterface
>* pRef
= mpList
->First();
142 uno::Reference
< uno::XInterface
> xTestRef( *pRef
);
145 uno::Reference
< lang::XComponent
> xComp( xTestRef
, uno::UNO_QUERY
);
150 pRef
= mpList
->Next();