gdcmCommand.h
Go to the documentation of this file.
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef GDCMCOMMAND_H
#define GDCMCOMMAND_H
#include "gdcmSubject.h"
namespace gdcm
{
class Event;
class GDCM_EXPORT Command : public Subject
{
public :
Command(const Command&) = delete;
void operator=(const Command&) = delete;
virtual void Execute(Subject *caller, const Event & event ) = 0;
virtual void Execute(const Subject *caller, const Event & event ) = 0;
protected:
Command();
~Command() override;
};
template <class T>
class MemberCommand : public Command
{
public:
typedef void (T::*TMemberFunctionPointer)(Subject*, const Event &);
typedef void (T::*TConstMemberFunctionPointer)(const Subject*,
const Event &);
typedef MemberCommand Self;
//typedef SmartPointer<Self> Pointer;
MemberCommand(const Self&) = delete;
void operator=(const Self&) = delete;
static SmartPointer<MemberCommand> New()
{
return new MemberCommand;
}
//gdcmTypeMacro(MemberCommand,Command);
void SetCallbackFunction(T* object,
TMemberFunctionPointer memberFunction)
{
m_This = object;
m_MemberFunction = memberFunction;
}
void SetCallbackFunction(T* object,
TConstMemberFunctionPointer memberFunction)
{
m_This = object;
m_ConstMemberFunction = memberFunction;
}
void Execute(Subject *caller, const Event & event ) override
{
if( m_MemberFunction )
{
((*m_This).*(m_MemberFunction))(caller, event);
}
}
void Execute( const Subject *caller, const Event & event ) override
{
if( m_ConstMemberFunction )
{
((*m_This).*(m_ConstMemberFunction))(caller, event);
}
}
protected:
T* m_This;
TMemberFunctionPointer m_MemberFunction;
TConstMemberFunctionPointer m_ConstMemberFunction;
MemberCommand():m_MemberFunction(nullptr),m_ConstMemberFunction(nullptr) {}
~MemberCommand() override= default;
};
template <typename T>
class SimpleMemberCommand : public Command
{
public:
typedef void (T::*TMemberFunctionPointer)();
typedef SimpleMemberCommand Self;
//typedef SmartPointer<Self> Pointer;
SimpleMemberCommand(const Self&) = delete;
void operator=(const Self&) = delete;
//gdcmTypeMacro(SimpleMemberCommand,Command);
static SmartPointer<SimpleMemberCommand> New()
{
return new SimpleMemberCommand;
}
void SetCallbackFunction(T* object,
TMemberFunctionPointer memberFunction)
{
m_This = object;
m_MemberFunction = memberFunction;
}
void Execute(Subject *,const Event & ) override
{
if( m_MemberFunction )
{
((*m_This).*(m_MemberFunction))();
}
}
void Execute(const Subject *,const Event & ) override
{
if( m_MemberFunction )
{
((*m_This).*(m_MemberFunction))();
}
}
protected:
T* m_This;
TMemberFunctionPointer m_MemberFunction;
SimpleMemberCommand():m_This(nullptr),m_MemberFunction(nullptr) {}
~SimpleMemberCommand() override = default;
};
} // end namespace gdcm
//-----------------------------------------------------------------------------
#endif //GDCMCOMMAND_H
gdcm::Command::~Command
~Command() override
gdcm::Command::Execute
virtual void Execute(Subject *caller, const Event &event)=0
Abstract method that defines the action to be taken by the command.
gdcm::Command::Command
Command(const Command &)=delete
gdcm::Command::Execute
virtual void Execute(const Subject *caller, const Event &event)=0
gdcm::Command::operator=
void operator=(const Command &)=delete
gdcm::Command::Command
Command()
gdcm::Event
superclass for callback/observer methods
Definition gdcmEvent.h:27
gdcm::MemberCommand::SetCallbackFunction
void SetCallbackFunction(T *object, TMemberFunctionPointer memberFunction)
Definition gdcmCommand.h:82
gdcm::MemberCommand::MemberCommand
MemberCommand()
Definition gdcmCommand.h:118
gdcm::MemberCommand::Execute
void Execute(const Subject *caller, const Event &event) override
Definition gdcmCommand.h:105
gdcm::MemberCommand::TConstMemberFunctionPointer
void(T::* TConstMemberFunctionPointer)(const Subject *, const Event &)
Definition gdcmCommand.h:61
gdcm::MemberCommand::New
static SmartPointer< MemberCommand > New()
Definition gdcmCommand.h:72
gdcm::MemberCommand< SimpleSubjectWatcher >::m_This
SimpleSubjectWatcher * m_This
Definition gdcmCommand.h:115
gdcm::MemberCommand< SimpleSubjectWatcher >::m_ConstMemberFunction
TConstMemberFunctionPointer m_ConstMemberFunction
Definition gdcmCommand.h:117
gdcm::MemberCommand::Execute
void Execute(Subject *caller, const Event &event) override
Definition gdcmCommand.h:96
gdcm::MemberCommand::operator=
void operator=(const Self &)=delete
gdcm::MemberCommand::TMemberFunctionPointer
void(T::* TMemberFunctionPointer)(Subject *, const Event &)
Definition gdcmCommand.h:60
gdcm::MemberCommand::SetCallbackFunction
void SetCallbackFunction(T *object, TConstMemberFunctionPointer memberFunction)
Definition gdcmCommand.h:88
gdcm::MemberCommand::~MemberCommand
~MemberCommand() override=default
gdcm::MemberCommand< SimpleSubjectWatcher >::m_MemberFunction
TMemberFunctionPointer m_MemberFunction
Definition gdcmCommand.h:116
gdcm::MemberCommand::MemberCommand
MemberCommand(const Self &)=delete
gdcm::MemberCommand::Self
MemberCommand Self
Definition gdcmCommand.h:65
gdcm::SimpleMemberCommand::TMemberFunctionPointer
void(T::* TMemberFunctionPointer)()
Definition gdcmCommand.h:135
gdcm::SimpleMemberCommand::SimpleMemberCommand
SimpleMemberCommand()
Definition gdcmCommand.h:180
gdcm::SimpleMemberCommand::Execute
void Execute(const Subject *, const Event &) override
Definition gdcmCommand.h:169
gdcm::SimpleMemberCommand::Execute
void Execute(Subject *, const Event &) override
Definition gdcmCommand.h:162
gdcm::SimpleMemberCommand::SimpleMemberCommand
SimpleMemberCommand(const Self &)=delete
gdcm::SimpleMemberCommand::SetCallbackFunction
void SetCallbackFunction(T *object, TMemberFunctionPointer memberFunction)
Definition gdcmCommand.h:154
gdcm::SimpleMemberCommand::~SimpleMemberCommand
~SimpleMemberCommand() override=default
gdcm::SimpleMemberCommand< SimpleSubjectWatcher >::m_This
SimpleSubjectWatcher * m_This
Definition gdcmCommand.h:178
gdcm::SimpleMemberCommand::operator=
void operator=(const Self &)=delete
gdcm::SimpleMemberCommand< SimpleSubjectWatcher >::m_MemberFunction
TMemberFunctionPointer m_MemberFunction
Definition gdcmCommand.h:179
gdcm::SimpleMemberCommand::New
static SmartPointer< SimpleMemberCommand > New()
Definition gdcmCommand.h:148
gdcm::SimpleMemberCommand::Self
SimpleMemberCommand Self
Definition gdcmCommand.h:138
gdcm::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::Subject
Subject.
Definition gdcmSubject.h:29
gdcm::Subject::Subject
Subject()
gdcmSubject.h
GDCM_EXPORT
#define GDCM_EXPORT
Definition gdcmWin32.h:34
gdcm
Definition gdcmASN1.h:21