OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / vtk / vtkInstantiator.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkInstantiator.h,v $
5   Language:  C++
6   Date:      $Date: 2002/12/26 18:24:21 $
7   Version:   $Revision: 1.5 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
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.
16
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.
27 //
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.
31 //
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:
38 //
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
48 //
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.
54 //
55
56 #ifndef __vtkInstantiator_h
57 #define __vtkInstantiator_h
58
59 #include "vtkObject.h"
60
61 // The vtkDebugLeaks singleton must be initialized before and
62 // destroyed after the vtkInstantiator singleton.
63 #include "vtkDebugLeaksManager.h" // Needed for proper singleton initialization
64
65 class vtkInstantiatorInitialize;
66 class vtkInstantiatorHashTable;
67
68 class VTK_COMMON_EXPORT vtkInstantiator : public vtkObject
69 {
70 public:
71   static vtkInstantiator* New();
72   vtkTypeRevisionMacro(vtkInstantiator,vtkObject);
73   void PrintSelf(ostream& os, vtkIndent indent);
74   
75   // Description:
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);
79   
80   //BTX
81   typedef vtkObject* (*CreateFunction)();
82
83   // Description:
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);
90
91   // Description:
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);
97   //ETX
98   
99 protected:
100   vtkInstantiator();
101   ~vtkInstantiator();
102   
103   // Internal storage for registered creation functions.
104   static vtkInstantiatorHashTable* CreatorTable;
105   
106   static void ClassInitialize();
107   static void ClassFinalize();
108   
109   //BTX
110   friend class vtkInstantiatorInitialize;
111   //ETX
112   
113 private:
114   vtkInstantiator(const vtkInstantiator&);  // Not implemented.
115   void operator=(const vtkInstantiator&);  // Not implemented.
116 };
117
118 //BTX
119 // Utility class to make sure vtkInstantiator is initialized before it
120 // is used.
121 class VTK_COMMON_EXPORT vtkInstantiatorInitialize
122 {
123 public:
124   vtkInstantiatorInitialize();
125   ~vtkInstantiatorInitialize();
126 private:
127   static unsigned int Count;
128 };
129
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;
134 //ETX
135
136 #endif