Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

dox/Common/vtkObjectFactory.h

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