SimpleITK  2.0.0
sitkCommand.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 sitkCommand_h
19 #define sitkCommand_h
20 
21 
22 #include "sitkCommon.h"
23 #include "sitkNonCopyable.h"
24 
25 #include <set>
26 
27 namespace itk {
28 namespace simple {
29 
30 class ProcessObject;
31 
45  protected NonCopyable
46 {
47 public:
48 
50  Command();
51 
53  virtual ~Command();
54 
56  virtual std::string GetName() const { return this->m_Name; }
57  virtual void SetName(const std::string &name) { this->m_Name = name; }
58 
60  virtual void Execute();
61 
62 protected:
63 
65 
66  #ifndef SWIG
67  // internal methods to maintain reference between ProcessObject and
68  // Command, so when either is destroyed, the other will be notified.
69  //
70  // Return value is the number of referenced process objects after
71  // operation.
72  virtual size_t AddProcessObject(itk::simple::ProcessObject *o);
73  virtual size_t RemoveProcessObject(const itk::simple::ProcessObject *o);
74 
75  virtual void SetOwnedByProcessObjects(bool o) {this->m_OwnedByProcessObjects = o;}
76  virtual bool GetOwnedByProcessObjects() const {return this->m_OwnedByProcessObjects;}
77  virtual void OwnedByProcessObjectsOn() {this->SetOwnedByProcessObjects(true);}
78  virtual void OwnedByProcessObjectsOff() {this->SetOwnedByProcessObjects(false);}
79  #endif
80 
81 
82 private:
83 
84  // a set of objects who use us
85  std::set<itk::simple::ProcessObject*> m_ReferencedObjects;
86 
88  std::string m_Name;
89 };
90 
91 } // end namespace simple
92 } // end namespace itk
93 
94 #endif
itk::simple::Command::SetName
virtual void SetName(const std::string &name)
Definition: sitkCommand.h:57
sitkNonCopyable.h
itk::simple::Command::OwnedByProcessObjectsOff
virtual void OwnedByProcessObjectsOff()
Definition: sitkCommand.h:78
sitkCommon.h
itk::simple::Command
An implementation of the Command design pattern for callback.
Definition: sitkCommand.h:44
itk::simple::Command::m_OwnedByProcessObjects
bool m_OwnedByProcessObjects
Definition: sitkCommand.h:87
SITKCommon_EXPORT
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
itk::simple::Command::m_Name
std::string m_Name
Definition: sitkCommand.h:88
itk::simple::NonCopyable
An inheritable class to disable copying of a class.
Definition: sitkNonCopyable.h:51
itk::Command
class ITK_FORWARD_EXPORT Command
itk::simple::Command::GetOwnedByProcessObjects
virtual bool GetOwnedByProcessObjects() const
Definition: sitkCommand.h:76
itk::simple::Command::m_ReferencedObjects
std::set< itk::simple::ProcessObject * > m_ReferencedObjects
Definition: sitkCommand.h:85
itk::simple::Command::OwnedByProcessObjectsOn
virtual void OwnedByProcessObjectsOn()
Definition: sitkCommand.h:77
itk
itk::simple::Command::GetName
virtual std::string GetName() const
Definition: sitkCommand.h:56
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
itk::simple::ProcessObject
Base class for SimpleITK classes based on ProcessObject.
Definition: sitkProcessObject.h:51
itk::simple::Command::SetOwnedByProcessObjects
virtual void SetOwnedByProcessObjects(bool o)
Definition: sitkCommand.h:75