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