Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/lang/XComponent.hpp>
21 :
22 : #include <unowcntr.hxx>
23 :
24 : using namespace ::rtl;
25 : using namespace ::com::sun::star;
26 :
27 2 : SvUnoWeakContainer::SvUnoWeakContainer() throw()
28 : {
29 2 : }
30 :
31 4 : SvUnoWeakContainer::~SvUnoWeakContainer() throw()
32 : {
33 4 : for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); ++it )
34 2 : delete *it;
35 2 : maList.clear();
36 2 : }
37 :
38 : /** inserts the given ref into this container */
39 10 : void SvUnoWeakContainer::insert( uno::WeakReference< uno::XInterface > xRef ) throw()
40 : {
41 20 : for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); )
42 : {
43 0 : uno::WeakReference< uno::XInterface >* pRef = *it;
44 0 : uno::Reference< uno::XInterface > xTestRef( *pRef );
45 0 : if ( !xTestRef.is() )
46 : {
47 0 : delete pRef;
48 0 : it = maList.erase( it );
49 : }
50 : else
51 : {
52 0 : if ( *pRef == xRef )
53 10 : return;
54 0 : ++it;
55 : }
56 0 : }
57 10 : maList.push_back( new uno::WeakReference< uno::XInterface >( xRef ) );
58 : }
59 :
60 : /** searches the container for a ref that returns true on the given
61 : search function
62 : */
63 10 : sal_Bool SvUnoWeakContainer::findRef(
64 : uno::WeakReference< uno::XInterface >& rRef,
65 : void* pSearchData,
66 : weakref_searchfunc pSearchFunc
67 : )
68 : {
69 28 : for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); )
70 : {
71 8 : uno::WeakReference< uno::XInterface >* pRef = *it;
72 8 : uno::Reference< uno::XInterface > xTestRef( *pRef );
73 8 : if ( !xTestRef.is() )
74 : {
75 8 : delete pRef;
76 8 : it = maList.erase( it );
77 : }
78 : else
79 : {
80 0 : if( (*pSearchFunc)( *pRef, pSearchData ) )
81 : {
82 0 : rRef = *pRef;
83 0 : return sal_True;
84 : }
85 0 : ++it;
86 : }
87 8 : }
88 10 : return sal_False;
89 : }
90 :
91 2 : void SvUnoWeakContainer::dispose()
92 : {
93 4 : for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); ++it )
94 : {
95 2 : uno::WeakReference< uno::XInterface >* pRef = *it;
96 2 : uno::Reference< uno::XInterface > xTestRef( *pRef );
97 2 : if ( xTestRef.is() )
98 : {
99 0 : uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY );
100 0 : if( xComp.is() )
101 0 : xComp->dispose();
102 : }
103 2 : }
104 2 : }
105 :
106 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|