ultimatepp/bazaar/Dispatcher/Dispatcher.cpp
kohait 03a3218bd7 bazaar: Dispatcher: Dispatcher0 notifiactor without arguments
Gen: some cleanup and CopyingC / PolyCopyingC interface

git-svn-id: svn://ultimatepp.org/upp/trunk@2677 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2010-09-09 10:13:19 +00:00

77 lines
No EOL
1.7 KiB
C++

#include "Dispatcher.hpp"
DispatcherGen::DispatcherGen()
{
}
DispatcherGen::~DispatcherGen()
{
//ASSERT(dests.IsEmpty()); //FIXME, DispatcherGen does keep the Dispatcher<T> instances, cause Dispatchable<T> are Register()ed there (forwarded) and do Unregister() only there as well.
}
//Callback variant
DispatcherCBGen::DispatcherCBGen()
{
}
DispatcherCBGen::~DispatcherCBGen()
{
//ASSERT(dests.IsEmpty()); //FIXME, DispatcherGen does keep the Dispatcher<T> instances, cause Dispatchable<T> are Register()ed there (forwarded) and do Unregister() only there as well.
}
//Dispatcher0
Dispatcher0::Dispatcher0()
{
}
Dispatcher0::~Dispatcher0()
{
ASSERT(dests.IsEmpty());
}
void Dispatcher0::DoDispatch() const
{
if(!EnableOption<>::IsEnabled()) return;
for(int i = 0; i < dests.GetCount(); i++)
{
const Callback & dest = dests.operator[](i);
dest();
}
}
void Dispatcher0::Register(Callback d, unsigned key)
{
int i = dests.Find(key);
if(i>=0) return;
dests.Add(key) = d;
}
void Dispatcher0::Unregister(unsigned key)
{
int i = dests.Find(key);
if(i<0) return;
dests.Remove(i);
}
Callback Dispatcher0::GetDispatchable(unsigned key)
{
int i = dests.Find(key);
if(i<0) return Callback();
Callback & dest = dests.operator[](i);
return dest;
}
#if 0 //for compile / debug only
template class Dispatchable<int>;
template class Dispatcher<int>;
template void DispatcherGen::DoDispatch<int>(const int & o, unsigned param) const;
template void DispatcherGen::Register<int>(Dispatchable<int> & d, unsigned key);
template void DispatcherGen::Unregister<int>(Dispatchable<int> & d, unsigned key);
DispatcherGen gen;
DispatcherCBGen gencb;
#endif