SimpleITK  1.0.1
sitkCommand.h
Go to the documentation of this file.
1 /*=========================================================================
2 *
3 * Copyright Insight Software Consortium
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(void);
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(void);
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 
83 private:
84 
85  // a set of objects who use us
86  std::set<itk::simple::ProcessObject*> m_ReferencedObjects;
87 
89  std::string m_Name;
90 };
91 
92 } // end namespace simple
93 } // end namespace itk
94 
95 #endif
virtual void SetOwnedByProcessObjects(bool o)
Definition: sitkCommand.h:75
std::string m_Name
Definition: sitkCommand.h:89
std::set< itk::simple::ProcessObject * > m_ReferencedObjects
Definition: sitkCommand.h:86
class ITK_FORWARD_EXPORT ProcessObject
virtual void OwnedByProcessObjectsOff()
Definition: sitkCommand.h:78
An implementation of the Command design pattern for callback.
Definition: sitkCommand.h:44
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
virtual bool GetOwnedByProcessObjects() const
Definition: sitkCommand.h:76
Base class for SimpleITK classes based on ProcessObject.
virtual void OwnedByProcessObjectsOn()
Definition: sitkCommand.h:77
An inheratable class to disable copying of a class.
class ITK_FORWARD_EXPORT Command
virtual std::string GetName() const
Definition: sitkCommand.h:56
virtual void SetName(const std::string &name)
Definition: sitkCommand.h:57