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); 00073 00075 static void ReHash(); 00077 static void RegisterFactory(vtkObjectFactory* ); 00079 static void UnRegisterFactory(vtkObjectFactory*); 00081 static void UnRegisterAllFactories(); 00082 00085 static vtkObjectFactoryCollection* GetRegisteredFactories(); 00086 00089 static int HasOverrideAny(const char* className); 00090 00092 00094 static void GetOverrideInformation(const char* name, 00095 vtkOverrideInformationCollection*); 00097 00099 00101 static void SetAllEnableFlags(int flag, 00102 const char* className); 00104 00105 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 vtkTypeMacro(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 virtual int HasOverride(const char* className); 00159 virtual int HasOverride(const char* className, const char* subclassName); 00160 00163 virtual void Disable(const char* className); 00164 00166 00167 vtkGetStringMacro(LibraryPath); 00169 00170 //BTX 00171 typedef vtkObject* (*CreateFunction)(); 00172 //ETX 00173 protected: 00174 //BTX 00175 00177 00178 void RegisterOverride(const char* classOverride, 00179 const char* overrideClassName, 00180 const char* description, 00181 int enableFlag, 00182 CreateFunction createFunction); 00184 00185 //ETX 00186 00187 00191 virtual vtkObject* CreateObject(const char* vtkclassname ); 00192 00193 vtkObjectFactory(); 00194 ~vtkObjectFactory(); 00195 //BTX 00196 struct OverrideInformation 00197 { 00198 char* Description; 00199 char* OverrideWithName; 00200 int EnabledFlag; 00201 CreateFunction CreateCallback; 00202 }; 00203 //ETX 00204 OverrideInformation* OverrideArray; 00205 char** OverrideClassNames; 00206 int SizeOverrideArray; 00207 int OverrideArrayLength; 00208 00209 private: 00210 void GrowOverrideArray(); 00211 00214 static void Init(); 00216 static void RegisterDefaults(); 00218 static void LoadDynamicFactories(); 00220 static void LoadLibrariesInPath( const char*); 00221 00222 // list of registered factories 00223 static vtkObjectFactoryCollection* RegisteredFactories; 00224 00225 // member variables for a factory set by the base class 00226 // at load or register time 00227 void* LibraryHandle; 00228 char* LibraryVTKVersion; 00229 char* LibraryCompilerUsed; 00230 char* LibraryPath; 00231 private: 00232 vtkObjectFactory(const vtkObjectFactory&); // Not implemented. 00233 void operator=(const vtkObjectFactory&); // Not implemented. 00234 }; 00235 00236 // Macro to create an object creation function. 00237 // The name of the function will by vtkObjectFactoryCreateclassname 00238 // where classname is the name of the class being created 00239 #define VTK_CREATE_CREATE_FUNCTION(classname) \ 00240 static vtkObject* vtkObjectFactoryCreate##classname() \ 00241 { return classname::New(); } 00242 00243 #endif 00244 00245 #define VTK_FACTORY_INTERFACE_EXPORT VTK_ABI_EXPORT 00246 00247 // Macro to create the interface "C" functions used in 00248 // a dll or shared library that contains a VTK object factory. 00249 // Put this function in the .cxx file of your object factory, 00250 // and pass in the name of the factory sub-class that you want 00251 // the dll to create. 00252 #define VTK_FACTORY_INTERFACE_IMPLEMENT(factoryName) \ 00253 extern "C" \ 00254 VTK_FACTORY_INTERFACE_EXPORT \ 00255 const char* vtkGetFactoryCompilerUsed() \ 00256 { \ 00257 return VTK_CXX_COMPILER; \ 00258 } \ 00259 extern "C" \ 00260 VTK_FACTORY_INTERFACE_EXPORT \ 00261 const char* vtkGetFactoryVersion() \ 00262 { \ 00263 return VTK_SOURCE_VERSION; \ 00264 } \ 00265 extern "C" \ 00266 VTK_FACTORY_INTERFACE_EXPORT \ 00267 vtkObjectFactory* vtkLoad() \ 00268 { \ 00269 return factoryName ::New(); \ 00270 }