4 Star 2 Fork 1

BLumia / PineappleSynth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
GallantSignal.h 14.33 KB
一键复制 编辑 原始数据 按行查看 历史
BLumia 提交于 2016-08-11 14:54 . First commit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
/*
* Signal.h
* A lightweight signals and slots implementation using fast delegates
*
* Created by Patrick Hogan on 5/18/09.
*
*/
#ifndef _Signal_H_
#define _Signal_H_
#include "Delegate.h"
#include <set>
namespace Gallant {
template< class Param0 = void >
class Signal0
{
public:
typedef Delegate0< void > _Delegate;
private:
typedef std::set<_Delegate> DelegateList;
typedef typename DelegateList::const_iterator DelegateIterator;
DelegateList delegateList;
public:
void Connect( _Delegate delegate )
{
delegateList.insert( delegate );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)() )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)() const )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
void Disconnect( _Delegate delegate )
{
delegateList.erase( delegate );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)() )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)() const )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
void Clear()
{
delegateList.clear();
}
void Emit() const
{
for (DelegateIterator i = delegateList.begin(); i != delegateList.end(); )
{
(*(i++))();
}
}
void operator() () const
{
Emit();
}
bool Empty() const
{
return delegateList.empty();
}
};
template< class Param1 >
class Signal1
{
public:
typedef Delegate1< Param1 > _Delegate;
private:
typedef std::set<_Delegate> DelegateList;
typedef typename DelegateList::const_iterator DelegateIterator;
DelegateList delegateList;
public:
void Connect( _Delegate delegate )
{
delegateList.insert( delegate );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1 ) )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1 ) const )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
void Disconnect( _Delegate delegate )
{
delegateList.erase( delegate );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1 ) )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1 ) const )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
void Clear()
{
delegateList.clear();
}
void Emit( Param1 p1 ) const
{
for (DelegateIterator i = delegateList.begin(); i != delegateList.end(); )
{
(*(i++))( p1 );
}
}
void operator() ( Param1 p1 ) const
{
Emit( p1 );
}
bool Empty() const
{
return delegateList.empty();
}
};
template< class Param1, class Param2 >
class Signal2
{
public:
typedef Delegate2< Param1, Param2 > _Delegate;
private:
typedef std::set<_Delegate> DelegateList;
typedef typename DelegateList::const_iterator DelegateIterator;
DelegateList delegateList;
public:
void Connect( _Delegate delegate )
{
delegateList.insert( delegate );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2 ) )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2 ) const )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
void Disconnect( _Delegate delegate )
{
delegateList.erase( delegate );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2 ) )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2 ) const )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
void Clear()
{
delegateList.clear();
}
void Emit( Param1 p1, Param2 p2 ) const
{
for (DelegateIterator i = delegateList.begin(); i != delegateList.end(); )
{
(*(i++))( p1, p2 );
}
}
void operator() ( Param1 p1, Param2 p2 ) const
{
Emit( p1, p2 );
}
bool Empty() const
{
return delegateList.empty();
}
};
template< class Param1, class Param2, class Param3 >
class Signal3
{
public:
typedef Delegate3< Param1, Param2, Param3 > _Delegate;
private:
typedef std::set<_Delegate> DelegateList;
typedef typename DelegateList::const_iterator DelegateIterator;
DelegateList delegateList;
public:
void Connect( _Delegate delegate )
{
delegateList.insert( delegate );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3 ) )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3 ) const )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
void Disconnect( _Delegate delegate )
{
delegateList.erase( delegate );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3 ) )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3 ) const )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
void Clear()
{
delegateList.clear();
}
void Emit( Param1 p1, Param2 p2, Param3 p3 ) const
{
for (DelegateIterator i = delegateList.begin(); i != delegateList.end(); )
{
(*(i++))( p1, p2, p3 );
}
}
void operator() ( Param1 p1, Param2 p2, Param3 p3 ) const
{
Emit( p1, p2, p3 );
}
bool Empty() const
{
return delegateList.empty();
}
};
template< class Param1, class Param2, class Param3, class Param4 >
class Signal4
{
public:
typedef Delegate4< Param1, Param2, Param3, Param4 > _Delegate;
private:
typedef std::set<_Delegate> DelegateList;
typedef typename DelegateList::const_iterator DelegateIterator;
DelegateList delegateList;
public:
void Connect( _Delegate delegate )
{
delegateList.insert( delegate );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
void Disconnect( _Delegate delegate )
{
delegateList.erase( delegate );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
void Clear()
{
delegateList.clear();
}
void Emit( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const
{
for (DelegateIterator i = delegateList.begin(); i != delegateList.end(); )
{
(*(i++))( p1, p2, p3, p4 );
}
}
void operator() ( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const
{
Emit( p1, p2, p3, p4 );
}
bool Empty() const
{
return delegateList.empty();
}
};
template< class Param1, class Param2, class Param3, class Param4, class Param5 >
class Signal5
{
public:
typedef Delegate5< Param1, Param2, Param3, Param4, Param5 > _Delegate;
private:
typedef std::set<_Delegate> DelegateList;
typedef typename DelegateList::const_iterator DelegateIterator;
DelegateList delegateList;
public:
void Connect( _Delegate delegate )
{
delegateList.insert( delegate );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
void Disconnect( _Delegate delegate )
{
delegateList.erase( delegate );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
void Clear()
{
delegateList.clear();
}
void Emit( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const
{
for (DelegateIterator i = delegateList.begin(); i != delegateList.end(); )
{
(*(i++))( p1, p2, p3, p4, p5 );
}
}
void operator() ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const
{
Emit( p1, p2, p3, p4, p5 );
}
bool Empty() const
{
return delegateList.empty();
}
};
template< class Param1, class Param2, class Param3, class Param4, class Param5, class Param6 >
class Signal6
{
public:
typedef Delegate6< Param1, Param2, Param3, Param4, Param5, Param6 > _Delegate;
private:
typedef std::set<_Delegate> DelegateList;
typedef typename DelegateList::const_iterator DelegateIterator;
DelegateList delegateList;
public:
void Connect( _Delegate delegate )
{
delegateList.insert( delegate );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
void Disconnect( _Delegate delegate )
{
delegateList.erase( delegate );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
void Clear()
{
delegateList.clear();
}
void Emit( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const
{
for (DelegateIterator i = delegateList.begin(); i != delegateList.end(); )
{
(*(i++))( p1, p2, p3, p4, p5, p6 );
}
}
void operator() ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const
{
Emit( p1, p2, p3, p4, p5, p6 );
}
bool Empty() const
{
return delegateList.empty();
}
};
template< class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7 >
class Signal7
{
public:
typedef Delegate7< Param1, Param2, Param3, Param4, Param5, Param6, Param7 > _Delegate;
private:
typedef std::set<_Delegate> DelegateList;
typedef typename DelegateList::const_iterator DelegateIterator;
DelegateList delegateList;
public:
void Connect( _Delegate delegate )
{
delegateList.insert( delegate );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
void Disconnect( _Delegate delegate )
{
delegateList.erase( delegate );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
void Clear()
{
delegateList.clear();
}
void Emit( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const
{
for (DelegateIterator i = delegateList.begin(); i != delegateList.end(); )
{
(*(i++))( p1, p2, p3, p4, p5, p6, p7 );
}
}
void operator() ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const
{
Emit( p1, p2, p3, p4, p5, p6, p7 );
}
bool Empty() const
{
return delegateList.empty();
}
};
template< class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8 >
class Signal8
{
public:
typedef Delegate8< Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8 > _Delegate;
private:
typedef std::set<_Delegate> DelegateList;
typedef typename DelegateList::const_iterator DelegateIterator;
DelegateList delegateList;
public:
void Connect( _Delegate delegate )
{
delegateList.insert( delegate );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Connect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const )
{
delegateList.insert( MakeDelegate( obj, func ) );
}
void Disconnect( _Delegate delegate )
{
delegateList.erase( delegate );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
template< class X, class Y >
void Disconnect( Y * obj, void (X::*func)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const )
{
delegateList.erase( MakeDelegate( obj, func ) );
}
void Clear()
{
delegateList.clear();
}
void Emit( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const
{
for (DelegateIterator i = delegateList.begin(); i != delegateList.end(); )
{
(*(i++))( p1, p2, p3, p4, p5, p6, p7, p8 );
}
}
void operator() ( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const
{
Emit( p1, p2, p3, p4, p5, p6, p7, p8 );
}
bool Empty() const
{
return delegateList.empty();
}
};
} // namespace
#endif //_SIGNAL_H_
C++
1
https://gitee.com/blumia/PineappleSynth.git
git@gitee.com:blumia/PineappleSynth.git
blumia
PineappleSynth
PineappleSynth
master

搜索帮助