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-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00008 All rights reserved.
00009 
00010 Redistribution and use in source and binary forms, with or without
00011 modification, are permitted provided that the following conditions are met:
00012 
00013  * Redistributions of source code must retain the above copyright notice,
00014    this list of conditions and the following disclaimer.
00015 
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019 
00020  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00021    of any contributors may be used to endorse or promote products derived
00022    from this software without specific prior written permission.
00023 
00024  * Modified source versions must be plainly marked as such, and must not be
00025    misrepresented as being the original software.
00026 
00027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00028 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00031 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00032 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00033 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00034 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00035 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 
00038 =========================================================================*/
00072 #ifndef __vtkObjectFactory_h
00073 #define __vtkObjectFactory_h
00074 
00075 
00076 
00077 
00078 #include "vtkObject.h"
00079 
00080 class vtkObjectFactoryCollection;
00081 class vtkOverrideInformationCollection;
00082 
00083 class VTK_COMMON_EXPORT vtkObjectFactory : public vtkObject
00084 {
00085 public:  
00086   // Class Methods used to interface with the registered factories
00087   
00089 
00093   static vtkObject* CreateInstance(const char* vtkclassname);
00094   // Description:
00095   // Re-check the VTK_AUTOLOAD_PATH for new factory libraries.
00096   // This calls UnRegisterAll before re-loading
00097   static void ReHash(); 
00098   // Description:
00099   // Register a factory so it can be used to create vtk objects
00100   static void RegisterFactory(vtkObjectFactory* );
00101   // Description:
00102   // Remove a factory from the list of registered factories
00103   static void UnRegisterFactory(vtkObjectFactory*);
00104   // Description:
00105   // Unregister all factories
00106   static void UnRegisterAllFactories();
00108   
00111   static vtkObjectFactoryCollection* GetRegisteredFactories();
00112 
00115   static int HasOverrideAny(const char* className);
00116   
00118 
00120   static void GetOverrideInformation(const char* name,
00121                                      vtkOverrideInformationCollection*);
00123   
00125 
00127   static void SetAllEnableFlags(int flag, 
00128                                 const char* className);
00129   // Description:
00130   // Set the enable flag for a given named class subclass pair
00131   // for all registered factories.
00132   static void SetAllEnableFlags(int flag, 
00133                                 const char* className,
00134                                 const char* subclassName);
00136 
00137   // Instance methods to be used on individual instances of vtkObjectFactory
00138   
00139   // Methods from vtkObject
00140   vtkTypeMacro(vtkObjectFactory,vtkObject);
00142   virtual void PrintSelf(ostream& os, vtkIndent indent);
00143 
00150   virtual const char* GetVTKSourceVersion() = 0;
00151 
00153   virtual const char* GetDescription() = 0;
00154 
00156   virtual int GetNumberOfOverrides();
00157 
00159   virtual const char* GetClassOverrideName(int index);
00160 
00163   virtual const char* GetClassOverrideWithName(int index);
00164   
00166   virtual int GetEnableFlag(int index);
00167 
00169   virtual const char* GetOverrideDescription(int index);
00170 
00172 
00174   virtual void SetEnableFlag(int flag,
00175                              const char* className,
00176                              const char* subclassName);
00177   virtual int GetEnableFlag(const char* className,
00178                             const char* subclassName);
00180 
00182 
00183   virtual int HasOverride(const char* className);
00184   // Description:
00185   // Return 1 if this factory overrides the given class name, 0 otherwise.
00186   virtual int HasOverride(const char* className, const char* subclassName);
00188   
00191   virtual void Disable(const char* className);
00192   
00194 
00195   vtkGetStringMacro(LibraryPath);
00197 
00198   //BTX
00199   typedef vtkObject* (*CreateFunction)();
00200   //ETX
00201 protected:
00202   //BTX
00203 
00205 
00206   void RegisterOverride(const char* classOverride,
00207                         const char* overrideClassName,
00208                         const char* description,
00209                         int enableFlag,
00210                         CreateFunction createFunction);
00212                 
00213   //ETX
00214 
00215         
00219   virtual vtkObject* CreateObject(const char* vtkclassname );
00220   
00221   vtkObjectFactory();
00222   ~vtkObjectFactory();
00223   //BTX
00224   struct OverrideInformation
00225   {
00226     char* Description;
00227     char* OverrideWithName;
00228     int EnabledFlag;
00229     CreateFunction CreateCallback;
00230   };
00231   //ETX
00232   OverrideInformation* OverrideArray;
00233   char** OverrideClassNames;
00234   int SizeOverrideArray;
00235   int OverrideArrayLength;
00236 
00237 private:
00238   void GrowOverrideArray();
00239 
00241 
00243   static void Init();
00244   // Description:
00245   // Register default factories which are not loaded at run time.
00246   static void RegisterDefaults();
00247   // Description:
00248   // Load dynamic factories from the VTK_AUTOLOAD_PATH
00249   static void LoadDynamicFactories();
00250   // Description:
00251   // Load all dynamic libraries in the given path
00252   static void LoadLibrariesInPath( const char*);
00254   
00255   // list of registered factories
00256   static vtkObjectFactoryCollection* RegisteredFactories; 
00257   
00258   // member variables for a factory set by the base class
00259   // at load or register time
00260   void* LibraryHandle;
00261   char* LibraryVTKVersion;
00262   char* LibraryCompilerUsed;
00263   char* LibraryPath;
00264 private:
00265   vtkObjectFactory(const vtkObjectFactory&);  // Not implemented.
00266   void operator=(const vtkObjectFactory&);  // Not implemented.
00267 };
00268 
00269 // Macro to create an object creation function.
00270 // The name of the function will by vtkObjectFactoryCreateclassname
00271 // where classname is the name of the class being created
00272 #define VTK_CREATE_CREATE_FUNCTION(classname) \
00273 static vtkObject* vtkObjectFactoryCreate##classname() \
00274 { return classname::New(); }
00275 
00276 #endif
00277 
00278 
00279 #ifdef _WIN32
00280 #define VTK_FACTORY_INTERFACE_EXPORT  __declspec( dllexport )
00281 #else
00282 #define VTK_FACTORY_INTERFACE_EXPORT 
00283 #endif
00284 
00285 // Macro to create the interface "C" functions used in
00286 // a dll or shared library that contains a VTK object factory.
00287 // Put this function in the .cxx file of your object factory,
00288 // and pass in the name of the factory sub-class that you want
00289 // the dll to create.
00290 #define VTK_FACTORY_INTERFACE_IMPLEMENT(factoryName)  \
00291 extern "C"                                      \
00292 VTK_FACTORY_INTERFACE_EXPORT                    \
00293 const char* vtkGetFactoryCompilerUsed()         \
00294 {                                               \
00295   return VTK_CXX_COMPILER;                      \
00296 }                                               \
00297 extern "C"                                      \
00298 VTK_FACTORY_INTERFACE_EXPORT                    \
00299 const char* vtkGetFactoryVersion()              \
00300 {                                               \
00301   return VTK_SOURCE_VERSION;                    \
00302 }                                               \
00303 extern "C"                                      \
00304 VTK_FACTORY_INTERFACE_EXPORT                    \
00305 vtkObjectFactory* vtkLoad()                     \
00306 {                                               \
00307   return factoryName ::New();                   \
00308 }

Generated on Thu Mar 28 14:19:16 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001