00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef LOADER_H
00016 #define LOADER_H
00017
00018 #include "pandabase.h"
00019
00020 #include "namable.h"
00021 #include "loaderOptions.h"
00022 #include "pnotify.h"
00023 #include "pandaNode.h"
00024 #include "filename.h"
00025 #include "dSearchPath.h"
00026 #include "pvector.h"
00027 #include "asyncTaskManager.h"
00028 #include "asyncTask.h"
00029
00030 class LoaderFileType;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class EXPCL_PANDA_PGRAPH Loader : public TypedReferenceCount, public Namable {
00048 private:
00049 class ConsiderFile {
00050 public:
00051 Filename _path;
00052 LoaderFileType *_type;
00053 };
00054
00055 PUBLISHED:
00056 class EXPCL_PANDA_PGRAPH Results {
00057 PUBLISHED:
00058 INLINE Results();
00059 INLINE Results(const Results ©);
00060 INLINE void operator = (const Results ©);
00061 INLINE ~Results();
00062
00063 INLINE void clear();
00064 INLINE int get_num_files() const;
00065 INLINE const Filename &get_file(int n) const;
00066 MAKE_SEQ(get_files, get_num_files, get_file);
00067 INLINE LoaderFileType *get_file_type(int n) const;
00068 MAKE_SEQ(get_file_types, get_num_files, get_file_type);
00069
00070 public:
00071 INLINE void add_file(const Filename &file, LoaderFileType *type);
00072
00073 private:
00074 typedef pvector<ConsiderFile> Files;
00075 Files _files;
00076 };
00077
00078 Loader(const string &name = "loader");
00079
00080 INLINE void set_task_manager(AsyncTaskManager *task_manager);
00081 INLINE AsyncTaskManager *get_task_manager() const;
00082 INLINE void set_task_chain(const string &task_chain);
00083 INLINE const string &get_task_chain() const;
00084
00085 BLOCKING INLINE void stop_threads();
00086 INLINE bool remove(AsyncTask *task);
00087
00088 BLOCKING INLINE PT(PandaNode) load_sync(const Filename &filename,
00089 const LoaderOptions &options = LoaderOptions()) const;
00090
00091 PT(AsyncTask) make_async_request(const Filename &filename,
00092 const LoaderOptions &options = LoaderOptions());
00093 INLINE void load_async(AsyncTask *request);
00094
00095 BLOCKING PT(PandaNode) load_bam_stream(istream &in);
00096
00097 virtual void output(ostream &out) const;
00098
00099 INLINE static Loader *get_global_ptr();
00100
00101 private:
00102 PT(PandaNode) load_file(const Filename &filename, const LoaderOptions &options) const;
00103 PT(PandaNode) try_load_file(const Filename &pathname, const LoaderOptions &options,
00104 LoaderFileType *requested_type) const;
00105
00106 static void make_global_ptr();
00107
00108 PT(AsyncTaskManager) _task_manager;
00109 string _task_chain;
00110
00111 static void load_file_types();
00112 static bool _file_types_loaded;
00113
00114 static PT(Loader) _global_ptr;
00115
00116 public:
00117 static TypeHandle get_class_type() {
00118 return _type_handle;
00119 }
00120 static void init_type() {
00121 TypedReferenceCount::init_type();
00122 Namable::init_type();
00123 register_type(_type_handle, "Loader",
00124 TypedReferenceCount::get_class_type(),
00125 Namable::get_class_type());
00126 }
00127 virtual TypeHandle get_type() const {
00128 return get_class_type();
00129 }
00130 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00131
00132 private:
00133 static TypeHandle _type_handle;
00134
00135 friend class ModelLoadRequest;
00136 };
00137
00138 #include "loader.I"
00139
00140 #endif