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 =========================================================================*/
00064 #ifndef __vtkObjectFactory_h
00065 #define __vtkObjectFactory_h
00066 
00067 
00068 
00069 
00070 #include "vtkObject.h"
00071 
00072 class vtkObjectFactoryCollection;
00073 
00074 class VTK_EXPORT vtkObjectFactory : public vtkObject
00075 {
00076 public:  
00077   // Methods from vtkObject
00078   vtkTypeMacro(vtkObjectFactory,vtkObject);
00080   virtual void PrintSelf(ostream& os, vtkIndent indent);
00081 
00082   // Class Methods used to interface with the registered factories
00083   
00088   static vtkObject* CreateInstance(const char* vtkclassname);
00091   static void ReHash(); 
00093   static void RegisterFactory(vtkObjectFactory* );
00095   static void UnRegisterFactory(vtkObjectFactory*);
00097   static void UnRegisterAllFactories();
00098   
00101   static vtkObjectFactoryCollection* GetRegisteredFactories();
00102 
00109   virtual const char* GetVTKSourceVersion() = 0;
00110 
00112   virtual const char* GetDescription() = 0;
00113 
00115   virtual int GetNumberOfOverrides();
00116 
00118   virtual const char* GetClassOverrideName(int index);
00119 
00122   virtual const char* GetClassOverrideWithName(int index);
00123   
00125   virtual int GetEnableFlag(int index);
00126 
00128   virtual const char* GetDescription(int index);
00129 
00131   virtual void SetEnableFlag(int flag,
00132               const char* className,
00133               const char* subclassName);
00134   virtual int GetEnableFlag(const char* className,
00135              const char* subclassName);
00136 
00139   virtual void Disable(const char* className);
00140   
00142   vtkGetStringMacro(LibraryPath);
00143 
00144   //BTX
00145   typedef vtkObject* (*CreateFunction)();
00146   //ETX
00147 protected:
00148   //BTX
00149 
00151   void RegisterOverride(const char* classOverride,
00152          const char* overrideClassName,
00153          const char* description,
00154          int enableFlag,
00155          CreateFunction createFunction);
00156       
00157   //ETX
00158 
00159    
00163   virtual vtkObject* CreateObject(const char* vtkclassname );
00164   
00165   vtkObjectFactory();
00166   ~vtkObjectFactory();
00167   vtkObjectFactory(const vtkObjectFactory&) {};
00168   void operator=(const vtkObjectFactory&) {};
00169   //BTX
00170   struct OverrideInformation
00171   {
00172     char* Description;
00173     char* OverrideWithName;
00174     int EnabledFlag;
00175     CreateFunction CreateCallback;
00176   };
00177   //ETX
00178   OverrideInformation* OverrideArray;
00179   char** OverrideClassNames;
00180   int SizeOverrideArray;
00181   int OverrideArrayLength;
00182 
00183 private:
00184   void GrowOverrideArray();
00185 
00188   static void Init();
00190   static void RegisterDefaults();
00192   static void LoadDynamicFactories();
00194   static void LoadLibrariesInPath( const char*);
00195   
00196   // list of registered factories
00197   static vtkObjectFactoryCollection* RegisteredFactories; 
00198   
00199   // member variables for a factory set by the base class
00200   // at load or register time
00201   void* LibraryHandle;
00202   unsigned long LibraryDate;
00203   char* LibraryPath;
00204 };
00205 
00206 // Macro to create an object creation function.
00207 // The name of the function will by vtkObjectFactoryCreateclassname
00208 // where classname is the name of the class being created
00209 #define VTK_CREATE_CREATE_FUNCTION(classname) \
00210 static vtkObject* vtkObjectFactoryCreate##classname() \
00211 { return classname::New(); }
00212 
00213 #endif

Generated on Wed Nov 21 12:26:53 2001 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001