00001 // Filename: factory.I 00002 // Created by: drose (08May00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 //////////////////////////////////////////////////////////////////// 00016 // Function: Factory::make_instance 00017 // Access: Public 00018 // Description: Attempts to create a new instance of some class of 00019 // the indicated type, or some derivative if necessary. 00020 // If an instance of the exact type cannot be created, 00021 // the specified preferred will specify which derived 00022 // class will be preferred. 00023 //////////////////////////////////////////////////////////////////// 00024 template<class Type> 00025 INLINE Type *Factory<Type>:: 00026 make_instance(TypeHandle handle, const FactoryParams ¶ms) { 00027 return (Type *)FactoryBase::make_instance(handle, params); 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: Factory::make_instance 00032 // Access: Public 00033 // Description: Attempts to create a new instance of some class of 00034 // the indicated type, or some derivative if necessary. 00035 // If an instance of the exact type cannot be created, 00036 // the specified preferred will specify which derived 00037 // class will be preferred. 00038 // 00039 // This flavor of make_instance() accepts a string name 00040 // that indicates the desired type. It must be the name 00041 // of some already-registered type. 00042 //////////////////////////////////////////////////////////////////// 00043 template<class Type> 00044 INLINE Type *Factory<Type>:: 00045 make_instance(const string &type_name, const FactoryParams ¶ms) { 00046 return (Type *)FactoryBase::make_instance(type_name, params); 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: Factory::make_instance_more_general 00051 // Access: Public 00052 // Description: Attempts to create an instance of the type requested, 00053 // or some base type of the type requested. Returns the 00054 // new instance created, or NULL if the instance could 00055 // not be created. 00056 //////////////////////////////////////////////////////////////////// 00057 template<class Type> 00058 INLINE Type *Factory<Type>:: 00059 make_instance_more_general(TypeHandle handle, const FactoryParams ¶ms) { 00060 return (Type *)FactoryBase::make_instance_more_general(handle, params); 00061 } 00062 00063 //////////////////////////////////////////////////////////////////// 00064 // Function: Factory::make_instance_more_general 00065 // Access: Public 00066 // Description: Attempts to create an instance of the type requested, 00067 // or some base type of the type requested. Returns the 00068 // new instance created, or NULL if the instance could 00069 // not be created. 00070 // 00071 // This flavor of make_instance_more_general() accepts a 00072 // string name that indicates the desired type. It must 00073 // be the name of some already-registered type. 00074 //////////////////////////////////////////////////////////////////// 00075 template<class Type> 00076 INLINE Type *Factory<Type>:: 00077 make_instance_more_general(const string &type_name, 00078 const FactoryParams ¶ms) { 00079 return (Type *)FactoryBase::make_instance_more_general(type_name, params); 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: Factory::register_factory 00084 // Access: Public 00085 // Description: Registers a new kind of thing the Factory will be 00086 // able to create. 00087 //////////////////////////////////////////////////////////////////// 00088 template<class Type> 00089 INLINE void Factory<Type>:: 00090 register_factory(TypeHandle handle, CreateFunc *func) { 00091 FactoryBase::register_factory(handle, (BaseCreateFunc *)func); 00092 }