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 =========================================================================*/
43 #ifndef __vtkObjectFactory_h
44 #define __vtkObjectFactory_h
45 
46 
47 
48 
49 #include "vtkObject.h"
50 
53 class vtkCollection;
54 
56 {
57 public:
58  // Class Methods used to interface with the registered factories
59 
64  static vtkObject* CreateInstance(const char* vtkclassname);
65 
67 
70  static void CreateAllInstance(const char* vtkclassname,
71  vtkCollection* retList);
72  // Description:
73  // Re-check the VTK_AUTOLOAD_PATH for new factory libraries.
74  // This calls UnRegisterAll before re-loading
75  static void ReHash();
76  // Description:
77  // Register a factory so it can be used to create vtk objects
78  static void RegisterFactory(vtkObjectFactory* );
79  // Description:
80  // Remove a factory from the list of registered factories
81  static void UnRegisterFactory(vtkObjectFactory*);
82  // Description:
83  // Unregister all factories
84  static void UnRegisterAllFactories();
86 
89  static vtkObjectFactoryCollection* GetRegisteredFactories();
90 
93  static int HasOverrideAny(const char* className);
94 
96 
98  static void GetOverrideInformation(const char* name,
101 
103 
105  static void SetAllEnableFlags(int flag,
106  const char* className);
107  // Description:
108  // Set the enable flag for a given named class subclass pair
109  // for all registered factories.
110  static void SetAllEnableFlags(int flag,
111  const char* className,
112  const char* subclassName);
114 
115  // Instance methods to be used on individual instances of vtkObjectFactory
116 
117  // Methods from vtkObject
120  virtual void PrintSelf(ostream& os, vtkIndent indent);
121 
128  virtual const char* GetVTKSourceVersion() = 0;
129 
131  virtual const char* GetDescription() = 0;
132 
134  virtual int GetNumberOfOverrides();
135 
137  virtual const char* GetClassOverrideName(int index);
138 
141  virtual const char* GetClassOverrideWithName(int index);
142 
144  virtual int GetEnableFlag(int index);
145 
147  virtual const char* GetOverrideDescription(int index);
148 
150 
152  virtual void SetEnableFlag(int flag,
153  const char* className,
154  const char* subclassName);
155  virtual int GetEnableFlag(const char* className,
156  const char* subclassName);
158 
160 
161  virtual int HasOverride(const char* className);
162  // Description:
163  // Return 1 if this factory overrides the given class name, 0 otherwise.
164  virtual int HasOverride(const char* className, const char* subclassName);
166 
169  virtual void Disable(const char* className);
170 
172 
173  vtkGetStringMacro(LibraryPath);
175 
176  //BTX
177  typedef vtkObject* (*CreateFunction)();
178  //ETX
179 protected:
180  //BTX
181 
183 
184  void RegisterOverride(const char* classOverride,
185  const char* overrideClassName,
186  const char* description,
187  int enableFlag,
188  CreateFunction createFunction);
190 
191  //ETX
192 
193 
197  virtual vtkObject* CreateObject(const char* vtkclassname );
198 
200  ~vtkObjectFactory();
201  //BTX
203  {
204  char* Description;
207  CreateFunction CreateCallback;
208  };
209  //ETX
214 
215 private:
216  void GrowOverrideArray();
217 
219 
221  static void Init();
222  // Description:
223  // Register default factories which are not loaded at run time.
224  static void RegisterDefaults();
225  // Description:
226  // Load dynamic factories from the VTK_AUTOLOAD_PATH
227  static void LoadDynamicFactories();
228  // Description:
229  // Load all dynamic libraries in the given path
230  static void LoadLibrariesInPath( const char*);
232 
233  // list of registered factories
234  static vtkObjectFactoryCollection* RegisteredFactories;
235 
236  // member variables for a factory set by the base class
237  // at load or register time
238  void* LibraryHandle;
239  char* LibraryVTKVersion;
240  char* LibraryCompilerUsed;
241  char* LibraryPath;
242 private:
243  vtkObjectFactory(const vtkObjectFactory&); // Not implemented.
244  void operator=(const vtkObjectFactory&); // Not implemented.
245 };
246 
247 // Macro to create an object creation function.
248 // The name of the function will by vtkObjectFactoryCreateclassname
249 // where classname is the name of the class being created
250 #define VTK_CREATE_CREATE_FUNCTION(classname) \
251 static vtkObject* vtkObjectFactoryCreate##classname() \
252 { return classname::New(); }
253 
254 #endif
255 
256 #define VTK_FACTORY_INTERFACE_EXPORT VTK_ABI_EXPORT
257 
258 // Macro to create the interface "C" functions used in
259 // a dll or shared library that contains a VTK object factory.
260 // Put this function in the .cxx file of your object factory,
261 // and pass in the name of the factory sub-class that you want
262 // the dll to create.
263 #define VTK_FACTORY_INTERFACE_IMPLEMENT(factoryName) \
264 extern "C" \
265 VTK_FACTORY_INTERFACE_EXPORT \
266 const char* vtkGetFactoryCompilerUsed() \
267 { \
268  return VTK_CXX_COMPILER; \
269 } \
270 extern "C" \
271 VTK_FACTORY_INTERFACE_EXPORT \
272 const char* vtkGetFactoryVersion() \
273 { \
274  return VTK_SOURCE_VERSION; \
275 } \
276 extern "C" \
277 VTK_FACTORY_INTERFACE_EXPORT \
278 vtkObjectFactory* vtkLoad() \
279 { \
280  return factoryName ::New(); \
281 }
maintain a list of override information objects
abstract base class for most VTK objects
Definition: vtkObject.h:60
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
OverrideInformation * OverrideArray
#define VTK_COMMON_EXPORT
maintain a list of object factories
create and manipulate unsorted lists of objects
Definition: vtkCollection.h:51
abstract base class for vtkObjectFactories