VTK
dox/Common/vtkInstantiator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkInstantiator.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 =========================================================================*/
00061 #ifndef __vtkInstantiator_h
00062 #define __vtkInstantiator_h
00063 
00064 #include "vtkObject.h"
00065 
00066 // The vtkDebugLeaks singleton must be initialized before and
00067 // destroyed after the vtkInstantiator singleton.
00068 #include "vtkDebugLeaksManager.h" // Needed for proper singleton initialization
00069 
00070 class vtkInstantiatorInitialize;
00071 class vtkInstantiatorHashTable;
00072 
00073 class VTK_COMMON_EXPORT vtkInstantiator : public vtkObject
00074 {
00075 public:
00076   static vtkInstantiator* New();
00077   vtkTypeMacro(vtkInstantiator,vtkObject);
00078   void PrintSelf(ostream& os, vtkIndent indent);
00079   
00082   static vtkObject* CreateInstance(const char* className);
00083   
00084   //BTX
00085   typedef vtkObject* (*CreateFunction)();
00086 
00088 
00092   static void RegisterInstantiator(const char* className,
00093                                    CreateFunction createFunction);
00095 
00097 
00100   static void UnRegisterInstantiator(const char* className,
00101                                      CreateFunction createFunction);
00102   //ETX
00104   
00105 protected:
00106   vtkInstantiator();
00107   ~vtkInstantiator();
00108   
00109   // Internal storage for registered creation functions.
00110   static vtkInstantiatorHashTable* CreatorTable;
00111   
00112   static void ClassInitialize();
00113   static void ClassFinalize();
00114   
00115   //BTX
00116   friend class vtkInstantiatorInitialize;
00117   //ETX
00118   
00119 private:
00120   vtkInstantiator(const vtkInstantiator&);  // Not implemented.
00121   void operator=(const vtkInstantiator&);  // Not implemented.
00122 };
00123 
00124 //BTX
00125 // Utility class to make sure vtkInstantiator is initialized before it
00126 // is used.
00127 class VTK_COMMON_EXPORT vtkInstantiatorInitialize
00128 {
00129 public:
00130   vtkInstantiatorInitialize();
00131   ~vtkInstantiatorInitialize();
00132 private:
00133   static unsigned int Count;
00134 };
00135 
00136 // This instance will show up in any translation unit that uses
00137 // vtkInstantiator.  It will make sure vtkInstantiator is initialized
00138 // before it is used.
00139 static vtkInstantiatorInitialize vtkInstantiatorInitializer;
00140 //ETX
00141 
00142 #endif