Boost::Filesystem

Started by
1 comment, last by Enigma 17 years, 6 months ago
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 &lt;string&gt;
#include &lt;map&gt;

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&lt;&lt; (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&lt;std::string, ResourceMaker *&gt; MakerMap;
    MakerMap m_makers;
    
    typedef std::map&lt;std::string, IResource *&gt; ResourceMap;
    ResourceMap m_resources;
};

#endif

Sylvarant @www.gamedesign.be
Advertisement
When you say 'it keeps saying', do you mean that an exception is being thrown? Or what?

The answer to this question may be in your posted code somewhere, but it'd be easier if you could direct us to the problem and/or provide more information about it.
extension lives in the header convenience.hpp, which you haven't included.

Σnigma

This topic is closed to new replies.

Advertisement