Merge branch '138-toggle-free-look-with-hotkey' into 'main/atys-live'
[ryzomcore.git] / nel / src / misc / event_emitter_multi.cpp
blob245d935a7e8eee0e7c0c82e80ca33394e1a76759
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdmisc.h"
21 #include "nel/misc/event_emitter_multi.h"
22 #include "nel/misc/system_utils.h"
24 #ifdef DEBUG_NEW
25 #define new DEBUG_NEW
26 #endif
28 namespace NLMISC
31 // a predicate to find an emitter in a list
32 struct EmitterEqualPred
34 EmitterEqualPred(IEventEmitter *e) : E(e) {}
35 IEventEmitter *E;
36 bool operator()(const std::pair<IEventEmitter *, bool> &el)
38 return el.first == E;
42 ///============================================================
43 CEventEmitterMulti::~CEventEmitterMulti()
45 for (TEmitterCont::iterator it = _Emitters.begin(); it != _Emitters.end(); ++it)
47 if (it->second) // asked "must Delete' ?
49 delete it->first;
54 ///============================================================
55 void CEventEmitterMulti::addEmitter(IEventEmitter *e, bool mustDelete)
57 nlassert(e != this); // avoid infinite recursion
58 nlassert(!isEmitter(e));
59 _Emitters.push_back(std::make_pair(e, mustDelete));
62 ///============================================================
63 void CEventEmitterMulti::removeEmitter(IEventEmitter *e)
65 TEmitterCont::iterator it = std::find_if(_Emitters.begin(), _Emitters.end(), EmitterEqualPred(e));
66 nlassert(it!= _Emitters.end());
67 if (it->second)
69 delete it->first;
71 _Emitters.erase(it);
74 ///============================================================
75 bool CEventEmitterMulti::isEmitter(IEventEmitter *e) const
77 TEmitterCont::const_iterator it = std::find_if(_Emitters.begin(), _Emitters.end(), EmitterEqualPred(e));
78 return it != _Emitters.end();
81 ///============================================================
82 void CEventEmitterMulti::submitEvents(CEventServer &server, bool allWindows)
84 for (TEmitterCont::iterator it = _Emitters.begin(); it != _Emitters.end(); ++it)
86 it->first->submitEvents(server, allWindows);
90 ///============================================================
91 IEventEmitter *CEventEmitterMulti::getEmitter(uint index)
93 nlassert(index < _Emitters.size());
94 return _Emitters[index].first;
97 ///============================================================
98 const IEventEmitter *CEventEmitterMulti::getEmitter(uint index) const
100 nlassert(index < _Emitters.size());
101 return _Emitters[index].first;
104 bool CEventEmitterMulti::copyTextToClipboard(const std::string &text)
106 // Naush: wrapped to old API to avoid duplicate code
107 return CSystemUtils::copyTextToClipboard(text);
110 bool CEventEmitterMulti::pasteTextFromClipboard(std::string &text)
112 // Naush: wrapped to old API to avoid duplicate code
113 return CSystemUtils::pasteTextFromClipboard(text);
117 } // NLMISC