X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmCommandManager.cxx;h=bcd747171566eb72a986210b891ca7a53a581ab9;hb=8132e180439a6e41d07240cad48be249b66e5e05;hp=49adb41807f3d8fc10e566a7f1588b990269be5b;hpb=46afb30d2d016a9b1581c7ee4ca96d614a35203c;p=gdcm.git diff --git a/src/gdcmCommandManager.cxx b/src/gdcmCommandManager.cxx index 49adb418..bcd74717 100644 --- a/src/gdcmCommandManager.cxx +++ b/src/gdcmCommandManager.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmCommandManager.cxx,v $ Language: C++ - Date: $Date: 2005/11/28 15:20:35 $ - Version: $Revision: 1.1 $ + Date: $Date: 2006/02/13 09:27:35 $ + Version: $Revision: 1.3 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,9 +18,13 @@ // --------------------------------------------------------------- #include "gdcmCommandManager.h" #include "gdcmCommand.h" +#include // for typeif (needed by __BORLANDC__ v6) namespace gdcm { +//----------------------------------------------------------------------------- +CommandManager CommandManager::Instance; + //----------------------------------------------------------------------------- // Constructor / Destructor /** @@ -36,32 +40,73 @@ CommandManager::CommandManager() */ CommandManager::~CommandManager () { + if( this == GetInstance() ) + InClearCommand(); } //----------------------------------------------------------------------------- // Public -void CommandManager::SetCommand(unsigned int type,Command *command) +void CommandManager::SetCommand(const Base *object,unsigned int type,Command *command) +{ + Instance.InSetCommand(object,type,command); +} + +Command *CommandManager::GetCommand(const Base *object,unsigned int type) +{ + return(Instance.InGetCommand(object,type)); +} + +bool CommandManager::ExecuteCommand(Base *object,unsigned int type,std::string text) { - Command *cmd=CommandList[type]; - if(cmd!=command) + return(Instance.InExecuteCommand(object,type,text)); +} + +bool CommandManager::ExecuteCommandConst(const Base *object,unsigned int type,std::string text) +{ + return(Instance.InExecuteCommandConst(object,type,text)); +} + +const CommandManager *CommandManager::GetInstance() +{ + return &Instance; +} + +//----------------------------------------------------------------------------- +// Protected +void CommandManager::InClearCommand(void) +{ + CommandHT::iterator it; + for(it=CommandList.begin();it!=CommandList.end();++it) + { + if( it->second ) + it->second->Delete(); + } +} + +void CommandManager::InSetCommand(const Base *object,unsigned int type,Command *command) +{ + CommandKey key = CommandKey(object,type); + Command *cmd = CommandList[key]; + if( cmd != command ) { - if(cmd) + if( cmd ) cmd->Unregister(); - if(command) + if( command ) { - CommandList[type]=command; + CommandList[key]=command; command->Register(); } else - CommandList.erase(type); + CommandList.erase(key); } } -Command *CommandManager::GetCommand(unsigned int type) const +Command *CommandManager::InGetCommand(const Base *object,unsigned int type) { + CommandKey key = CommandKey(object,type); try { - return CommandList[type]; + return CommandList[key]; } catch(...) { @@ -69,13 +114,13 @@ Command *CommandManager::GetCommand(unsigned int type) const } } -bool CommandManager::ExecuteCommand(unsigned int type,std::string text) +bool CommandManager::InExecuteCommand(Base *object,unsigned int type,std::string text) { - Command *cmd = GetCommand(type); - if(cmd) + Command *cmd = GetCommand(object,type); + if( cmd ) { cmd->SetText(text); - cmd->SetObject(this); + cmd->SetObject(object); cmd->SetType(type); cmd->Execute(); return true; @@ -83,13 +128,13 @@ bool CommandManager::ExecuteCommand(unsigned int type,std::string text) return false; } -bool CommandManager::ConstExecuteCommand(unsigned int type,std::string text) const +bool CommandManager::InExecuteCommandConst(const Base *object,unsigned int type,std::string text) { - Command *cmd = GetCommand(type); - if(cmd) + Command *cmd = GetCommand(object,type); + if( cmd ) { cmd->SetText(text); - cmd->SetConstObject(this); + cmd->SetConstObject(object); cmd->SetType(type); cmd->Execute(); return true; @@ -97,9 +142,6 @@ bool CommandManager::ConstExecuteCommand(unsigned int type,std::string text) con return false; } -//----------------------------------------------------------------------------- -// Protected - //----------------------------------------------------------------------------- // Private @@ -111,9 +153,10 @@ void CommandManager::Print(std::ostream &os, std::string const &indent) CommandHT::iterator it; for(it=CommandList.begin();it!=CommandList.end();++it) { - os<first) - <<" : "<second).name() - <<" ("<second<<")"<first.first).name()<<" ("<first.first<<") - " + <first.second) + <<" : "<second).name()<<" ("<second<<")" + <