VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkObjectFactory.h,v $ 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 =========================================================================*/ 00040 #ifndef __vtkObjectFactory_h 00041 #define __vtkObjectFactory_h 00042 00043 00044 00045 00046 #include "vtkObject.h" 00047 00048 class vtkObjectFactoryCollection; 00049 class vtkOverrideInformationCollection; 00050 class vtkCollection; 00051 00052 class VTK_COMMON_EXPORT vtkObjectFactory : public vtkObject 00053 { 00054 public: 00055 // Class Methods used to interface with the registered factories 00056 00061 static vtkObject* CreateInstance(const char* vtkclassname); 00062 00064 00067 static void CreateAllInstance(const char* vtkclassname, 00068 vtkCollection* retList); 00069 // Description: 00070 // Re-check the VTK_AUTOLOAD_PATH for new factory libraries. 00071 // This calls UnRegisterAll before re-loading 00072 static void ReHash(); 00073 // Description: 00074 // Register a factory so it can be used to create vtk objects 00075 static void RegisterFactory(vtkObjectFactory* ); 00076 // Description: 00077 // Remove a factory from the list of registered factories 00078 static void UnRegisterFactory(vtkObjectFactory*); 00079 // Description: 00080 // Unregister all factories 00081 static void UnRegisterAllFactories(); 00083 00086 static vtkObjectFactoryCollection* GetRegisteredFactories(); 00087 00090 static int HasOverrideAny(const char* className); 00091 00093 00095 static void GetOverrideInformation(const char* name, 00096 vtkOverrideInformationCollection*); 00098 00100 00102 static void SetAllEnableFlags(int flag, 00103 const char* className); 00104 // Description: 00105 // Set the enable flag for a given named class subclass pair 00106 // for all registered factories. 00107 static void SetAllEnableFlags(int flag, 00108 const char* className, 00109 const char* subclassName); 00111 00112 // Instance methods to be used on individual instances of vtkObjectFactory 00113 00114 // Methods from vtkObject 00115 vtkTypeRevisionMacro(vtkObjectFactory,vtkObject); 00117 virtual void PrintSelf(ostream& os, vtkIndent indent); 00118 00125 virtual const char* GetVTKSourceVersion() = 0; 00126 00128 virtual const char* GetDescription() = 0; 00129 00131 virtual int GetNumberOfOverrides(); 00132 00134 virtual const char* GetClassOverrideName(int index); 00135 00138 virtual const char* GetClassOverrideWithName(int index); 00139 00141 virtual int GetEnableFlag(int index); 00142 00144 virtual const char* GetOverrideDescription(int index); 00145 00147 00149 virtual void SetEnableFlag(int flag, 00150 const char* className, 00151 const char* subclassName); 00152 virtual int GetEnableFlag(const char* className, 00153 const char* subclassName); 00155 00157 00158 virtual int HasOverride(const char* className); 00159 // Description: 00160 // Return 1 if this factory overrides the given class name, 0 otherwise. 00161 virtual int HasOverride(const char* className, const char* subclassName); 00163 00166 virtual void Disable(const char* className); 00167 00169 00170 vtkGetStringMacro(LibraryPath); 00172 00173 //BTX 00174 typedef vtkObject* (*CreateFunction)(); 00175 //ETX 00176 protected: 00177 //BTX 00178 00180 00181 void RegisterOverride(const char* classOverride, 00182 const char* overrideClassName, 00183 const char* description, 00184 int enableFlag, 00185 CreateFunction createFunction); 00187 00188 //ETX 00189 00190 00194 virtual vtkObject* CreateObject(const char* vtkclassname ); 00195 00196 vtkObjectFactory(); 00197 ~vtkObjectFactory(); 00198 //BTX 00199 struct OverrideInformation 00200 { 00201 char* Description; 00202 char* OverrideWithName; 00203 int EnabledFlag; 00204 CreateFunction CreateCallback; 00205 }; 00206 //ETX 00207 OverrideInformation* OverrideArray; 00208 char** OverrideClassNames; 00209 int SizeOverrideArray; 00210 int OverrideArrayLength; 00211 00212 private: 00213 void GrowOverrideArray(); 00214 00216 00218 static void Init(); 00219 // Description: 00220 // Register default factories which are not loaded at run time. 00221 static void RegisterDefaults(); 00222 // Description: 00223 // Load dynamic factories from the VTK_AUTOLOAD_PATH 00224 static void LoadDynamicFactories(); 00225 // Description: 00226 // Load all dynamic libraries in the given path 00227 static void LoadLibrariesInPath( const char*); 00229 00230 // list of registered factories 00231 static vtkObjectFactoryCollection* RegisteredFactories; 00232 00233 // member variables for a factory set by the base class 00234 // at load or register time 00235 void* LibraryHandle; 00236 char* LibraryVTKVersion; 00237 char* LibraryCompilerUsed; 00238 char* LibraryPath; 00239 private: 00240 vtkObjectFactory(const vtkObjectFactory&); // Not implemented. 00241 void operator=(const vtkObjectFactory&); // Not implemented. 00242 }; 00243 00244 // Macro to create an object creation function. 00245 // The name of the function will by vtkObjectFactoryCreateclassname 00246 // where classname is the name of the class being created 00247 #define VTK_CREATE_CREATE_FUNCTION(classname) \ 00248 static vtkObject* vtkObjectFactoryCreate##classname() \ 00249 { return classname::New(); } 00250 00251 #endif 00252 00253 00254 #ifdef _WIN32 00255 #define VTK_FACTORY_INTERFACE_EXPORT __declspec( dllexport ) 00256 #else 00257 #define VTK_FACTORY_INTERFACE_EXPORT 00258 #endif 00259 00260 // Macro to create the interface "C" functions used in 00261 // a dll or shared library that contains a VTK object factory. 00262 // Put this function in the .cxx file of your object factory, 00263 // and pass in the name of the factory sub-class that you want 00264 // the dll to create. 00265 #define VTK_FACTORY_INTERFACE_IMPLEMENT(factoryName) \ 00266 extern "C" \ 00267 VTK_FACTORY_INTERFACE_EXPORT \ 00268 const char* vtkGetFactoryCompilerUsed() \ 00269 { \ 00270 return VTK_CXX_COMPILER; \ 00271 } \ 00272 extern "C" \ 00273 VTK_FACTORY_INTERFACE_EXPORT \ 00274 const char* vtkGetFactoryVersion() \ 00275 { \ 00276 return VTK_SOURCE_VERSION; \ 00277 } \ 00278 extern "C" \ 00279 VTK_FACTORY_INTERFACE_EXPORT \ 00280 vtkObjectFactory* vtkLoad() \ 00281 { \ 00282 return factoryName ::New(); \ 00283 }