LibreOffice Module sd (master) 1
unowcntr.cxx
Go to the documentation of this file.
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
24using namespace ::com::sun::star;
25
27{
28}
29
31{
32}
33
35void SvUnoWeakContainer::insert( const uno::WeakReference< uno::XInterface >& xRef ) noexcept
36{
37 for ( auto it = maVector.begin(); it != maVector.end(); )
38 {
39 uno::WeakReference< uno::XInterface > & rWeakRef = *it;
40 uno::Reference< uno::XInterface > xTestRef( rWeakRef );
41 if ( !xTestRef.is() )
42 {
43 it = maVector.erase( it );
44 }
45 else
46 {
47 if ( rWeakRef == xRef )
48 return;
49 ++it;
50 }
51 }
52 maVector.emplace_back( xRef );
53}
54
59 uno::WeakReference< uno::XInterface >& rRef,
60 void const * pSearchData,
61 weakref_searchfunc pSearchFunc
62)
63{
64 for ( auto it = maVector.begin(); it != maVector.end(); )
65 {
66 uno::WeakReference< uno::XInterface > & itRef = *it;
67 uno::Reference< uno::XInterface > xTestRef( itRef );
68 if ( !xTestRef.is() )
69 {
70 it = maVector.erase( it );
71 }
72 else
73 {
74 if( (*pSearchFunc)( itRef, pSearchData ) )
75 {
76 rRef = itRef;
77 return true;
78 }
79 ++it;
80 }
81 }
82 return false;
83}
84
86{
87 for (auto const& elem : maVector)
88 {
89 uno::Reference< uno::XInterface > xTestRef( elem );
90 if ( xTestRef.is() )
91 {
92 uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY );
93 if( xComp.is() )
94 xComp->dispose();
95 }
96 }
97}
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< css::uno::WeakReference< css::uno::XInterface > > maVector
Definition: unowcntr.hxx:30
void insert(const css::uno::WeakReference< css::uno::XInterface > &xRef) noexcept
inserts the given ref into this container
Definition: unowcntr.cxx:35
~SvUnoWeakContainer() noexcept
Definition: unowcntr.cxx:30
bool findRef(css::uno::WeakReference< css::uno::XInterface > &rRef, void const *pSearchData, weakref_searchfunc pSearchFunc)
searches the container for a ref that returns true on the given search function
Definition: unowcntr.cxx:58
SvUnoWeakContainer() noexcept
Definition: unowcntr.cxx:26
bool(* weakref_searchfunc)(const css::uno::WeakReference< css::uno::XInterface > &xRef, void const *pSearchData)
Definition: unowcntr.hxx:25