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);
73 
75  static void ReHash();
77  static void RegisterFactory(vtkObjectFactory* );
79  static void UnRegisterFactory(vtkObjectFactory*);
81  static void UnRegisterAllFactories();
82 
85  static vtkObjectFactoryCollection* GetRegisteredFactories();
86 
89  static int HasOverrideAny(const char* className);
90 
92 
94  static void GetOverrideInformation(const char* name,
97 
99 
101  static void SetAllEnableFlags(int flag,
102  const char* className);
104 
105 
107  static void SetAllEnableFlags(int flag,
108  const char* className,
109  const char* subclassName);
111 
112  // Instance methods to be used on individual instances of vtkObjectFactory
113 
114  // Methods from vtkObject
117  virtual void PrintSelf(ostream& os, vtkIndent indent);
118 
125  virtual const char* GetVTKSourceVersion() = 0;
126 
128  virtual const char* GetDescription() = 0;
129 
131  virtual int GetNumberOfOverrides();
132 
134  virtual const char* GetClassOverrideName(int index);
135 
138  virtual const char* GetClassOverrideWithName(int index);
139 
141  virtual int GetEnableFlag(int index);
142 
144  virtual const char* GetOverrideDescription(int index);
145 
147 
149  virtual void SetEnableFlag(int flag,
150  const char* className,
151  const char* subclassName);
152  virtual int GetEnableFlag(const char* className,
153  const char* subclassName);
155 
157  virtual int HasOverride(const char* className);
159  virtual int HasOverride(const char* className, const char* subclassName);
160 
163  virtual void Disable(const char* className);
164 
166 
167  vtkGetStringMacro(LibraryPath);
169 
170  //BTX
171  typedef vtkObject* (*CreateFunction)();
172  //ETX
173 protected:
174  //BTX
175 
177 
178  void RegisterOverride(const char* classOverride,
179  const char* overrideClassName,
180  const char* description,
181  int enableFlag,
182  CreateFunction createFunction);
184 
185  //ETX
186 
187 
191  virtual vtkObject* CreateObject(const char* vtkclassname );
192 
194  ~vtkObjectFactory();
195  //BTX
197  {
198  char* Description;
201  CreateFunction CreateCallback;
202  };
203  //ETX
208 
209 private:
210  void GrowOverrideArray();
211 
214  static void Init();
216  static void RegisterDefaults();
218  static void LoadDynamicFactories();
220  static void LoadLibrariesInPath( const char*);
221 
222  // list of registered factories
223  static vtkObjectFactoryCollection* RegisteredFactories;
224 
225  // member variables for a factory set by the base class
226  // at load or register time
227  void* LibraryHandle;
228  char* LibraryVTKVersion;
229  char* LibraryCompilerUsed;
230  char* LibraryPath;
231 private:
232  vtkObjectFactory(const vtkObjectFactory&); // Not implemented.
233  void operator=(const vtkObjectFactory&); // Not implemented.
234 };
235 
236 // Macro to create an object creation function.
237 // The name of the function will by vtkObjectFactoryCreateclassname
238 // where classname is the name of the class being created
239 #define VTK_CREATE_CREATE_FUNCTION(classname) \
240 static vtkObject* vtkObjectFactoryCreate##classname() \
241 { return classname::New(); }
242 
243 #endif
244 
245 #define VTK_FACTORY_INTERFACE_EXPORT VTK_ABI_EXPORT
246 
247 // Macro to create the interface "C" functions used in
248 // a dll or shared library that contains a VTK object factory.
249 // Put this function in the .cxx file of your object factory,
250 // and pass in the name of the factory sub-class that you want
251 // the dll to create.
252 #define VTK_FACTORY_INTERFACE_IMPLEMENT(factoryName) \
253 extern "C" \
254 VTK_FACTORY_INTERFACE_EXPORT \
255 const char* vtkGetFactoryCompilerUsed() \
256 { \
257  return VTK_CXX_COMPILER; \
258 } \
259 extern "C" \
260 VTK_FACTORY_INTERFACE_EXPORT \
261 const char* vtkGetFactoryVersion() \
262 { \
263  return VTK_SOURCE_VERSION; \
264 } \
265 extern "C" \
266 VTK_FACTORY_INTERFACE_EXPORT \
267 vtkObjectFactory* vtkLoad() \
268 { \
269  return factoryName ::New(); \
270 }