ITK  5.2.0
Insight Toolkit
itkObjectFactoryBase.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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkObjectFactoryBase_h
29 #define itkObjectFactoryBase_h
30 
32 #include "itkSingletonMacro.h"
33 #include "itkCommonEnums.h"
34 #include <list>
35 #include <vector>
36 
37 namespace itk
38 {
58 // Forward reference because of private implementation
59 class OverRideMap;
60 struct ObjectFactoryBasePrivate;
61 
62 class ITKCommon_EXPORT ObjectFactoryBase : public Object
63 {
64 public:
65  ITK_DISALLOW_COPY_AND_MOVE(ObjectFactoryBase);
66 
69  using Superclass = Object;
72 
74  itkTypeMacro(ObjectFactoryBase, Object);
75 
81  CreateInstance(const char * itkclassname);
82 
87  static std::list<LightObject::Pointer>
88  CreateAllInstance(const char * itkclassname);
89 
92  static void
93  ReHash();
94 
102  static void
103  RegisterFactoryInternal(ObjectFactoryBase *);
104 
106 #if !defined(ITK_LEGACY_REMOVE)
107  // We need to expose the enum values at the class level
108  // for backwards compatibility
109  static constexpr InsertionPositionEnum INSERT_AT_FRONT = InsertionPositionEnum::INSERT_AT_FRONT;
110  static constexpr InsertionPositionEnum INSERT_AT_BACK = InsertionPositionEnum::INSERT_AT_BACK;
111  static constexpr InsertionPositionEnum INSERT_AT_POSITION = InsertionPositionEnum::INSERT_AT_POSITION;
112 #endif
113 
132  static bool
133  RegisterFactory(ObjectFactoryBase *,
134  InsertionPositionEnum where = InsertionPositionEnum::INSERT_AT_BACK,
135  size_t position = 0);
137 
139  static void
140  UnRegisterFactory(ObjectFactoryBase *);
141 
143  static void
144  UnRegisterAllFactories();
145 
148  static std::list<ObjectFactoryBase *>
149  GetRegisteredFactories();
150 
156  virtual const char *
157  GetITKSourceVersion() const = 0;
158 
164  static void
165  SetStrictVersionChecking(bool);
166  static void
167  StrictVersionCheckingOn();
168  static void
169  StrictVersionCheckingOff();
170  static bool
171  GetStrictVersionChecking();
173 
175  virtual const char *
176  GetDescription() const = 0;
177 
179  virtual std::list<std::string>
180  GetClassOverrideNames();
181 
183  virtual std::list<std::string>
184  GetClassOverrideWithNames();
185 
187  virtual std::list<std::string>
188  GetClassOverrideDescriptions();
189 
191  virtual std::list<bool>
192  GetEnableFlags();
193 
195  virtual void
196  SetEnableFlag(bool flag, const char * className, const char * subclassName);
197 
199  virtual bool
200  GetEnableFlag(const char * className, const char * subclassName);
201 
205  virtual void
206  Disable(const char * className);
207 
209  const char *
210  GetLibraryPath();
211 
217  {
218  std::string m_Description;
219  std::string m_OverrideWithName;
222  };
223 
224 protected:
225  void
226  PrintSelf(std::ostream & os, Indent indent) const override;
227 
229  void
230  RegisterOverride(const char * classOverride,
231  const char * subclass,
232  const char * description,
233  bool enableFlag,
234  CreateObjectFunctionBase * createFunction);
235 
239  virtual LightObject::Pointer
240  CreateObject(const char * itkclassname);
241 
245  virtual std::list<LightObject::Pointer>
246  CreateAllObject(const char * itkclassname);
247 
249  ~ObjectFactoryBase() override;
250 
251 private:
254  static void
255  SynchronizeObjectFactoryBase(void * objectFactoryBasePrivate);
256  itkGetGlobalDeclarationMacro(ObjectFactoryBasePrivate, PimplGlobals);
258 
259  OverRideMap * m_OverrideMap;
260 
262  static void
263  InitializeFactoryList();
264 
267  static void
268  Initialize();
269 
271  static void
272  RegisterInternal();
273 
275  static void
276  LoadDynamicFactories();
277 
279  static void
280  LoadLibrariesInPath(const char *);
281 
282  static void
283  DeleteNonInternalFactory(ObjectFactoryBase *);
284 
288  unsigned long m_LibraryDate;
289  std::string m_LibraryPath;
290 
291  static ObjectFactoryBasePrivate * m_PimplGlobals;
292 };
293 } // end namespace itk
294 
295 #endif
itkCreateObjectFunction.h
itk::ObjectFactoryBase
Create instances of classes using an object factory.
Definition: itkObjectFactoryBase.h:62
itk::ObjectFactoryBase::m_LibraryPath
std::string m_LibraryPath
Definition: itkObjectFactoryBase.h:289
itk::ObjectFactoryBase::OverrideInformation
Internal implementation class for ObjectFactorBase.
Definition: itkObjectFactoryBase.h:216
itk::ObjectFactoryBase::OverrideInformation::m_OverrideWithName
std::string m_OverrideWithName
Definition: itkObjectFactoryBase.h:219
itk::ObjectFactoryBase::m_LibraryDate
unsigned long m_LibraryDate
Definition: itkObjectFactoryBase.h:288
itk::ObjectFactoryBase::OverrideInformation::m_EnabledFlag
bool m_EnabledFlag
Definition: itkObjectFactoryBase.h:220
itkSingletonMacro.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::CreateObjectFunctionBase
Define API for object creation callback functions.
Definition: itkCreateObjectFunction.h:31
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::ObjectFactoryBase::OverrideInformation::m_Description
std::string m_Description
Definition: itkObjectFactoryBase.h:218
itk::ObjectFactoryBase::m_OverrideMap
OverRideMap * m_OverrideMap
Definition: itkObjectFactoryBase.h:259
itk::ObjectFactoryBase::m_LibraryHandle
void * m_LibraryHandle
Definition: itkObjectFactoryBase.h:287
itk::ObjectFactoryBase::OverrideInformation::m_CreateObject
CreateObjectFunctionBase::Pointer m_CreateObject
Definition: itkObjectFactoryBase.h:221
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ObjectFactoryBase::m_PimplGlobals
static ObjectFactoryBasePrivate * m_PimplGlobals
Definition: itkObjectFactoryBase.h:291
itkCommonEnums.h
itkGetGlobalDeclarationMacro
#define itkGetGlobalDeclarationMacro(Type, VarName)
Definition: itkSingletonMacro.h:35
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::ObjectFactoryEnums::InsertionPosition
InsertionPosition
Definition: itkCommonEnums.h:279