VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkObjectFactory.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00043 #ifndef __vtkObjectFactory_h 00044 #define __vtkObjectFactory_h 00045 00046 00047 00048 00049 #include "vtkObject.h" 00050 00051 class vtkObjectFactoryCollection; 00052 class vtkOverrideInformationCollection; 00053 class vtkCollection; 00054 00055 class VTK_COMMON_EXPORT vtkObjectFactory : public vtkObject 00056 { 00057 public: 00058 // Class Methods used to interface with the registered factories 00059 00064 static vtkObject* CreateInstance(const char* vtkclassname); 00065 00067 00070 static void CreateAllInstance(const char* vtkclassname, 00071 vtkCollection* retList); 00072 // Description: 00073 // Re-check the VTK_AUTOLOAD_PATH for new factory libraries. 00074 // This calls UnRegisterAll before re-loading 00075 static void ReHash(); 00076 // Description: 00077 // Register a factory so it can be used to create vtk objects 00078 static void RegisterFactory(vtkObjectFactory* ); 00079 // Description: 00080 // Remove a factory from the list of registered factories 00081 static void UnRegisterFactory(vtkObjectFactory*); 00082 // Description: 00083 // Unregister all factories 00084 static void UnRegisterAllFactories(); 00086 00089 static vtkObjectFactoryCollection* GetRegisteredFactories(); 00090 00093 static int HasOverrideAny(const char* className); 00094 00096 00098 static void GetOverrideInformation(const char* name, 00099 vtkOverrideInformationCollection*); 00101 00103 00105 static void SetAllEnableFlags(int flag, 00106 const char* className); 00107 // Description: 00108 // Set the enable flag for a given named class subclass pair 00109 // for all registered factories. 00110 static void SetAllEnableFlags(int flag, 00111 const char* className, 00112 const char* subclassName); 00114 00115 // Instance methods to be used on individual instances of vtkObjectFactory 00116 00117 // Methods from vtkObject 00118 vtkTypeMacro(vtkObjectFactory,vtkObject); 00120 virtual void PrintSelf(ostream& os, vtkIndent indent); 00121 00128 virtual const char* GetVTKSourceVersion() = 0; 00129 00131 virtual const char* GetDescription() = 0; 00132 00134 virtual int GetNumberOfOverrides(); 00135 00137 virtual const char* GetClassOverrideName(int index); 00138 00141 virtual const char* GetClassOverrideWithName(int index); 00142 00144 virtual int GetEnableFlag(int index); 00145 00147 virtual const char* GetOverrideDescription(int index); 00148 00150 00152 virtual void SetEnableFlag(int flag, 00153 const char* className, 00154 const char* subclassName); 00155 virtual int GetEnableFlag(const char* className, 00156 const char* subclassName); 00158 00160 00161 virtual int HasOverride(const char* className); 00162 // Description: 00163 // Return 1 if this factory overrides the given class name, 0 otherwise. 00164 virtual int HasOverride(const char* className, const char* subclassName); 00166 00169 virtual void Disable(const char* className); 00170 00172 00173 vtkGetStringMacro(LibraryPath); 00175 00176 //BTX 00177 typedef vtkObject* (*CreateFunction)(); 00178 //ETX 00179 protected: 00180 //BTX 00181 00183 00184 void RegisterOverride(const char* classOverride, 00185 const char* overrideClassName, 00186 const char* description, 00187 int enableFlag, 00188 CreateFunction createFunction); 00190 00191 //ETX 00192 00193 00197 virtual vtkObject* CreateObject(const char* vtkclassname ); 00198 00199 vtkObjectFactory(); 00200 ~vtkObjectFactory(); 00201 //BTX 00202 struct OverrideInformation 00203 { 00204 char* Description; 00205 char* OverrideWithName; 00206 int EnabledFlag; 00207 CreateFunction CreateCallback; 00208 }; 00209 //ETX 00210 OverrideInformation* OverrideArray; 00211 char** OverrideClassNames; 00212 int SizeOverrideArray; 00213 int OverrideArrayLength; 00214 00215 private: 00216 void GrowOverrideArray(); 00217 00219 00221 static void Init(); 00222 // Description: 00223 // Register default factories which are not loaded at run time. 00224 static void RegisterDefaults(); 00225 // Description: 00226 // Load dynamic factories from the VTK_AUTOLOAD_PATH 00227 static void LoadDynamicFactories(); 00228 // Description: 00229 // Load all dynamic libraries in the given path 00230 static void LoadLibrariesInPath( const char*); 00232 00233 // list of registered factories 00234 static vtkObjectFactoryCollection* RegisteredFactories; 00235 00236 // member variables for a factory set by the base class 00237 // at load or register time 00238 void* LibraryHandle; 00239 char* LibraryVTKVersion; 00240 char* LibraryCompilerUsed; 00241 char* LibraryPath; 00242 private: 00243 vtkObjectFactory(const vtkObjectFactory&); // Not implemented. 00244 void operator=(const vtkObjectFactory&); // Not implemented. 00245 }; 00246 00247 // Macro to create an object creation function. 00248 // The name of the function will by vtkObjectFactoryCreateclassname 00249 // where classname is the name of the class being created 00250 #define VTK_CREATE_CREATE_FUNCTION(classname) \ 00251 static vtkObject* vtkObjectFactoryCreate##classname() \ 00252 { return classname::New(); } 00253 00254 #endif 00255 00256 #define VTK_FACTORY_INTERFACE_EXPORT VTK_ABI_EXPORT 00257 00258 // Macro to create the interface "C" functions used in 00259 // a dll or shared library that contains a VTK object factory. 00260 // Put this function in the .cxx file of your object factory, 00261 // and pass in the name of the factory sub-class that you want 00262 // the dll to create. 00263 #define VTK_FACTORY_INTERFACE_IMPLEMENT(factoryName) \ 00264 extern "C" \ 00265 VTK_FACTORY_INTERFACE_EXPORT \ 00266 const char* vtkGetFactoryCompilerUsed() \ 00267 { \ 00268 return VTK_CXX_COMPILER; \ 00269 } \ 00270 extern "C" \ 00271 VTK_FACTORY_INTERFACE_EXPORT \ 00272 const char* vtkGetFactoryVersion() \ 00273 { \ 00274 return VTK_SOURCE_VERSION; \ 00275 } \ 00276 extern "C" \ 00277 VTK_FACTORY_INTERFACE_EXPORT \ 00278 vtkObjectFactory* vtkLoad() \ 00279 { \ 00280 return factoryName ::New(); \ 00281 }