1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #ifndef INCLUDED_SVL_BROADCAST_HXX
20 #define INCLUDED_SVL_BROADCAST_HXX
22 #include <svl/svldllapi.h>
29 class SVL_DLLPUBLIC SvtBroadcaster
32 friend class SvtListener
;
34 typedef std::vector
<SvtListener
*> ListenersType
;
37 const SvtBroadcaster
& operator=(const SvtBroadcaster
&) = delete;
40 * Ensure that the container doesn't contain any duplicated listener
41 * entries. As a side effect, the listeners get sorted by pointer values
44 void Normalize() const;
46 void Add( SvtListener
* p
);
47 void Remove( SvtListener
* p
);
50 virtual void ListenersGone();
54 SvtBroadcaster( const SvtBroadcaster
&rBC
);
55 virtual ~SvtBroadcaster();
57 void Broadcast( const SfxHint
&rHint
);
59 ListenersType
& GetAllListeners();
60 const ListenersType
& GetAllListeners() const;
62 bool HasListeners() const;
65 * Listeners and broadcasters are M:N relationship. If you want to
66 * destruct them, you easily end up in O(M*N) situation; where for every
67 * listener, you iterate all broadcasters, to remove that one listener.
69 * To avoid that, use this call to announce to the broadcaster it is going
70 * to die, and the listeners do not have to bother with removing
71 * themselves from the broadcaster - the broadcaster will not broadcast
72 * anything after the PrepareForDesctruction() call anyway.
74 void PrepareForDestruction();
77 /// contains only one of each listener, which is enforced by SvtListener
78 mutable ListenersType maListeners
;
80 /// When the broadcaster is about to die, collect listeners that asked for removal.
81 mutable ListenersType maDestructedListeners
;
83 /// Indicate that this broadcaster will be destructed (we indicate this on all ScColumn's broadcasters during the ScTable destruction, eg.)
86 mutable bool mbNormalized
:1;
87 mutable bool mbDestNormalized
:1;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */