GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / notify / lstner.cxx
bloba6946bcb543aacf2544a8e328fea2a4211ad590a
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 .
21 #include <tools/debug.hxx>
23 #include <svl/hint.hxx>
24 #include <svl/brdcst.hxx>
26 #include <svl/lstner.hxx>
27 #include <algorithm>
29 DBG_NAME(SfxListener)
30 TYPEINIT0(SfxListener);
32 // simple ctor of class SfxListener
34 SfxListener::SfxListener()
36 DBG_CTOR(SfxListener, 0);
39 // copy ctor of class SfxListener
41 SfxListener::SfxListener( const SfxListener &rListener )
43 DBG_CTOR(SfxListener, 0);
45 for ( sal_uInt16 n = 0; n < rListener.aBCs.size(); ++n )
46 StartListening( *rListener.aBCs[n] );
49 // unregisters the SfxListener from its SfxBroadcasters
51 SfxListener::~SfxListener()
53 DBG_DTOR(SfxListener, 0);
55 // unregister at all remaining broadcasters
56 for ( sal_uInt16 nPos = 0; nPos < aBCs.size(); ++nPos )
58 SfxBroadcaster *pBC = aBCs[nPos];
59 pBC->RemoveListener(*this);
64 // unregisters a specific SfxBroadcaster
66 void SfxListener::RemoveBroadcaster_Impl( SfxBroadcaster& rBroadcaster )
68 DBG_CHKTHIS(SfxListener, 0);
70 aBCs.erase( std::find( aBCs.begin(), aBCs.end(), &rBroadcaster ) );
74 // registers a specific SfxBroadcaster
76 sal_Bool SfxListener::StartListening( SfxBroadcaster& rBroadcaster, sal_Bool bPreventDups )
78 DBG_CHKTHIS(SfxListener, 0);
80 if ( !bPreventDups || !IsListening( rBroadcaster ) )
82 rBroadcaster.AddListener(*this);
83 aBCs.push_back( &rBroadcaster );
85 DBG_ASSERT( IsListening(rBroadcaster), "StartListening failed" );
86 return sal_True;
89 return sal_False;
93 // unregisters a specific SfxBroadcaster
95 sal_Bool SfxListener::EndListening( SfxBroadcaster& rBroadcaster, sal_Bool bAllDups )
97 DBG_CHKTHIS(SfxListener, 0);
99 if ( !IsListening( rBroadcaster ) )
100 return sal_False;
104 rBroadcaster.RemoveListener(*this);
105 aBCs.erase( std::find( aBCs.begin(), aBCs.end(), &rBroadcaster ) );
107 while ( bAllDups && IsListening( rBroadcaster ) );
108 return sal_True;
112 // unregisters all Broadcasters
114 void SfxListener::EndListeningAll()
116 DBG_CHKTHIS(SfxListener, 0);
118 // MI: bei Optimierung beachten: Seiteneffekte von RemoveListener beachten!
119 while ( !aBCs.empty() )
121 SfxBroadcaster *pBC = aBCs.front();
122 pBC->RemoveListener(*this);
123 aBCs.pop_front();
128 sal_Bool SfxListener::IsListening( SfxBroadcaster& rBroadcaster ) const
130 return aBCs.end() != std::find( aBCs.begin(), aBCs.end(), &rBroadcaster );
134 // base implementation of notification handler
136 #ifdef DBG_UTIL
137 void SfxListener::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& )
138 #else
139 void SfxListener::Notify( SfxBroadcaster&, const SfxHint& )
140 #endif
142 #ifdef DBG_UTIL
143 DBG_ASSERT(aBCs.end() != std::find(aBCs.begin(), aBCs.end(), &rBroadcaster),
144 "notification from unregistered broadcaster" );
145 #endif
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */