fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / comphelper / weakbag.hxx
blobb654baa2bda496551b5e0cc4d09712044153bb3f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_COMPHELPER_WEAKBAG_HXX
21 #define INCLUDED_COMPHELPER_WEAKBAG_HXX
23 #include "sal/config.h"
25 #include <list>
26 #include "com/sun/star/uno/Reference.hxx"
27 #include "cppuhelper/weakref.hxx"
28 #include "osl/diagnose.h"
30 namespace comphelper {
32 /**
33 A bag of UNO weak references.
35 template< typename T > class WeakBag {
36 public:
37 /**
38 Add a new weak reference.
40 The implementation keeps the amount of memory consumed linear in the
41 number of living references added, not linear in the number of total
42 references added.
44 @param e
45 a non-null reference.
47 void add(com::sun::star::uno::Reference< T > const & e) {
48 OSL_ASSERT(e.is());
49 for (typename WeakReferenceList::iterator i(m_list.begin()); i != m_list.end();) {
50 if (com::sun::star::uno::Reference< T >(*i).is()) {
51 ++i;
52 } else {
53 i = m_list.erase(i);
56 m_list.push_back(com::sun::star::uno::WeakReference< T >(e));
59 /**
60 Remove a living reference.
62 @return
63 a living reference, or null if there are none.
65 com::sun::star::uno::Reference< T > remove() {
66 while (!m_list.empty()) {
67 com::sun::star::uno::Reference< T > r(m_list.front());
68 m_list.pop_front();
69 if (r.is()) {
70 return r;
73 return com::sun::star::uno::Reference< T >();
76 private:
77 typedef std::list< com::sun::star::uno::WeakReference< T > > WeakReferenceList;
79 WeakReferenceList m_list;
84 #endif
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */