2016-02-13 09:02:47 +00:00
|
|
|
#ifndef __PSHAG_CFACTORYMGR_HPP__
|
|
|
|
#define __PSHAG_CFACTORYMGR_HPP__
|
2015-08-23 06:42:29 +00:00
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "RetroTypes.hpp"
|
2016-02-16 05:50:41 +00:00
|
|
|
#include "IOStreams.hpp"
|
2015-08-23 06:42:29 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-23 06:42:29 +00:00
|
|
|
{
|
2016-02-17 03:42:27 +00:00
|
|
|
struct SObjectTag;
|
2015-08-23 06:42:29 +00:00
|
|
|
class CVParamTransfer;
|
2016-02-16 05:50:41 +00:00
|
|
|
class IObj;
|
2015-08-23 06:42:29 +00:00
|
|
|
|
2016-02-16 05:50:41 +00:00
|
|
|
using CFactoryFnReturn = std::unique_ptr<IObj>;
|
2016-03-04 23:04:53 +00:00
|
|
|
using FFactoryFunc = std::function<CFactoryFnReturn(const urde::SObjectTag& tag,
|
|
|
|
urde::CInputStream& in,
|
|
|
|
const urde::CVParamTransfer& vparms)>;
|
2016-03-29 23:14:14 +00:00
|
|
|
using FMemFactoryFunc = std::function<CFactoryFnReturn(const urde::SObjectTag& tag,
|
|
|
|
std::unique_ptr<u8[]>&& in, u32 len,
|
|
|
|
const urde::CVParamTransfer& vparms)>;
|
2015-08-23 06:42:29 +00:00
|
|
|
class CFactoryMgr
|
|
|
|
{
|
2016-02-16 05:50:41 +00:00
|
|
|
std::unordered_map<FourCC, FFactoryFunc> m_factories;
|
2016-03-29 23:14:14 +00:00
|
|
|
std::unordered_map<FourCC, FMemFactoryFunc> m_memFactories;
|
2015-08-23 06:42:29 +00:00
|
|
|
public:
|
2016-03-04 23:04:53 +00:00
|
|
|
CFactoryFnReturn MakeObject(const SObjectTag& tag, urde::CInputStream& in,
|
2016-02-16 05:50:41 +00:00
|
|
|
const CVParamTransfer& paramXfer);
|
2016-03-29 23:14:14 +00:00
|
|
|
bool CanMakeMemory(const urde::SObjectTag& tag) const;
|
|
|
|
CFactoryFnReturn MakeObjectFromMemory(const SObjectTag& tag, std::unique_ptr<u8[]>&& buf, int size, bool compressed,
|
2016-02-16 05:50:41 +00:00
|
|
|
const CVParamTransfer& paramXfer);
|
|
|
|
void AddFactory(FourCC key, FFactoryFunc func)
|
2015-08-23 06:42:29 +00:00
|
|
|
{
|
|
|
|
m_factories[key] = func;
|
|
|
|
}
|
2016-03-29 23:14:14 +00:00
|
|
|
void AddFactory(FourCC key, FMemFactoryFunc func)
|
|
|
|
{
|
|
|
|
m_memFactories[key] = func;
|
|
|
|
}
|
2015-08-23 06:42:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
#endif // __PSHAG_CFACTORYMGR_HPP__
|