00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef FACTORYBASE_H
00016 #define FACTORYBASE_H
00017
00018 #include "pandabase.h"
00019
00020 #include "typedObject.h"
00021 #include "typedReferenceCount.h"
00022 #include "factoryParams.h"
00023
00024 #include "pvector.h"
00025 #include "pmap.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 class EXPCL_PANDA_PUTIL FactoryBase {
00043 public:
00044 typedef TypedObject *BaseCreateFunc(const FactoryParams ¶ms);
00045
00046
00047 public:
00048 FactoryBase();
00049 ~FactoryBase();
00050
00051 TypedObject *make_instance(TypeHandle handle,
00052 const FactoryParams ¶ms);
00053
00054 INLINE TypedObject *make_instance(const string &type_name,
00055 const FactoryParams ¶ms);
00056
00057 TypedObject *make_instance_more_general(TypeHandle handle,
00058 const FactoryParams ¶ms);
00059
00060 INLINE TypedObject *make_instance_more_general(const string &type_name,
00061 const FactoryParams ¶ms);
00062
00063 TypeHandle find_registered_type(TypeHandle handle);
00064
00065 void register_factory(TypeHandle handle, BaseCreateFunc *func);
00066
00067 int get_num_types() const;
00068 TypeHandle get_type(int n) const;
00069
00070 void clear_preferred();
00071 void add_preferred(TypeHandle handle);
00072 int get_num_preferred() const;
00073 TypeHandle get_preferred(int n) const;
00074
00075 void write_types(ostream &out, int indent_level = 0) const;
00076
00077 private:
00078
00079 FactoryBase(const FactoryBase ©);
00080 void operator = (const FactoryBase ©);
00081
00082
00083 TypedObject *make_instance_exact(TypeHandle handle,
00084 const FactoryParams ¶ms);
00085 TypedObject *make_instance_more_specific(TypeHandle handle,
00086 const FactoryParams ¶ms);
00087
00088 private:
00089
00090
00091 #if (defined(WIN32_VC) || defined(WIN64_VC)) && !defined(__ICL) //__ICL is Intel C++
00092
00093
00094 typedef pmap<TypeHandle, void *> Creators;
00095 #else
00096 typedef pmap<TypeHandle, BaseCreateFunc *> Creators;
00097 #endif
00098
00099 Creators _creators;
00100
00101 typedef pvector<TypeHandle> Preferred;
00102 Preferred _preferred;
00103 };
00104
00105 #include "factoryBase.I"
00106
00107 #endif