ITK  5.1.0
Insight Toolkit
itkObjectFactoryBase.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 /*=========================================================================
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 "ITKCommonExport.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_ASSIGN(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 
113  {
114  INSERT_AT_FRONT,
115  INSERT_AT_BACK,
116  INSERT_AT_POSITION
117  };
118 #if !defined(ITK_LEGACY_REMOVE) || defined(ITK_WRAPPING) /* castxml 'enum class' workaround */
119  // We need to expose the enum values at the class level
120  // for backwards compatibility
121  static constexpr InsertionPositionType INSERT_AT_FRONT = InsertionPositionType::INSERT_AT_FRONT;
122  static constexpr InsertionPositionType INSERT_AT_BACK = InsertionPositionType::INSERT_AT_BACK;
123  static constexpr InsertionPositionType INSERT_AT_POSITION = InsertionPositionType::INSERT_AT_POSITION;
124 #endif
125 
144  static bool
145  RegisterFactory(ObjectFactoryBase *,
146  InsertionPositionType where = InsertionPositionType::INSERT_AT_BACK,
147  size_t position = 0);
149 
151  static void
152  UnRegisterFactory(ObjectFactoryBase *);
153 
155  static void
156  UnRegisterAllFactories();
157 
160  static std::list<ObjectFactoryBase *>
161  GetRegisteredFactories();
162 
168  virtual const char *
169  GetITKSourceVersion() const = 0;
170 
176  static void
177  SetStrictVersionChecking(bool);
178  static void
179  StrictVersionCheckingOn();
180  static void
181  StrictVersionCheckingOff();
182  static bool
183  GetStrictVersionChecking();
185 
187  virtual const char *
188  GetDescription() const = 0;
189 
191  virtual std::list<std::string>
192  GetClassOverrideNames();
193 
195  virtual std::list<std::string>
196  GetClassOverrideWithNames();
197 
199  virtual std::list<std::string>
200  GetClassOverrideDescriptions();
201 
203  virtual std::list<bool>
204  GetEnableFlags();
205 
207  virtual void
208  SetEnableFlag(bool flag, const char * className, const char * subclassName);
209 
211  virtual bool
212  GetEnableFlag(const char * className, const char * subclassName);
213 
217  virtual void
218  Disable(const char * className);
219 
221  const char *
222  GetLibraryPath();
223 
229  {
230  std::string m_Description;
231  std::string m_OverrideWithName;
234  };
235 
236 protected:
237  void
238  PrintSelf(std::ostream & os, Indent indent) const override;
239 
241  void
242  RegisterOverride(const char * classOverride,
243  const char * overrideClassName,
244  const char * description,
245  bool enableFlag,
246  CreateObjectFunctionBase * createFunction);
247 
251  virtual LightObject::Pointer
252  CreateObject(const char * itkclassname);
253 
257  virtual std::list<LightObject::Pointer>
258  CreateAllObject(const char * itkclassname);
259 
261  ~ObjectFactoryBase() override;
262 
263 private:
266  static void
267  SynchronizeObjectFactoryBase(void * objectFactoryBasePrivate);
268  itkGetGlobalDeclarationMacro(ObjectFactoryBasePrivate, PimplGlobals);
270 
271  OverRideMap * m_OverrideMap;
272 
274  static void
275  InitializeFactoryList();
276 
279  static void
280  Initialize();
281 
283  static void
284  RegisterInternal();
285 
287  static void
288  LoadDynamicFactories();
289 
291  static void
292  LoadLibrariesInPath(const char *);
293 
294  static void
295  DeleteNonInternalFactory(ObjectFactoryBase *);
296 
300  unsigned long m_LibraryDate;
301  std::string m_LibraryPath;
302 
303  static ObjectFactoryBasePrivate * m_PimplGlobals;
304 };
305 
306 // Define how to print enumeration
307 extern ITKCommon_EXPORT std::ostream &
308  operator<<(std::ostream & out, const ObjectFactoryBase::InsertionPositionType value);
309 
310 } // end namespace itk
311 
312 #endif
itk::uint8_t
::uint8_t uint8_t
Definition: itkIntTypes.h:29
itkCreateObjectFunction.h
itk::ObjectFactoryBase
Create instances of classes using an object factory.
Definition: itkObjectFactoryBase.h:62
InsertionPositionType
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:211
itk::ObjectFactoryBase::m_LibraryPath
std::string m_LibraryPath
Definition: itkObjectFactoryBase.h:301
itk::ObjectFactoryBase::OverrideInformation
Internal implementation class for ObjectFactorBase.
Definition: itkObjectFactoryBase.h:228
itk::ObjectFactoryBase::OverrideInformation::m_OverrideWithName
std::string m_OverrideWithName
Definition: itkObjectFactoryBase.h:231
itk::ObjectFactoryBase::m_LibraryDate
unsigned long m_LibraryDate
Definition: itkObjectFactoryBase.h:300
itk::ObjectFactoryBase::OverrideInformation::m_EnabledFlag
bool m_EnabledFlag
Definition: itkObjectFactoryBase.h:232
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:230
itk::ObjectFactoryBase::m_OverrideMap
OverRideMap * m_OverrideMap
Definition: itkObjectFactoryBase.h:271
itk::ObjectFactoryBase::InsertionPositionType
InsertionPositionType
Definition: itkObjectFactoryBase.h:112
itk::ObjectFactoryBase::m_LibraryHandle
void * m_LibraryHandle
Definition: itkObjectFactoryBase.h:299
itk::ObjectFactoryBase::OverrideInformation::m_CreateObject
CreateObjectFunctionBase::Pointer m_CreateObject
Definition: itkObjectFactoryBase.h:233
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::ObjectFactoryBase::m_PimplGlobals
static ObjectFactoryBasePrivate * m_PimplGlobals
Definition: itkObjectFactoryBase.h:303
itkGetGlobalDeclarationMacro
#define itkGetGlobalDeclarationMacro(Type, VarName)
Definition: itkSingletonMacro.h:34
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60