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 ::com::sun::star;
25 :
26 63 : SvUnoWeakContainer::SvUnoWeakContainer() throw()
27 : {
28 63 : }
29 :
30 126 : SvUnoWeakContainer::~SvUnoWeakContainer() throw()
31 : {
32 129 : for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); ++it )
33 66 : delete *it;
34 63 : maList.clear();
35 63 : }
36 :
37 : /** inserts the given ref into this container */
38 313 : void SvUnoWeakContainer::insert( uno::WeakReference< uno::XInterface > xRef ) throw()
39 : {
40 632 : for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); )
41 : {
42 6 : uno::WeakReference< uno::XInterface >* pRef = *it;
43 6 : uno::Reference< uno::XInterface > xTestRef( *pRef );
44 6 : if ( !xTestRef.is() )
45 : {
46 0 : delete pRef;
47 0 : it = maList.erase( it );
48 : }
49 : else
50 : {
51 6 : if ( *pRef == xRef )
52 313 : return;
53 6 : ++it;
54 : }
55 6 : }
56 313 : maList.push_back( new uno::WeakReference< uno::XInterface >( xRef ) );
57 : }
58 :
59 : /** searches the container for a ref that returns true on the given
60 : search function
61 : */
62 315 : bool SvUnoWeakContainer::findRef(
63 : uno::WeakReference< uno::XInterface >& rRef,
64 : void* pSearchData,
65 : weakref_searchfunc pSearchFunc
66 : )
67 : {
68 886 : for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); )
69 : {
70 258 : uno::WeakReference< uno::XInterface >* pRef = *it;
71 258 : uno::Reference< uno::XInterface > xTestRef( *pRef );
72 258 : if ( !xTestRef.is() )
73 : {
74 247 : delete pRef;
75 247 : it = maList.erase( it );
76 : }
77 : else
78 : {
79 11 : if( (*pSearchFunc)( *pRef, pSearchData ) )
80 : {
81 2 : rRef = *pRef;
82 2 : return true;
83 : }
84 9 : ++it;
85 : }
86 256 : }
87 313 : return false;
88 : }
89 :
90 63 : void SvUnoWeakContainer::dispose()
91 : {
92 129 : for ( WeakRefList::iterator it = maList.begin(); it != maList.end(); ++it )
93 : {
94 66 : uno::WeakReference< uno::XInterface >* pRef = *it;
95 66 : uno::Reference< uno::XInterface > xTestRef( *pRef );
96 66 : if ( xTestRef.is() )
97 : {
98 5 : uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY );
99 5 : if( xComp.is() )
100 5 : xComp->dispose();
101 : }
102 66 : }
103 63 : }
104 :
105 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|