1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkInstantiator.h,v $
6 Date: $Date: 2002/12/26 18:24:21 $
7 Version: $Revision: 1.5 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkInstantiator - create an instance of any VTK class from its name.
19 // .SECTION Description
20 // vtkInstantiator provides an interface to create an instance of any
21 // VTK class from its name. Instances are created through registered
22 // pointers to functions returning the objects. New classes can also be
23 // registered with the creator. VTK libraries automatically register
24 // their classes with the creator when they are loaded. Instances are
25 // created using the static New() method, so the normal vtkObjectFactory
26 // mechanism is still invoked.
28 // When using this class from language wrappers (Tcl, Python, or Java),
29 // the vtkInstantiator should be able to create any class from any kit
30 // that has been loaded.
32 // In C++ code, one should include the header for each kit from which
33 // one wishes to create instances through vtkInstantiator. This is
34 // necessary to ensure proper linking when building static libraries.
35 // Be careful, though, because including each kit's header means every
36 // class from that kit will be linked into your executable whether or
37 // not the class is used. The headers are:
39 // vtkCommon - vtkCommonInstantiator.h
40 // vtkFiltering - vtkFilteringInstantiator.h
41 // vtkIO - vtkIOInstantiator.h
42 // vtkImaging - vtkImagingInstantiator.h
43 // vtkGraphics - vtkGraphicsInstantiator.h
44 // vtkRendering - vtkRenderingInstantiator.h
45 // vtkHybrid - vtkHybridInstantiator.h
46 // vtkParallel - vtkParallelInstantiator.h
47 // vtkPatented - vtkPatentedInstantiator.h
49 // The VTK_MAKE_INSTANTIATOR() command in CMake is used to automatically
50 // generate the creator registration for each VTK library. It can also
51 // be used to create registration code for VTK-style user libraries
52 // that are linked to vtkCommon. After using this command to register
53 // classes from a new library, the generated header must be included.
56 #ifndef __vtkInstantiator_h
57 #define __vtkInstantiator_h
59 #include "vtkObject.h"
61 // The vtkDebugLeaks singleton must be initialized before and
62 // destroyed after the vtkInstantiator singleton.
63 #include "vtkDebugLeaksManager.h" // Needed for proper singleton initialization
65 class vtkInstantiatorInitialize;
66 class vtkInstantiatorHashTable;
68 class VTK_COMMON_EXPORT vtkInstantiator : public vtkObject
71 static vtkInstantiator* New();
72 vtkTypeRevisionMacro(vtkInstantiator,vtkObject);
73 void PrintSelf(ostream& os, vtkIndent indent);
76 // Create an instance of the class whose name is given. If creation
77 // fails, a NULL pointer is returned.
78 static vtkObject* CreateInstance(const char* className);
81 typedef vtkObject* (*CreateFunction)();
84 // Register a function to create instances of the class whose name
85 // is given. This allows more than one create function to be
86 // registered for the same class. The first one registered is used
87 // until it is unregistered.
88 static void RegisterInstantiator(const char* className,
89 CreateFunction createFunction);
92 // Unregister the instance creation of the class whose name is
93 // given. This will unregister the function given, but any other
94 // function registered for the same class will be left untouched.
95 static void UnRegisterInstantiator(const char* className,
96 CreateFunction createFunction);
103 // Internal storage for registered creation functions.
104 static vtkInstantiatorHashTable* CreatorTable;
106 static void ClassInitialize();
107 static void ClassFinalize();
110 friend class vtkInstantiatorInitialize;
114 vtkInstantiator(const vtkInstantiator&); // Not implemented.
115 void operator=(const vtkInstantiator&); // Not implemented.
119 // Utility class to make sure vtkInstantiator is initialized before it
121 class VTK_COMMON_EXPORT vtkInstantiatorInitialize
124 vtkInstantiatorInitialize();
125 ~vtkInstantiatorInitialize();
127 static unsigned int Count;
130 // This instance will show up in any translation unit that uses
131 // vtkInstantiator. It will make sure vtkInstantiator is initialized
132 // before it is used.
133 static vtkInstantiatorInitialize vtkInstantiatorInitializer;