I'm trying to work with a resource maneger that's using the boost::filesystem thing but it keeps saying filesystem::extension(path)isn't correct.
resourcemgr.cpp
#include "resourcemgr.h"
#include <assert.h>
#include <boost/filesystem/operations.hpp>
#include<iostream>
#include "boost/filesystem/fstream.hpp"
using namespace std;
using namespace boost;
ResourceMgr::~ResourceMgr()
{
ResourceMap::iterator it = m_resources.begin();
while (it != m_resources.end())
{
IResource * pRes = (*it).second;
delete pRes;
++it;
}
}
void ResourceMgr::Register(ResourceMaker * pMaker)
{
assert (pMaker != NULL);
m_makers[string(pMaker->GetExtension())] = pMaker;
}
IResource * ResourceMgr::Create(const std::string & filename)
{
filesystem::path full_path (filename);
ResourceMap::iterator it = m_resources.find(full_path.string());
if (it != m_resources.end())
return (*it).second;
IResource * pRes = LoadResource(full_path.string());
if (pRes == NULL)
return NULL;
m_resources[full_path.string()] = pRes;
return pRes;
}
IResource * ResourceMgr::LoadResource(const std::string & filename)
{
filesystem::path path (filename);
string ext = filesystem::extension(path);
MakerMap::iterator it = m_makers.find(ext);
if (it == m_makers.end())
return NULL;
ResourceMaker * pMaker = (*it).second;
assert (pMaker != NULL);
FILE * fin = fopen(filename.c_str(), "rt");
if (fin == NULL)
return NULL;
IResource * pRes = pMaker->Create(fin);
fclose(fin);
return pRes;
}
std::ostream & operator<< (std::ostream & o, const IResource & res)
{
res.Dump(o);
return o;
}
resourcemgr.h
#ifndef RESOURCEMGR_H
#define RESOURCEMGR_H
#include <string>
#include <map>
class ResourceMgr;
class IResource {
public:
typedef std::string Type;
virtual const std::string & GetName() const = 0;
virtual Type GetType() const = 0;
virtual void Dump(std::ostream & o) const = 0;
protected:
virtual ~IResource() {};
friend class ResourceMgr; // The resource manager is the only place resources can be destroyed
};
std::ostream & operator<< (std::ostream & o, const IResource & res);
class ResourceMaker
{
public:
virtual IResource * Create (FILE * fin) = 0;
virtual const char * GetExtension () = 0;
};
class ResourceMgr {
public:
~ResourceMgr();
void Register (ResourceMaker * pMaker);
//void Unregister (const std::string & objectType);
IResource * Create(const std::string & filename);
private:
IResource * LoadResource(const std::string & filename);
typedef std::map<std::string, ResourceMaker *> MakerMap;
MakerMap m_makers;
typedef std::map<std::string, IResource *> ResourceMap;
ResourceMap m_resources;
};
#endif