D:/Zythum/DinoKod/Common/Command.cpp

00001 #include "Common/Error.h"
00002 
00003 #include "Common/Command.h"
00004 
00005 //---------------------------------------------------------------------------------------------------------------------
00006 KCommandList::KCommandList()
00007 {
00008 }
00009 
00010 //---------------------------------------------------------------------------------------------------------------------
00011 KCommandList::~KCommandList()
00012 {
00013         KCommand*       pCommand;
00014         while( pCommand = m_CommandList.GetFirst() )
00015         {
00016                 m_CommandList.Remove( pCommand );
00017                 SafeDeletep( pCommand );
00018         }
00019 }
00020 
00021 //---------------------------------------------------------------------------------------------------------------------
00022 void KCommandList::RegisterCommand( KStr sName, void* pBind, KStr sDescription, void* pContext )
00023 {
00024         KCommand* pCommand = new KCommand( sName, pBind, sDescription, pContext );
00025         m_CommandList.Add( pCommand );
00026 }
00027 
00028 //---------------------------------------------------------------------------------------------------------------------
00029 void KCommandList::UnregisterCommand( KStr sName )
00030 {
00031         KCommand*       pCommand = GetpCommand( sName );
00032 
00033         if( pCommand )
00034         {
00035                 m_CommandList.Remove( pCommand );
00036                 delete pCommand;
00037         }
00038         else
00039                 KError::Error( NULL, "KCommandList::UnregisterCommand(...) : Command name not found [%s]", sName.GetpString() );
00040 }
00041 
00042 //---------------------------------------------------------------------------------------------------------------------
00043 KCommand* KCommandList::GetpCommand( KStr sName )
00044 {
00045         KCommand*       pCommand;
00046         for( pCommand = m_CommandList.GetFirst(); pCommand; pCommand = m_CommandList.GetNext( pCommand ) )
00047         {
00048                 if( pCommand->GetsName() == sName )
00049                 {
00050                         return pCommand;
00051                 }
00052         }
00053         return NULL;
00054 }
00055 
00056 //---------------------------------------------------------------------------------------------------------------------
00057 bool KCommandList::ExecCommand( KStr sName, KStr sArgument )
00058 {
00059         KCommand*       pCommand = GetpCommand( sName );
00060 
00061         if( pCommand )
00062         {
00063 //              void(*Bind)( KStr sArg );
00064 //              
00065 //              Bind = (void(*)(KStr))pCommand->GetpBind();
00066 //              Bind( sArgument );
00067                 ((void(*)(KStr,void*))pCommand->GetpBind())( sArgument, pCommand->GetpContext() );
00069                 //              (*pCommand->GetpBind())( sArgument );
00070                 return true;
00071         }
00072 
00073         return false;
00074 }

Generated on Sun Mar 25 20:02:10 2007 for Zythum Project by  doxygen 1.5.1-p1