00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00036 class PG_API pgResMgr
00037 {
00038 public:
00039 pgDefineException(ExceptionCannotOpenFile);
00040 pgDefineException(ExceptionCannotReadFile);
00041 pgDefineException(ExceptionInvalidArgument);
00042 pgDefineException(ExceptionNotFound);
00043 pgDefineException(ExceptionNotInitialized);
00044 pgDefineException(ExceptionSameExtensionExists);
00045 pgDefineException(ExceptionSameIDExists);
00046
00047 typedef void (*Initializer)(pgID id, pgStr<char, 3> ext, const void* data, u32 data_size, void** exinfo);
00048 typedef void (*Finalizer)(pgID id, pgStr<char, 3> ext, const void* data, u32 data_size, void* exinfo);
00049
00050 static bool isCreated();
00051 static void createAfterTask();
00052 static void destroyBeforeSys();
00053
00054 static u16 getTypeNum();
00055 static u16 getResourceNum();
00056
00057 static void addType(pgStr<char, 3> ext, Initializer init, Finalizer final);
00058 static void removeType(pgStr<char, 3> ext);
00059
00060 static bool hasResource(pgID id);
00061 static pgRes getResource(pgID id);
00062 static void addResource(pgID id, pgStr<char, 3> ext, const void* data, u32 data_size, bool is_auto_free);
00063 static void removeResource(pgID id);
00064
00065 static void loadResource(const char* filename, bool is_type_detect);
00066 static void loadResourceAs(pgID id, const char* filename, bool is_type_detect);
00067
00068 static const pgStr<char, 3>* getFirstTypeN();
00069 static const pgStr<char, 3>* getNextTypeN(pgStr<char, 3> ext);
00070
00071 static const pgRes* getFirstResourceN();
00072 static const pgRes* getNextResourceN(pgID id);
00073
00074 private:
00075 static const u32 TYPE_HASH_SIZE = 1;
00076 static const u32 RESOURCE_HASH_SIZE = 10;
00077
00078 struct TypeInfo
00079 {
00080 pgStr<char, 3> ext;
00081 Initializer init;
00082 Finalizer final;
00083 };
00084
00085 pgResMgr();
00086 ~pgResMgr();
00087 void operator=(const pgResMgr&);
00088
00089 static pgResMgr* instance();
00090
00091 pgMap<pgStr<char, 3>, TypeInfo> m_type_info_map;
00092 pgMap<pgID, pgRes> m_res_map;
00093
00094 static pgResMgr* m_instance;
00095 };