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

vtkObjectFactory.h

Go to the documentation of this file.
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 =========================================================================*/
00051 #ifndef __vtkObjectFactory_h
00052 #define __vtkObjectFactory_h
00053 
00054 
00055 
00056 
00057 #include "vtkObject.h"
00058 
00059 class vtkObjectFactoryCollection;
00060 class vtkOverrideInformationCollection;
00061 class vtkCollection;
00062 
00063 class VTK_COMMON_EXPORT vtkObjectFactory : public vtkObject
00064 {
00065 public:  
00066   // Class Methods used to interface with the registered factories
00067   
00072   static vtkObject* CreateInstance(const char* vtkclassname);
00073 
00075 
00078   static void CreateAllInstance(const char* vtkclassname,
00079                                 vtkCollection* retList);
00080   // Description:
00081   // Re-check the VTK_AUTOLOAD_PATH for new factory libraries.
00082   // This calls UnRegisterAll before re-loading
00083   static void ReHash(); 
00084   // Description:
00085   // Register a factory so it can be used to create vtk objects
00086   static void RegisterFactory(vtkObjectFactory* );
00087   // Description:
00088   // Remove a factory from the list of registered factories
00089   static void UnRegisterFactory(vtkObjectFactory*);
00090   // Description:
00091   // Unregister all factories
00092   static void UnRegisterAllFactories();
00094   
00097   static vtkObjectFactoryCollection* GetRegisteredFactories();
00098 
00101   static int HasOverrideAny(const char* className);
00102   
00104 
00106   static void GetOverrideInformation(const char* name,
00107                                      vtkOverrideInformationCollection*);
00109   
00111 
00113   static void SetAllEnableFlags(int flag, 
00114                                 const char* className);
00115   // Description:
00116   // Set the enable flag for a given named class subclass pair
00117   // for all registered factories.
00118   static void SetAllEnableFlags(int flag, 
00119                                 const char* className,
00120                                 const char* subclassName);
00122 
00123   // Instance methods to be used on individual instances of vtkObjectFactory
00124   
00125   // Methods from vtkObject
00126   vtkTypeRevisionMacro(vtkObjectFactory,vtkObject);
00128   virtual void PrintSelf(ostream& os, vtkIndent indent);
00129 
00136   virtual const char* GetVTKSourceVersion() = 0;
00137 
00139   virtual const char* GetDescription() = 0;
00140 
00142   virtual int GetNumberOfOverrides();
00143 
00145   virtual const char* GetClassOverrideName(int index);
00146 
00149   virtual const char* GetClassOverrideWithName(int index);
00150   
00152   virtual int GetEnableFlag(int index);
00153 
00155   virtual const char* GetOverrideDescription(int index);
00156 
00158 
00160   virtual void SetEnableFlag(int flag,
00161                              const char* className,
00162                              const char* subclassName);
00163   virtual int GetEnableFlag(const char* className,
00164                             const char* subclassName);
00166 
00168 
00169   virtual int HasOverride(const char* className);
00170   // Description:
00171   // Return 1 if this factory overrides the given class name, 0 otherwise.
00172   virtual int HasOverride(const char* className, const char* subclassName);
00174   
00177   virtual void Disable(const char* className);
00178   
00180 
00181   vtkGetStringMacro(LibraryPath);
00183 
00184   //BTX
00185   typedef vtkObject* (*CreateFunction)();
00186   //ETX
00187 protected:
00188   //BTX
00189 
00191 
00192   void RegisterOverride(const char* classOverride,
00193                         const char* overrideClassName,
00194                         const char* description,
00195                         int enableFlag,
00196                         CreateFunction createFunction);
00198                 
00199   //ETX
00200 
00201         
00205   virtual vtkObject* CreateObject(const char* vtkclassname );
00206   
00207   vtkObjectFactory();
00208   ~vtkObjectFactory();
00209   //BTX
00210   struct OverrideInformation
00211   {
00212     char* Description;
00213     char* OverrideWithName;
00214     int EnabledFlag;
00215     CreateFunction CreateCallback;
00216   };
00217   //ETX
00218   OverrideInformation* OverrideArray;
00219   char** OverrideClassNames;
00220   int SizeOverrideArray;
00221   int OverrideArrayLength;
00222 
00223 private:
00224   void GrowOverrideArray();
00225 
00227 
00229   static void Init();
00230   // Description:
00231   // Register default factories which are not loaded at run time.
00232   static void RegisterDefaults();
00233   // Description:
00234   // Load dynamic factories from the VTK_AUTOLOAD_PATH
00235   static void LoadDynamicFactories();
00236   // Description:
00237   // Load all dynamic libraries in the given path
00238   static void LoadLibrariesInPath( const char*);
00240   
00241   // list of registered factories
00242   static vtkObjectFactoryCollection* RegisteredFactories; 
00243   
00244   // member variables for a factory set by the base class
00245   // at load or register time
00246   void* LibraryHandle;
00247   char* LibraryVTKVersion;
00248   char* LibraryCompilerUsed;
00249   char* LibraryPath;
00250 private:
00251   vtkObjectFactory(const vtkObjectFactory&);  // Not implemented.
00252   void operator=(const vtkObjectFactory&);  // Not implemented.
00253 };
00254 
00255 // Macro to create an object creation function.
00256 // The name of the function will by vtkObjectFactoryCreateclassname
00257 // where classname is the name of the class being created
00258 #define VTK_CREATE_CREATE_FUNCTION(classname) \
00259 static vtkObject* vtkObjectFactoryCreate##classname() \
00260 { return classname::New(); }
00261 
00262 #endif
00263 
00264 
00265 #ifdef _WIN32
00266 #define VTK_FACTORY_INTERFACE_EXPORT  __declspec( dllexport )
00267 #else
00268 #define VTK_FACTORY_INTERFACE_EXPORT 
00269 #endif
00270 
00271 // Macro to create the interface "C" functions used in
00272 // a dll or shared library that contains a VTK object factory.
00273 // Put this function in the .cxx file of your object factory,
00274 // and pass in the name of the factory sub-class that you want
00275 // the dll to create.
00276 #define VTK_FACTORY_INTERFACE_IMPLEMENT(factoryName)  \
00277 extern "C"                                      \
00278 VTK_FACTORY_INTERFACE_EXPORT                    \
00279 const char* vtkGetFactoryCompilerUsed()         \
00280 {                                               \
00281   return VTK_CXX_COMPILER;                      \
00282 }                                               \
00283 extern "C"                                      \
00284 VTK_FACTORY_INTERFACE_EXPORT                    \
00285 const char* vtkGetFactoryVersion()              \
00286 {                                               \
00287   return VTK_SOURCE_VERSION;                    \
00288 }                                               \
00289 extern "C"                                      \
00290 VTK_FACTORY_INTERFACE_EXPORT                    \
00291 vtkObjectFactory* vtkLoad()                     \
00292 {                                               \
00293   return factoryName ::New();                   \
00294 }