OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / vtk / vtkObjectFactory.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkObjectFactory.h,v $
5   Language:  C++
6   Date:      $Date: 2002/01/22 15:25:48 $
7   Version:   $Revision: 1.23 $
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 vtkObjectFactory - abstract base class for vtkObjectFactories
19 // .SECTION Description
20 // vtkObjectFactory is used to create vtk objects.   The base class
21 // vtkObjectFactory contains a static method CreateInstance which is used
22 // to create vtk objects from the list of registered vtkObjectFactory 
23 // sub-classes.   The first time CreateInstance is called, all dll's or shared
24 // libraries in the environment variable VTK_AUTOLOAD_PATH are loaded into
25 // the current process.   The C functions vtkLoad, vtkGetFactoryCompilerUsed, 
26 // and vtkGetFactoryVersion are called on each dll.  To implement these
27 // functions in a shared library or dll, use the macro:
28 // VTK_FACTORY_INTERFACE_IMPLEMENT.
29 // VTK_AUTOLOAD_PATH is an environment variable 
30 // containing a colon separated (semi-colon on win32) list of paths.
31 //
32 // The vtkObjectFactory can be use to override the creation of any object
33 // in VTK with a sub-class of that object.  The factories can be registered
34 // either at run time with the VTK_AUTOLOAD_PATH, or at compile time
35 // with the vtkObjectFactory::RegisterFactory method.
36 //
37
38
39
40 #ifndef __vtkObjectFactory_h
41 #define __vtkObjectFactory_h
42
43
44
45
46 #include "vtkObject.h"
47
48 class vtkObjectFactoryCollection;
49 class vtkOverrideInformationCollection;
50 class vtkCollection;
51
52 class VTK_COMMON_EXPORT vtkObjectFactory : public vtkObject
53 {
54 public:  
55   // Class Methods used to interface with the registered factories
56   
57   // Description:
58   // Create and return an instance of the named vtk object.
59   // Each loaded vtkObjectFactory will be asked in the order
60   // the factory was in the VTK_AUTOLOAD_PATH.  After the
61   // first factory returns the object no other factories are asked.
62   static vtkObject* CreateInstance(const char* vtkclassname);
63
64   // Description:
65   // Create all possible instances of the named vtk object.
66   // Each registered vtkObjectFactory will be asked, and the
67   // result will be stored in the user allocated vtkCollection
68   // passed in to the function.
69   static void CreateAllInstance(const char* vtkclassname,
70                                 vtkCollection* retList);
71   // Description:
72   // Re-check the VTK_AUTOLOAD_PATH for new factory libraries.
73   // This calls UnRegisterAll before re-loading
74   static void ReHash(); 
75   // Description:
76   // Register a factory so it can be used to create vtk objects
77   static void RegisterFactory(vtkObjectFactory* );
78   // Description:
79   // Remove a factory from the list of registered factories
80   static void UnRegisterFactory(vtkObjectFactory*);
81   // Description:
82   // Unregister all factories
83   static void UnRegisterAllFactories();
84   
85   // Description:
86   // Return the list of all registered factories.  This is NOT a copy,
87   // do not remove items from this list!
88   static vtkObjectFactoryCollection* GetRegisteredFactories();
89
90   // Description: 
91   // return 1 if one of the registered factories 
92   // overrides the given class name
93   static int HasOverrideAny(const char* className);
94   
95   // Description:
96   // Fill the given collection with all the overrides for
97   // the class with the given name.
98   static void GetOverrideInformation(const char* name,
99                                      vtkOverrideInformationCollection*);
100   
101   // Description:
102   // Set the enable flag for a given named class for all registered
103   // factories.
104   static void SetAllEnableFlags(int flag, 
105                                 const char* className);
106   // Description:
107   // Set the enable flag for a given named class subclass pair
108   // for all registered factories.
109   static void SetAllEnableFlags(int flag, 
110                                 const char* className,
111                                 const char* subclassName);
112
113   // Instance methods to be used on individual instances of vtkObjectFactory
114   
115   // Methods from vtkObject
116   vtkTypeRevisionMacro(vtkObjectFactory,vtkObject);
117   // Description:
118   // Print ObjectFactory to stream.
119   virtual void PrintSelf(ostream& os, vtkIndent indent);
120
121   // Description:
122   // All sub-classes of vtkObjectFactory should must return the version of 
123   // VTK they were built with.  This should be implemented with the macro
124   // VTK_SOURCE_VERSION and NOT a call to vtkVersion::GetVTKSourceVersion.
125   // As the version needs to be compiled into the file as a string constant.
126   // This is critical to determine possible incompatible dynamic factory loads.
127   virtual const char* GetVTKSourceVersion() = 0;
128
129   // Description:
130   // Return a descriptive string describing the factory.
131   virtual const char* GetDescription() = 0;
132
133   // Description:
134   // Return number of overrides this factory can create.
135   virtual int GetNumberOfOverrides();
136
137   // Description:
138   // Return the name of a class override at the given index.
139   virtual const char* GetClassOverrideName(int index);
140
141   // Description:
142   // Return the name of the class that will override the class
143   // at the given index
144   virtual const char* GetClassOverrideWithName(int index);
145   
146   // Description:
147   // Return the enable flag for the class at the given index.
148   virtual int GetEnableFlag(int index);
149
150   // Description:
151   // Return the description for a the class override at the given 
152   // index.
153   virtual const char* GetOverrideDescription(int index);
154
155   // Description:
156   // Set and Get the Enable flag for the specific override of className.
157   // if subclassName is null, then it is ignored.
158   virtual void SetEnableFlag(int flag,
159                              const char* className,
160                              const char* subclassName);
161   virtual int GetEnableFlag(const char* className,
162                             const char* subclassName);
163
164   // Description:
165   // Return 1 if this factory overrides the given class name, 0 otherwise.
166   virtual int HasOverride(const char* className);
167   // Description:
168   // Return 1 if this factory overrides the given class name, 0 otherwise.
169   virtual int HasOverride(const char* className, const char* subclassName);
170   
171   // Description:
172   // Set all enable flags for the given class to 0.  This will
173   // mean that the factory will stop producing class with the given
174   // name.
175   virtual void Disable(const char* className);
176   
177   // Description:
178   // This returns the path to a dynamically loaded factory.
179   vtkGetStringMacro(LibraryPath);
180
181   //BTX
182   typedef vtkObject* (*CreateFunction)();
183   //ETX
184 protected:
185   //BTX
186
187   // Description:
188   // Register object creation information with the factory.
189   void RegisterOverride(const char* classOverride,
190                         const char* overrideClassName,
191                         const char* description,
192                         int enableFlag,
193                         CreateFunction createFunction);
194                 
195   //ETX
196
197         
198   // Description:
199   // This method is provided by sub-classes of vtkObjectFactory.
200   // It should create the named vtk object or return 0 if that object
201   // is not supported by the factory implementation.
202   virtual vtkObject* CreateObject(const char* vtkclassname );
203   
204   vtkObjectFactory();
205   ~vtkObjectFactory();
206   //BTX
207   struct OverrideInformation
208   {
209     char* Description;
210     char* OverrideWithName;
211     int EnabledFlag;
212     CreateFunction CreateCallback;
213   };
214   //ETX
215   OverrideInformation* OverrideArray;
216   char** OverrideClassNames;
217   int SizeOverrideArray;
218   int OverrideArrayLength;
219
220 private:
221   void GrowOverrideArray();
222
223   // Description:
224   // Initialize the static members of vtkObjectFactory.   RegisterDefaults
225   // is called here.
226   static void Init();
227   // Description:
228   // Register default factories which are not loaded at run time.
229   static void RegisterDefaults();
230   // Description:
231   // Load dynamic factories from the VTK_AUTOLOAD_PATH
232   static void LoadDynamicFactories();
233   // Description:
234   // Load all dynamic libraries in the given path
235   static void LoadLibrariesInPath( const char*);
236   
237   // list of registered factories
238   static vtkObjectFactoryCollection* RegisteredFactories; 
239   
240   // member variables for a factory set by the base class
241   // at load or register time
242   void* LibraryHandle;
243   char* LibraryVTKVersion;
244   char* LibraryCompilerUsed;
245   char* LibraryPath;
246 private:
247   vtkObjectFactory(const vtkObjectFactory&);  // Not implemented.
248   void operator=(const vtkObjectFactory&);  // Not implemented.
249 };
250
251 // Macro to create an object creation function.
252 // The name of the function will by vtkObjectFactoryCreateclassname
253 // where classname is the name of the class being created
254 #define VTK_CREATE_CREATE_FUNCTION(classname) \
255 static vtkObject* vtkObjectFactoryCreate##classname() \
256 { return classname::New(); }
257
258 #endif
259
260
261 #ifdef _WIN32
262 #define VTK_FACTORY_INTERFACE_EXPORT  __declspec( dllexport )
263 #else
264 #define VTK_FACTORY_INTERFACE_EXPORT 
265 #endif
266
267 // Macro to create the interface "C" functions used in
268 // a dll or shared library that contains a VTK object factory.
269 // Put this function in the .cxx file of your object factory,
270 // and pass in the name of the factory sub-class that you want
271 // the dll to create.
272 #define VTK_FACTORY_INTERFACE_IMPLEMENT(factoryName)  \
273 extern "C"                                      \
274 VTK_FACTORY_INTERFACE_EXPORT                    \
275 const char* vtkGetFactoryCompilerUsed()         \
276 {                                               \
277   return VTK_CXX_COMPILER;                      \
278 }                                               \
279 extern "C"                                      \
280 VTK_FACTORY_INTERFACE_EXPORT                    \
281 const char* vtkGetFactoryVersion()              \
282 {                                               \
283   return VTK_SOURCE_VERSION;                    \
284 }                                               \
285 extern "C"                                      \
286 VTK_FACTORY_INTERFACE_EXPORT                    \
287 vtkObjectFactory* vtkLoad()                     \
288 {                                               \
289   return factoryName ::New();                   \
290 }