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