Common/vtkObjectFactory.h Source File

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

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