Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / comphelper / multicontainer2.hxx
blob91875b6689f35810fd3e7ea2fb67419ddc5da3b7
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 #pragma once
22 #include <sal/config.h>
24 #include <osl/mutex.hxx>
25 #include <com/sun/star/lang/EventObject.hpp>
26 #include <comphelper/comphelperdllapi.h>
27 #include <comphelper/interfacecontainer2.hxx>
28 #include <memory>
29 #include <vector>
30 #include <utility>
32 namespace com::sun::star::uno
34 class XInterface;
37 namespace comphelper
39 /** This is a copy of cppu::OMultiTypeInterfaceContainerHelper2 in include/cppuhelper/interfacecontainer.h,
40 except that it uses comphelper::OInterfaceContainerHelper2, which is more efficient.
42 class COMPHELPER_DLLPUBLIC OMultiTypeInterfaceContainerHelper2
44 public:
45 /**
46 Create a container of interface containers.
48 @param rMutex the mutex to protect multi thread access.
49 The lifetime must be longer than the lifetime
50 of this object.
52 OMultiTypeInterfaceContainerHelper2(::osl::Mutex& rMutex);
53 /**
54 Delete all containers.
56 ~OMultiTypeInterfaceContainerHelper2();
58 /**
59 Return all id's under which at least one interface is added.
61 std::vector<css::uno::Type> getContainedTypes() const;
63 /**
64 Return the container created under this key.
65 @return the container created under this key. If the container
66 was not created, null was returned.
68 OInterfaceContainerHelper2* getContainer(const css::uno::Type& rKey) const;
70 /** Inserts an element into the container with the specified key.
71 The position is not specified, thus it is not specified in which order events are fired.
73 @attention
74 If you add the same interface more than once, then it will be added to the elements list
75 more than once and thus if you want to remove that interface from the list, you have to call
76 removeInterface() the same number of times.
77 In the latter case, you will also get events fired more than once (if the interface is a
78 listener interface).
80 @param rKey
81 the id of the container
82 @param r
83 interface to be added; it is allowed, to insert null or
84 the same interface more than once
85 @return
86 the new count of elements in the container
88 sal_Int32 addInterface(const css::uno::Type& rKey,
89 const css::uno::Reference<css::uno::XInterface>& r);
91 /** Removes an element from the container with the specified key.
92 It uses interface equality to remove the interface.
94 @param rKey
95 the id of the container
96 @param rxIFace
97 interface to be removed
98 @return
99 the new count of elements in the container
101 sal_Int32 removeInterface(const css::uno::Type& rKey,
102 const css::uno::Reference<css::uno::XInterface>& rxIFace);
105 Call disposing on all object in the container that
106 support XEventListener. Then clear the container.
108 void disposeAndClear(const css::lang::EventObject& rEvt);
110 Remove all elements of all containers. Does not delete the container.
112 void clear();
114 typedef css::uno::Type keyType;
116 private:
117 typedef std::vector<std::pair<css::uno::Type, std::unique_ptr<OInterfaceContainerHelper2>>>
118 t_type2ptr;
120 t_type2ptr::iterator findType(const css::uno::Type& rKey);
121 t_type2ptr::const_iterator findType(const css::uno::Type& rKey) const;
123 t_type2ptr m_aMap;
124 ::osl::Mutex& rMutex;
126 OMultiTypeInterfaceContainerHelper2(const OMultiTypeInterfaceContainerHelper2&) = delete;
127 OMultiTypeInterfaceContainerHelper2& operator=(const OMultiTypeInterfaceContainerHelper2&)
128 = delete;
131 } // namespace comphelper
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */