ITK  5.3.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  * https://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 class 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);
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();
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 
226  template <typename TFactory>
227  static void
229  {
230  struct FactoryRegistration
231  {};
232 
233  // Factory registration, made thread-safe by "magic statics" (as introduced with C++11).
234  static const FactoryRegistration staticFactoryRegistration = [] {
235  RegisterFactoryInternal(TFactory::New());
236  return FactoryRegistration{};
237  }();
238 
239  (void)staticFactoryRegistration;
240  }
241 
244  static void
245  Initialize();
246 
247 protected:
248  void
249  PrintSelf(std::ostream & os, Indent indent) const override;
250 
252  void
253  RegisterOverride(const char * classOverride,
254  const char * subclass,
255  const char * description,
256  bool enableFlag,
257  CreateObjectFunctionBase * createFunction);
258 
262  virtual LightObject::Pointer
263  CreateObject(const char * itkclassname);
264 
268  virtual std::list<LightObject::Pointer>
269  CreateAllObject(const char * itkclassname);
270 
272  ~ObjectFactoryBase() override;
273 
274 private:
277  static void
278  SynchronizeObjectFactoryBase(void * objectFactoryBasePrivate);
279  itkGetGlobalDeclarationMacro(ObjectFactoryBasePrivate, PimplGlobals);
282  OverRideMap * m_OverrideMap;
283 
285  static void
286  InitializeFactoryList();
287 
289  static void
290  RegisterInternal();
291 
293  static void
294  LoadDynamicFactories();
295 
297  static void
298  LoadLibrariesInPath(const char *);
299 
300  static void
301  DeleteNonInternalFactory(ObjectFactoryBase *);
302 
306  unsigned long m_LibraryDate;
307  std::string m_LibraryPath;
308 
309  static ObjectFactoryBasePrivate * m_PimplGlobals;
310 };
311 } // end namespace itk
312 
313 #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:307
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:306
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:55
itk::ObjectFactoryBase::OverrideInformation::m_Description
std::string m_Description
Definition: itkObjectFactoryBase.h:218
itk::ObjectFactoryBase::m_OverrideMap
OverRideMap * m_OverrideMap
Definition: itkObjectFactoryBase.h:282
itk::ObjectFactoryBase::m_LibraryHandle
void * m_LibraryHandle
Definition: itkObjectFactoryBase.h:305
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:309
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:280
New
static Pointer New()
itk::ObjectFactoryBase::RegisterInternalFactoryOnce
static void RegisterInternalFactoryOnce()
Definition: itkObjectFactoryBase.h:228