Panda3D
 All Classes Functions Variables Enumerations
factory.h
00001 // Filename: factory.h
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 #ifndef FACTORY_H
00016 #define FACTORY_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "factoryBase.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //       Class : Factory
00024 // Description : A Factory can be used to create an instance of a
00025 //               particular subclass of some general base class.  Each
00026 //               subclass registers itself with the Factory, supplying
00027 //               a function that will construct an instance of that
00028 //               subclass; the Factory can later choose a suitable
00029 //               subclass and return a newly-constructed pointer to an
00030 //               object of that type on the user's demand.  This is
00031 //               used, for instance, to manage the set of
00032 //               GraphicsPipes available to the user.
00033 //
00034 //               This is a thin template wrapper around FactoryBase.
00035 //               All it does is ensure the types are correctly cast.
00036 //               All of its methods are inline, and it has no data
00037 //               members, so it is not necessary to export the class
00038 //               from the DLL.
00039 ////////////////////////////////////////////////////////////////////
00040 template<class Type>
00041 class Factory : public FactoryBase {
00042 public:
00043   typedef Type *CreateFunc(const FactoryParams &params);
00044 
00045   INLINE Type *make_instance(TypeHandle handle,
00046                              const FactoryParams &params = FactoryParams());
00047 
00048   INLINE Type *make_instance(const string &type_name,
00049                              const FactoryParams &params = FactoryParams());
00050 
00051   INLINE Type *
00052   make_instance_more_general(TypeHandle handle,
00053                              const FactoryParams &params = FactoryParams());
00054 
00055   INLINE Type *
00056   make_instance_more_general(const string &type_name,
00057                              const FactoryParams &params = FactoryParams());
00058 
00059   INLINE void register_factory(TypeHandle handle, CreateFunc *func);
00060 };
00061 
00062 #include "factory.I"
00063 
00064 #endif
00065 
 All Classes Functions Variables Enumerations