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