SimpleITK  2.1.0
sitkObjectOwnedBase.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 sitkObjectOwnedBase_h
19 #define sitkObjectOwnedBase_h
20 
21 
22 #include "sitkCommon.h"
23 #include "sitkNonCopyable.h"
24 
25 #include <map>
26 #include <functional>
27 
28 
29 namespace itk
30 {
31 
32 class Object;
33 
34 namespace simple
35 {
36 
48 : public NonCopyable
49 {
50 public:
51  virtual ~ObjectOwnedBase()
52 #ifndef SWIGR
53  = 0
54 #endif
55  ;
56 
57  ObjectOwnedBase() = default;
58 
60  virtual std::string
61  GetName() const;
62 
64  virtual void
65  SetName(const std::string & name);
66 
67 protected:
68 
77 
78 
79 #ifndef SWIG
80 
86  virtual size_t
87  AddObjectCallback(itk::Object *o, std::function<void()> onDelete);
88 
89  virtual size_t
90  RemoveObject(const itk::Object *);
91 
92 
101  virtual void
102  SetOwnedByObjects(bool o);
103  virtual bool
104  GetOwnedByObjects() const;
105  virtual void
106  OwnedByObjectsOn();
107  virtual void
108  OwnedByObjectsOff();
110 #endif
111 
112 
113 private:
114 
115  void ExecuteCallbacks(void);
116 
117  bool m_OwnedByObjects{ false };
118  std::multimap<itk::Object *, std::function<void()>> m_ReferencedObjectsCallbacks;
119  std::string m_Name;
120 };
121 
122 } // namespace simple
123 } // namespace itk
124 #endif
sitkNonCopyable.h
sitkCommon.h
itk::simple::ObjectOwnedBase::m_Name
std::string m_Name
Definition: sitkObjectOwnedBase.h:119
SITKCommon_EXPORT
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
itk::simple::NonCopyable
An inheritable class to disable copying of a class.
Definition: sitkNonCopyable.h:51
itk
itk::simple::ObjectOwnedBase::m_ReferencedObjectsCallbacks
std::multimap< itk::Object *, std::function< void()> > m_ReferencedObjectsCallbacks
Definition: sitkObjectOwnedBase.h:118
itk::Object
itk::simple::ObjectOwnedBase
An abstract base class to connect this object with the lifetime of another.
Definition: sitkObjectOwnedBase.h:47