00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc. 00008 * 477 Richmond Street West, Suite 1001 00009 * Toronto, Ontario 00010 * Canada M5V 3E7 00011 * 416-504-9876 00012 */ 00013 00014 #ifndef __SIM_DataFactory_h__ 00015 #define __SIM_DataFactory_h__ 00016 00017 #include "SIM_API.h" 00018 #include <UT/UT_String.h> 00019 00020 class UT_Guid; 00021 class SIM_Data; 00022 class SIM_DataFactory; 00023 class SIM_DopDescription; 00024 class SIM_Engine; 00025 class SIM_DataFactoryCreator; 00026 00027 typedef SIM_Data *(*SIM_DataConstructor)(const SIM_DataFactory *); 00028 typedef void (*SIM_DataDestructor)(SIM_Data *); 00029 00030 /// This class provides a means of creating and destroying SIM_Data objects. 00031 /// Nothing needs to be known about the SIM_Data object except its data 00032 /// type name. It is possible to derive a subclass to use instead of 00033 /// relying on the default implementations used by the DECLARE_DATAFACTORY 00034 /// and IMPLEMENT_DATAFACTORY macros. But generally these macros will be 00035 /// sufficient. 00036 class SIM_API SIM_DataFactory 00037 { 00038 public: 00039 /// Constructor which receives all the data for this factory. 00040 /// The constructor arguments contain all the information that may be 00041 /// required for the new data type without actually requiring an 00042 /// instance of that data type to be constructed. 00043 SIM_DataFactory(const char *datatype, 00044 const char *description, 00045 SIM_DataConstructor constructor, 00046 SIM_DataDestructor destructor, 00047 const SIM_DopDescription *dopdesc, 00048 const SIM_Engine *engine); 00049 /// Destructor. 00050 virtual ~SIM_DataFactory(); 00051 00052 /// Return the SIM_Engine that owns this factory. 00053 const SIM_Engine &getEngine() const; 00054 /// Get the name of the data type that is created by this factory. 00055 /// This is the unique identifier that is passed to a SIM_Object to 00056 /// create a new instance of this data type. 00057 const UT_String &getDataType() const; 00058 /// Gets a string that describes what this data type does. 00059 /// This descriptive string is what is presented to the user when 00060 /// given a menu of data type choices. 00061 const UT_String &getDescription() const; 00062 /// Returns the name of the DSO or DLL file that defines the data type. 00063 /// For data types defined internally to Houdini the returned string 00064 /// will be empty. 00065 const UT_String &getSource() const; 00066 00067 /// Create a new instance of our particular subclass of SIM_Data. 00068 virtual SIM_Data *newData() const; 00069 /// Calls newData() to create some new data, then changes the unique id. 00070 SIM_Data *newData(const UT_Guid &uniqueid) const; 00071 /// Delete an instance of our particular subclass of SIM_Data. 00072 virtual void deleteData(SIM_Data *data) const; 00073 /// Return our SIM_DopDescription. 00074 virtual const SIM_DopDescription *getDopDescription() const; 00075 00076 private: 00077 /// All our data is set up in the constructor and cannot be modified. 00078 const UT_String myDataType; 00079 const UT_String myDescription; 00080 const SIM_DataConstructor myConstructor; 00081 const SIM_DataDestructor myDestructor; 00082 const SIM_DopDescription *myDopDescription; 00083 const SIM_Engine *myEngine; 00084 const SIM_DataFactoryCreator *myCreator; 00085 00086 friend class SIM_DataFactoryCreator; 00087 }; 00088 00089 /// This helper class lets each SIM_Engine create an instance of 00090 /// each SIM_DataFactory available on the system. 00091 class SIM_API SIM_DataFactoryCreator 00092 { 00093 public: 00094 /// Defines a function for creating a SIM_DataFactory. 00095 typedef void (*SIM_DataFactoryCreateFunc)(SIM_Engine *engine); 00096 00097 /// Constructor sets the SIM_DataFactory creation function. 00098 /// It also registers this SIM_DataFactoryCreator instance with the 00099 /// global list in the SIM_Engine class. 00100 SIM_DataFactoryCreator(SIM_DataFactoryCreateFunc createfunc); 00101 /// Destructor which removes this SIM_DataFactoryCreator from the 00102 /// global list owned by the SIM_Engine class. 00103 ~SIM_DataFactoryCreator(); 00104 00105 /// Returns the name of the DSO or DLL file that defines the data type. 00106 /// For data types defined internally to Houdini the returned string 00107 /// will be empty. 00108 const UT_String &getSource() const; 00109 /// Call the creation function to make a new SIM_DataFactory instance. 00110 void createDataFactory(SIM_Engine *engine); 00111 /// Call addDataFactory on the specified SIM_Engine. 00112 static void addDataFactory(SIM_Engine *engine, 00113 SIM_DataFactory *factory); 00114 00115 private: 00116 SIM_DataFactoryCreateFunc myCreateFunc; 00117 const UT_String mySource; 00118 00119 static const SIM_DataFactoryCreator *theCreatingFactory; 00120 }; 00121 00122 #endif 00123
1.5.9