SimpleITK  
itkHolderCommand.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkHolderCommand_h
19 #define itkHolderCommand_h
20 
21 #include "itkCommand.h"
22 
23 namespace itk
24 {
25 
36 template <class T>
38 {
39 public:
40  using ObjectType = T;
41 
44 
47 
49 
50  void
51  Set(const ObjectType object)
52  {
53  this->m_Object = object;
54  }
55  ObjectType &
56  Get()
57  {
58  return this->m_Object;
59  }
60  const ObjectType &
61  Get() const
62  {
63  return this->m_Object;
64  }
65 
66  void
67  Execute(itk::Object *, const itk::EventObject &) override
68  {}
69  void
70  Execute(const itk::Object *, const itk::EventObject &) override
71  {}
72 
73  void
74  operator=(const HolderCommand &) = delete;
75  HolderCommand(const HolderCommand &) = delete;
76 
77 protected:
78  HolderCommand() = default;
79  ~HolderCommand() override = default;
80 
81 private:
83 };
84 
85 template <class T>
86 class HolderCommand<T *> : public itk::Command
87 {
88 public:
89  using ObjectType = T;
90 
93 
96 
97  itkNewMacro(HolderCommand);
98 
99  void
100  Set(ObjectType * object)
101  {
102  this->m_Object = object;
103  }
104  ObjectType *
105  Get()
106  {
107  return this->m_Object;
108  }
109  const ObjectType *
110  Get() const
111  {
112  return this->m_Object;
113  }
114 
115  void
116  Execute(itk::Object *, const itk::EventObject &) override
117  {}
118  void
119  Execute(const itk::Object *, const itk::EventObject &) override
120  {}
121 
122  void
123  operator=(const HolderCommand &) = delete;
124  HolderCommand(const HolderCommand &) = delete;
125 
126 protected:
128  : m_Object(nullptr){};
129  ~HolderCommand() override { delete m_Object; }
130 
131 private:
133 };
134 
135 } // namespace itk
136 
137 #endif
itk::HolderCommand< T * >::Get
const ObjectType * Get() const
Definition: itkHolderCommand.h:110
itk::HolderCommand::~HolderCommand
~HolderCommand() override=default
itk::HolderCommand< T * >::HolderCommand
HolderCommand()
Definition: itkHolderCommand.h:127
itk::SmartPointer< Self >
itk::HolderCommand< T * >::Set
void Set(ObjectType *object)
Definition: itkHolderCommand.h:100
itk::HolderCommand::Set
void Set(const ObjectType object)
Definition: itkHolderCommand.h:51
itk::HolderCommand< T * >::m_Object
ObjectType * m_Object
Definition: itkHolderCommand.h:132
itk::HolderCommand::Get
ObjectType & Get()
Definition: itkHolderCommand.h:56
itk::Command
itk::Command
class ITK_FORWARD_EXPORT Command
itk::HolderCommand< T * >::Execute
void Execute(itk::Object *, const itk::EventObject &) override
Definition: itkHolderCommand.h:116
itk::HolderCommand::itkNewMacro
itkNewMacro(HolderCommand)
itk::HolderCommand::ObjectType
T ObjectType
Definition: itkHolderCommand.h:40
itk::HolderCommand::operator=
void operator=(const HolderCommand &)=delete
itk::HolderCommand
An ITK Command class to hold a object until destruction.
Definition: itkHolderCommand.h:37
itk::HolderCommand::Execute
void Execute(const itk::Object *, const itk::EventObject &) override
Definition: itkHolderCommand.h:70
itk::HolderCommand< T * >::Execute
void Execute(const itk::Object *, const itk::EventObject &) override
Definition: itkHolderCommand.h:119
itk::HolderCommand::Execute
void Execute(itk::Object *, const itk::EventObject &) override
Definition: itkHolderCommand.h:67
itk::HolderCommand< T * >::Get
ObjectType * Get()
Definition: itkHolderCommand.h:105
itk::HolderCommand::HolderCommand
HolderCommand()=default
itk
itk::HolderCommand::m_Object
ObjectType m_Object
Definition: itkHolderCommand.h:82
itk::Object
itk::HolderCommand< T * >::ObjectType
T ObjectType
Definition: itkHolderCommand.h:89
itk::EventObject
itkCommand.h
itk::HolderCommand::Get
const ObjectType & Get() const
Definition: itkHolderCommand.h:61
itk::HolderCommand< T * >::~HolderCommand
~HolderCommand() override
Definition: itkHolderCommand.h:129