ITK  6.0.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 <memory> // For unique_ptr.
36#include <vector>
37
38namespace itk
39{
59class ITKCommon_EXPORT ObjectFactoryBase : public Object
60{
61public:
62 ITK_DISALLOW_COPY_AND_MOVE(ObjectFactoryBase);
63
69
71 itkOverrideGetNameOfClassMacro(ObjectFactoryBase);
72
82 CreateInstance(const char * itkclassname);
83
88 static std::list<LightObject::Pointer>
89 CreateAllInstance(const char * itkclassname);
90
93 static void
95
103 static void
105
107#if !defined(ITK_LEGACY_REMOVE)
108 // We need to expose the enum values at the class level
109 // for backwards compatibility
110 static constexpr InsertionPositionEnum INSERT_AT_FRONT = InsertionPositionEnum::INSERT_AT_FRONT;
111 static constexpr InsertionPositionEnum INSERT_AT_BACK = InsertionPositionEnum::INSERT_AT_BACK;
112 static constexpr InsertionPositionEnum INSERT_AT_POSITION = InsertionPositionEnum::INSERT_AT_POSITION;
113#endif
114
133 static bool
135 InsertionPositionEnum where = InsertionPositionEnum::INSERT_AT_BACK,
136 size_t position = 0);
140 static void
142
144 static void
146
149 static std::list<ObjectFactoryBase *>
151
157 virtual const char *
159
165 static void
167 static void
169 static void
171 static bool
176 virtual const char *
177 GetDescription() const = 0;
178
180 virtual std::list<std::string>
182
184 virtual std::list<std::string>
186
188 virtual std::list<std::string>
190
192 virtual std::list<bool>
194
196 virtual void
197 SetEnableFlag(bool flag, const char * className, const char * subclassName);
198
200 virtual bool
201 GetEnableFlag(const char * className, const char * subclassName);
202
206 virtual void
207 Disable(const char * className);
208
210 const char *
212
215 template <typename TFactory>
216 static void
218 {
219 struct FactoryRegistration
220 {};
221
222 // Factory registration, made thread-safe by "magic statics" (as introduced with C++11).
223 [[maybe_unused]] static const FactoryRegistration staticFactoryRegistration = [] {
224 RegisterFactoryInternal(TFactory::New());
225 return FactoryRegistration{};
226 }();
227 }
228
230 static void
232
233protected:
234 void
235 PrintSelf(std::ostream & os, Indent indent) const override;
236
238 void
239 RegisterOverride(const char * classOverride,
240 const char * subclass,
241 const char * description,
242 bool enableFlag,
243 CreateObjectFunctionBase * createFunction);
244
249 CreateObject(const char * itkclassname);
250
254 virtual std::list<LightObject::Pointer>
255 CreateAllObject(const char * itkclassname);
256
259
260private:
261 // Forward reference because of private implementation
262 class OverrideMap;
263 class ObjectFactoryBasePrivate;
264
267 static void
268 SynchronizeObjectFactoryBase(void * objectFactoryBasePrivate);
269 itkGetGlobalDeclarationMacro(ObjectFactoryBasePrivate, PimplGlobals);
272 const std::unique_ptr<OverrideMap> m_OverrideMap;
273
275 static void
277
279 static void
280 LoadLibrariesInPath(const char *);
281
282 static void
284
287 void * m_LibraryHandle{};
288 unsigned long m_LibraryDate{};
289 std::string m_LibraryPath{};
290
291 static ObjectFactoryBasePrivate * m_PimplGlobals;
292};
293} // end namespace itk
294
295#endif
Define API for object creation callback functions.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Create instances of classes using an object factory.
virtual void SetEnableFlag(bool flag, const char *className, const char *subclassName)
virtual std::list< std::string > GetClassOverrideDescriptions()
static void UnRegisterAllFactories()
static void StrictVersionCheckingOn()
static void ReHash()
static void UnRegisterFactory(ObjectFactoryBase *)
virtual const char * GetITKSourceVersion() const =0
~ObjectFactoryBase() override
const char * GetLibraryPath()
void PrintSelf(std::ostream &os, Indent indent) const override
static LightObject::Pointer CreateInstance(const char *itkclassname)
void RegisterOverride(const char *classOverride, const char *subclass, const char *description, bool enableFlag, CreateObjectFunctionBase *createFunction)
static void RegisterFactoryInternal(ObjectFactoryBase *)
virtual std::list< std::string > GetClassOverrideNames()
virtual void Disable(const char *className)
virtual LightObject::Pointer CreateObject(const char *itkclassname)
virtual std::list< LightObject::Pointer > CreateAllObject(const char *itkclassname)
static ObjectFactoryBasePrivate * m_PimplGlobals
virtual std::list< bool > GetEnableFlags()
static void DeleteNonInternalFactory(ObjectFactoryBase *)
static bool GetStrictVersionChecking()
static bool RegisterFactory(ObjectFactoryBase *, InsertionPositionEnum where=InsertionPositionEnum::INSERT_AT_BACK, vcl_size_t position=0)
const std::unique_ptr< OverrideMap > m_OverrideMap
static void LoadDynamicFactories()
virtual const char * GetDescription() const =0
static void SynchronizeObjectFactoryBase(void *objectFactoryBasePrivate)
static void StrictVersionCheckingOff()
static void RegisterInternalFactoryOnce()
static std::list< ObjectFactoryBase * > GetRegisteredFactories()
static void Initialize()
virtual bool GetEnableFlag(const char *className, const char *subclassName)
virtual std::list< std::string > GetClassOverrideWithNames()
static void SetStrictVersionChecking(bool)
static std::list< LightObject::Pointer > CreateAllInstance(const char *itkclassname)
itkGetGlobalDeclarationMacro(ObjectFactoryBasePrivate, PimplGlobals)
static void LoadLibrariesInPath(const char *)
Base class for most ITK classes.
Definition: itkObject.h:62
static Pointer New()
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....