move common subscription code into templated class

This commit is contained in:
Chris Danford
2005-02-05 11:21:13 +00:00
parent e2da825c30
commit 9d760bbdea
4 changed files with 83 additions and 54 deletions
+7 -19
View File
@@ -7,21 +7,9 @@
#include "LuaManager.h"
#include "LuaBinding.h"
static vector<ActorCommands*>* g_pActorCommands;
#include "SubscriptionManager.h"
set<ActorCommands*>* SubscriptionManager<ActorCommands>::s_pSubscribers = NULL;
static void Subscribe( ActorCommands* p )
{
if( g_pActorCommands == NULL )
g_pActorCommands = new vector<ActorCommands*>;
g_pActorCommands->push_back( p );
}
static void Unsubscribe( ActorCommands* p )
{
vector<ActorCommands*>::iterator iter = find( g_pActorCommands->begin(), g_pActorCommands->end(), p );
ASSERT( iter != g_pActorCommands->end() );
g_pActorCommands->erase( iter );
}
static CString GetNextFunctionName()
{
@@ -32,7 +20,7 @@ static CString GetNextFunctionName()
ActorCommands::ActorCommands( const Commands& cmds )
{
Subscribe( this );
SubscriptionManager<ActorCommands>::Subscribe( this );
m_cmds = cmds;
@@ -41,7 +29,7 @@ ActorCommands::ActorCommands( const Commands& cmds )
ActorCommands::~ActorCommands()
{
Unsubscribe( this );
SubscriptionManager<ActorCommands>::Unsubscribe( this );
if( m_sLuaFunctionName.size() )
Unregister();
@@ -49,7 +37,7 @@ ActorCommands::~ActorCommands()
ActorCommands::ActorCommands( const ActorCommands& cpy )
{
Subscribe( this );
SubscriptionManager<ActorCommands>::Subscribe( this );
m_sLuaFunctionName = GetNextFunctionName();
@@ -172,9 +160,9 @@ void ActorCommands::Unregister()
void ActorCommands::ReRegisterAll()
{
if( g_pActorCommands == NULL )
if( SubscriptionManager<ActorCommands>::s_pSubscribers == NULL )
return;
FOREACH( ActorCommands*, *g_pActorCommands, p )
FOREACHS( ActorCommands*, *SubscriptionManager<ActorCommands>::s_pSubscribers, p )
(*p)->Register();
}