Jump to content
  • Advertisement
Sign in to follow this  
Sylvarant

Boost::Filesystem

This topic is 4237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!