1 /*=========================================================================
4 Module: $RCSfile: gdcmCommandManager.cxx,v $
6 Date: $Date: 2007/05/23 14:18:08 $
7 Version: $Revision: 1.5 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
18 // ---------------------------------------------------------------
19 #include "gdcmCommandManager.h"
20 #include "gdcmCommand.h"
21 #include <typeinfo> // for typeif (needed by __BORLANDC__ v6)
23 namespace GDCM_NAME_SPACE
25 //-----------------------------------------------------------------------------
26 CommandManager CommandManager::Instance;
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
31 * \brief Constructor used when we want to generate dicom files from scratch
33 CommandManager::CommandManager()
39 * \brief Canonical destructor.
41 CommandManager::~CommandManager ()
43 if( this == GetInstance() )
47 //-----------------------------------------------------------------------------
49 void CommandManager::SetCommand(const Base *object, unsigned int type, Command *command)
51 Instance.InSetCommand(object, type, command);
54 Command *CommandManager::GetCommand(const Base *object, unsigned int type)
56 return(Instance.InGetCommand(object, type));
59 bool CommandManager::ExecuteCommand(Base *object, unsigned int type, std::string text)
61 return(Instance.InExecuteCommand(object, type, text));
64 bool CommandManager::ExecuteCommandConst(const Base *object, unsigned int type, std::string text)
66 return(Instance.InExecuteCommandConst(object,type,text));
69 const CommandManager *CommandManager::GetInstance()
74 //-----------------------------------------------------------------------------
76 void CommandManager::InClearCommand(void)
78 CommandHT::iterator it;
79 for(it=CommandList.begin(); it != CommandList.end(); ++it)
86 void CommandManager::InSetCommand(const Base *object, unsigned int type, Command *command)
88 CommandKey key = CommandKey(object, type);
89 Command *cmd = CommandList[key];
96 CommandList[key] = command;
100 CommandList.erase(key);
104 Command *CommandManager::InGetCommand(const Base *object,unsigned int type)
106 CommandKey key = CommandKey(object,type);
109 return CommandList[key];
117 bool CommandManager::InExecuteCommand(Base *object,unsigned int type,std::string text)
119 Command *cmd = GetCommand(object,type);
123 cmd->SetObject(object);
131 bool CommandManager::InExecuteCommandConst(const Base *object,unsigned int type,std::string text)
133 Command *cmd = GetCommand(object,type);
137 cmd->SetConstObject(object);
145 //-----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
150 void CommandManager::Print(std::ostream &os, std::string const &indent)
152 os<<indent<<"Command list : \n";
153 CommandHT::iterator it;
154 for(it=CommandList.begin();it!=CommandList.end();++it)
156 os<<indent<<" "<<typeid(it->first.first).name()<<" ("<<it->first.first<<") - "
157 <<Command::GetCommandAsString(it->first.second)
158 <<" : "<<typeid(it->second).name()<<" ("<<it->second<<")"
163 //-----------------------------------------------------------------------------
164 } // end namespace gdcm