1 /*=========================================================================
4 Module: $RCSfile: gdcmCommandManager.cxx,v $
6 Date: $Date: 2005/11/28 16:31:22 $
7 Version: $Revision: 1.2 $
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"
24 //-----------------------------------------------------------------------------
25 CommandManager CommandManager::Instance;
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
30 * \brief Constructor used when we want to generate dicom files from scratch
32 CommandManager::CommandManager()
38 * \brief Canonical destructor.
40 CommandManager::~CommandManager ()
42 if( this == GetInstance() )
46 //-----------------------------------------------------------------------------
48 void CommandManager::SetCommand(const Base *object,unsigned int type,Command *command)
50 Instance.InSetCommand(object,type,command);
53 Command *CommandManager::GetCommand(const Base *object,unsigned int type)
55 return(Instance.InGetCommand(object,type));
58 bool CommandManager::ExecuteCommand(Base *object,unsigned int type,std::string text)
60 return(Instance.InExecuteCommand(object,type,text));
63 bool CommandManager::ExecuteCommandConst(const Base *object,unsigned int type,std::string text)
65 return(Instance.InExecuteCommandConst(object,type,text));
68 const CommandManager *CommandManager::GetInstance()
73 //-----------------------------------------------------------------------------
75 void CommandManager::InClearCommand(void)
77 CommandHT::iterator it;
78 for(it=CommandList.begin();it!=CommandList.end();++it)
85 void CommandManager::InSetCommand(const Base *object,unsigned int type,Command *command)
87 CommandKey key = CommandKey(object,type);
88 Command *cmd = CommandList[key];
95 CommandList[key]=command;
99 CommandList.erase(key);
103 Command *CommandManager::InGetCommand(const Base *object,unsigned int type)
105 CommandKey key = CommandKey(object,type);
108 return CommandList[key];
116 bool CommandManager::InExecuteCommand(Base *object,unsigned int type,std::string text)
118 Command *cmd = GetCommand(object,type);
122 cmd->SetObject(object);
130 bool CommandManager::InExecuteCommandConst(const Base *object,unsigned int type,std::string text)
132 Command *cmd = GetCommand(object,type);
136 cmd->SetConstObject(object);
144 //-----------------------------------------------------------------------------
147 //-----------------------------------------------------------------------------
149 void CommandManager::Print(std::ostream &os, std::string const &indent)
151 os<<indent<<"Command list : \n";
152 CommandHT::iterator it;
153 for(it=CommandList.begin();it!=CommandList.end();++it)
155 os<<indent<<" "<<typeid(it->first.first).name()<<" ("<<it->first.first<<") - "
156 <<Command::GetCommandAsString(it->first.second)
157 <<" : "<<typeid(it->second).name()<<" ("<<it->second<<")"
162 //-----------------------------------------------------------------------------
163 } // end namespace gdcm