GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / notify / brdcst.cxx
blob1509a5213fb4aeb880c1734ace39286fd464b43e
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 #include <assert.h>
22 #include <tools/debug.hxx>
24 #include <svl/hint.hxx>
25 #include <svl/smplhint.hxx>
26 #include <svl/lstner.hxx>
28 #include <svl/brdcst.hxx>
29 #include <algorithm>
31 DBG_NAME(SfxBroadcaster)
32 TYPEINIT0(SfxBroadcaster);
35 // broadcast immediately
37 void SfxBroadcaster::Broadcast( const SfxHint &rHint )
39 DBG_CHKTHIS(SfxBroadcaster, 0);
41 // notify all registered listeners exactly once
42 for (size_t n = 0; n < m_Listeners.size(); ++n)
44 SfxListener *const pListener = m_Listeners[n];
45 if (pListener) {
46 pListener->Notify( *this, rHint );
51 // unregister all listeners
53 SfxBroadcaster::~SfxBroadcaster()
55 DBG_DTOR(SfxBroadcaster, 0);
57 Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
59 // remove all still registered listeners
60 for (size_t nPos = 0; nPos < m_Listeners.size(); ++nPos)
62 SfxListener *const pListener = m_Listeners[nPos];
63 if (pListener) {
64 pListener->RemoveBroadcaster_Impl(*this);
70 // simple ctor of class SfxBroadcaster
72 SfxBroadcaster::SfxBroadcaster()
74 DBG_CTOR(SfxBroadcaster, 0);
78 // copy ctor of class SfxBroadcaster
81 SfxBroadcaster::SfxBroadcaster( const SfxBroadcaster &rBC )
83 DBG_CTOR(SfxBroadcaster, 0);
85 for (size_t n = 0; n < rBC.m_Listeners.size(); ++n)
87 SfxListener *const pListener = rBC.m_Listeners[n];
88 if (pListener) {
89 pListener->StartListening( *this );
95 // add a new SfxListener to the list
97 void SfxBroadcaster::AddListener( SfxListener& rListener )
99 DBG_CHKTHIS(SfxBroadcaster, 0);
101 for (size_t i = 0; i < m_Listeners.size(); ++i)
103 if (!m_Listeners[i]) // removed by RemoveListener?
105 m_Listeners[i] = &rListener;
106 return;
109 m_Listeners.push_back(&rListener);
113 // called, if no more listeners exists
115 void SfxBroadcaster::ListenersGone()
117 DBG_CHKTHIS(SfxBroadcaster,0);
121 // forward a notification to all registered listeners
123 void SfxBroadcaster::Forward(SfxBroadcaster& rBC, const SfxHint& rHint)
125 for (size_t i = 0; i < m_Listeners.size(); ++i)
127 SfxListener *const pListener = m_Listeners[i];
128 if (pListener) {
129 pListener->Notify( rBC, rHint );
135 // remove one SfxListener from the list
137 void SfxBroadcaster::RemoveListener( SfxListener& rListener )
139 {DBG_CHKTHIS(SfxBroadcaster, 0);}
140 SfxListenerArr_Impl::iterator aIter = std::find(
141 m_Listeners.begin(), m_Listeners.end(), &rListener);
142 assert(aIter != m_Listeners.end()); // "RemoveListener: Listener unknown"
143 // DO NOT erase the listener, set the pointer to 0
144 // because the current continuation may contain this->Broadcast
145 *aIter = 0;
147 if ( !HasListeners() )
148 ListenersGone();
151 bool SfxBroadcaster::HasListeners() const
153 for (size_t i = 0; i < m_Listeners.size(); ++i)
155 if (m_Listeners[i]) {
156 return true;
159 return false;
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */