VTK
vtkObjectFactory.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkObjectFactory.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
40 #ifndef vtkObjectFactory_h
41 #define vtkObjectFactory_h
42 
43 #include "vtkCommonCoreModule.h" // For export macro
44 #include "vtkObject.h"
45 
48 class vtkCollection;
49 
51 {
52 public:
53  // Class Methods used to interface with the registered factories
54 
59  static vtkObject* CreateInstance(const char* vtkclassname);
60 
63  static void ConstructInstance(const char* vtkclassname);
64 
66 
69  static void CreateAllInstance(const char* vtkclassname,
70  vtkCollection* retList);
72 
74  static void ReHash();
76  static void RegisterFactory(vtkObjectFactory* );
78  static void UnRegisterFactory(vtkObjectFactory*);
80  static void UnRegisterAllFactories();
81 
84  static vtkObjectFactoryCollection* GetRegisteredFactories();
85 
88  static int HasOverrideAny(const char* className);
89 
91 
93  static void GetOverrideInformation(const char* name,
96 
98 
100  static void SetAllEnableFlags(int flag,
101  const char* className);
103 
104 
106  static void SetAllEnableFlags(int flag,
107  const char* className,
108  const char* subclassName);
110 
111  // Instance methods to be used on individual instances of vtkObjectFactory
112 
113  // Methods from vtkObject
116  virtual void PrintSelf(ostream& os, vtkIndent indent);
117 
124  virtual const char* GetVTKSourceVersion() = 0;
125 
127  virtual const char* GetDescription() = 0;
128 
130  virtual int GetNumberOfOverrides();
131 
133  virtual const char* GetClassOverrideName(int index);
134 
137  virtual const char* GetClassOverrideWithName(int index);
138 
140  virtual int GetEnableFlag(int index);
141 
143  virtual const char* GetOverrideDescription(int index);
144 
146 
148  virtual void SetEnableFlag(int flag,
149  const char* className,
150  const char* subclassName);
151  virtual int GetEnableFlag(const char* className,
152  const char* subclassName);
154 
156  virtual int HasOverride(const char* className);
158  virtual int HasOverride(const char* className, const char* subclassName);
159 
162  virtual void Disable(const char* className);
163 
165 
166  vtkGetStringMacro(LibraryPath);
168 
169  //BTX
170  typedef vtkObject* (*CreateFunction)();
171  //ETX
172 protected:
173  //BTX
174 
176 
177  void RegisterOverride(const char* classOverride,
178  const char* overrideClassName,
179  const char* description,
180  int enableFlag,
181  CreateFunction createFunction);
183 
184  //ETX
185 
186 
190  virtual vtkObject* CreateObject(const char* vtkclassname );
191 
193  ~vtkObjectFactory();
194  //BTX
196  {
197  char* Description;
200  CreateFunction CreateCallback;
201  };
202  //ETX
207 
208 private:
209  void GrowOverrideArray();
210 
213  static void Init();
215  static void RegisterDefaults();
217  static void LoadDynamicFactories();
219  static void LoadLibrariesInPath( const char*);
220 
221  // list of registered factories
222  static vtkObjectFactoryCollection* RegisteredFactories;
223 
224  // member variables for a factory set by the base class
225  // at load or register time
226  void* LibraryHandle;
227  char* LibraryVTKVersion;
228  char* LibraryCompilerUsed;
229  char* LibraryPath;
230 private:
231  vtkObjectFactory(const vtkObjectFactory&); // Not implemented.
232  void operator=(const vtkObjectFactory&); // Not implemented.
233 };
234 
235 // Macro to create an object creation function.
236 // The name of the function will by vtkObjectFactoryCreateclassname
237 // where classname is the name of the class being created
238 #define VTK_CREATE_CREATE_FUNCTION(classname) \
239 static vtkObject* vtkObjectFactoryCreate##classname() \
240 { return classname::New(); }
241 
242 #endif
243 
244 #define VTK_FACTORY_INTERFACE_EXPORT VTKCOMMONCORE_EXPORT
245 
246 // Macro to create the interface "C" functions used in
247 // a dll or shared library that contains a VTK object factory.
248 // Put this function in the .cxx file of your object factory,
249 // and pass in the name of the factory sub-class that you want
250 // the dll to create.
251 #define VTK_FACTORY_INTERFACE_IMPLEMENT(factoryName) \
252 extern "C" \
253 VTK_FACTORY_INTERFACE_EXPORT \
254 const char* vtkGetFactoryCompilerUsed() \
255 { \
256  return VTK_CXX_COMPILER; \
257 } \
258 extern "C" \
259 VTK_FACTORY_INTERFACE_EXPORT \
260 const char* vtkGetFactoryVersion() \
261 { \
262  return VTK_SOURCE_VERSION; \
263 } \
264 extern "C" \
265 VTK_FACTORY_INTERFACE_EXPORT \
266 vtkObjectFactory* vtkLoad() \
267 { \
268  return factoryName ::New(); \
269 }
270 
271 // Macro to implement the body of the object factory form of the New() method.
272 #define VTK_OBJECT_FACTORY_NEW_BODY(thisClass) \
273  vtkObject* ret = vtkObjectFactory::CreateInstance(#thisClass); \
274  if(ret) \
275  { \
276  return static_cast<thisClass*>(ret); \
277  } \
278  return new thisClass;
279 
280 // Macro to implement the body of the abstract object factory form of the New()
281 // method, i.e. an abstract base class that can only be instantiated if the
282 // object factory overrides it.
283 #define VTK_ABSTRACT_OBJECT_FACTORY_NEW_BODY(thisClass) \
284  vtkObject* ret = vtkObjectFactory::CreateInstance(#thisClass); \
285  if(ret) \
286  { \
287  return static_cast<thisClass*>(ret); \
288  } \
289  vtkGenericWarningMacro("Error: no override found for '" #thisClass "'."); \
290  return NULL;
291 
292 // Macro to implement the body of the standard form of the New() method.
293 #if defined(VTK_ALL_NEW_OBJECT_FACTORY)
294 # define VTK_STANDARD_NEW_BODY(thisClass) \
295  VTK_OBJECT_FACTORY_NEW_BODY(thisClass)
296 #elif defined(VTK_DEBUG_LEAKS)
297 # define VTK_STANDARD_NEW_BODY(thisClass) \
298  thisClass *result = new thisClass; \
299  vtkObjectFactory::ConstructInstance(result->GetClassName()); \
300  return result;
301 #else
302 # define VTK_STANDARD_NEW_BODY(thisClass) \
303  return new thisClass;
304 #endif
305 
306 // Macro to implement the standard form of the New() method.
307 #define vtkStandardNewMacro(thisClass) \
308  thisClass* thisClass::New() \
309  { \
310  VTK_STANDARD_NEW_BODY(thisClass) \
311  }
312 
313 // Macro to implement the object factory form of the New() method.
314 #define vtkObjectFactoryNewMacro(thisClass) \
315  thisClass* thisClass::New() \
316  { \
317  VTK_OBJECT_FACTORY_NEW_BODY(thisClass) \
318  }
319 
320 // Macro to implement the abstract object factory form of the New() method.
321 // That is an abstract base class that can only be instantiated if the
322 // object factory overrides it.
323 #define vtkAbstractObjectFactoryNewMacro(thisClass) \
324  thisClass* thisClass::New() \
325  { \
326  VTK_ABSTRACT_OBJECT_FACTORY_NEW_BODY(thisClass) \
327  }
maintain a list of override information objects
abstract base class for most VTK objects
Definition: vtkObject.h:61
#define VTKCOMMONCORE_EXPORT
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
OverrideInformation * OverrideArray
maintain a list of object factories
create and manipulate unsorted lists of objects
Definition: vtkCollection.h:52
abstract base class for vtkObjectFactories