Errors when compiling resource manager

Started by
2 comments, last by rick_appleton 19 years, 1 month ago
If I try to compile the following code in VS2002 I get some compiler errors (I've added comments to lines 69 and 126). manager.h

/*		Resource/resManager.h
 *
 *		Desc:
 *			CResourceManager is defined here, as well as helper classes IResourceLoader, 
 *			and IResourceData (helper classes in .cpp file).
 *		
 *			IResourceLoader saves pointers to the loading functions, and stores the filetype
 *			name the loader can load
 *
 *			IResourceData saves additional info about a resource that is only used by
 *			the resource manager. Users will never need to access this.
 *
 *			CResourceManager inherits from ISingleton, since there should never be more than
 *			one resourcemanager in the sytem.
 *
 *		Created
 *		On:				05 March 2004
 *		By:				R. Appleton
 */
#ifndef INC_RESOURCE_MANAGER_H
#define INC_RESOURCE_MANAGER_H

#include "Design_Patterns/singleton.h"
#include <map>
#include <vector>
#include <string>
#include "Buffers/buffer.h"
#include "Logging/log.h"

#define resManager CResourceManager::GetInstance()

class IResourceLoader
{
public:
	virtual ~IResourceLoader() {}
	virtual void* Load( BufferReader &reader ) const = 0;
};

class IBaseResourceWrapper
{
public:
  // So the derived versions are destructed correctly
  virtual ~IBaseResourceWrapper() {}

	unsigned short mNofReferences;
};

template< class ResourceType >
class IDerivedResourceWrapper : public IBaseResourceWrapper
{
public:
  ~IDerivedResourceWrapper() { delete mResource; }     
	IDerivedResourceWrapper( ResourceType *res ) : mResource(res) {}
  ResourceType *mResource;
};

typedef std::map<std::string, IBaseResourceWrapper*> ResourceMap;
typedef std::map<std::string, const IResourceLoader*>	LoaderMap;

class CResourceManager : public ISingleton<CResourceManager>
{
public:
	CResourceManager( void );
	~CResourceManager( void );

	template< class ResourceType >
	bool LoadResource( const char* name,
                     ResourceMap::iterator& iterOut )        // Error on this line
	{
    // See if the resource is already loaded
    ResourceMap::iterator iter = mResources.find(name);
    if (iter!=mResources.end())
    {
       Log(GENERAL) << name << " found, already loaded." << end;
       iter->second->mNofReferences++;
       iterOut = iter;
       return true;
    }
    
		// Create the extension to use when searching a loader
		const char *extension = strrchr(name, '.');
		if (extension)
			++extension;
		else
			extension = name;

		// Find the loader
		LoaderMap::const_iterator loaderIter = mLoaders.find(extension);
		if (loaderIter==mLoaders.end())
		{	// No loader found
			Error(GENERAL) << "Couldn't find a loader for " << name << end;
			return false;
		}
		else
		{	// Loader found
			const IResourceLoader *loader = loaderIter->second;

			// Loader creates a ResourceType
			BufferReader b;
      if ( !b.OpenFile(name) )
      {
         Error(GENERAL) << "Couldn't read file " << name << end;
         return false;
      }
      
      // Now how to get
      ResourceType* res = (ResourceType*)loader->Load(b);
      if (res)
      {
         Log(GENERAL) << name << " loaded succesfully." << end;
         
         // Add the resource to the map
         IDerivedResourceWrapper<ResourceType> *baseRes = new IDerivedResourceWrapper<ResourceType>(res);
         baseRes->mNofReferences = 1;
         iterOut = (mResources.insert( ResourceMap::value_type(name, baseRes) )).first;
         return true;
      }
      else
          return false;
    }
	}

	void RegisterLoader( const char* type, IResourceLoader* loader );

  template< class ResourceType >
  void GetResource( ResourceMap::iterator& iterIn, ResourceType*& out )       // Error on this line
  {
    // Just to check if the resource is still loaded correctly
   	ResourceMap::iterator iter = mResources.find(iterIn->first);
   	if (iter!=mResources.end())
   	{
      iterIn = iter;
      out = ((IDerivedResourceWrapper<ResourceType>*)iter->second)->mResource;
    }
    else
      out = 0;
  }



	std::string ListResources( void );
//  bool RegisterResource( const char* name, ResourceMap::iterator &out );

protected:
//  bool LoadResourceFromBufferFunc( const char* name, BufferReader *reader, ResourceMap::iterator& out );
  
public:  
//	ResourceMap::iterator GetEmptyResource( void ) { return resources.end(); }
//	bool LoadResourceFromFile( const char* filename, ResourceMap::iterator& out );
//	bool LoadResourceFromFile( const char* filename, ResourceMapNew::iterator& out );
//  bool LoadResourceFromBuffer( const char* name, const char* type, BufferReader *reader, ResourceMap::iterator& out );

  void UnLoadResource( ResourceMap::iterator it );

private:
	ResourceMap		mResources;
  LoaderMap			mLoaders;
};

#endif // INC_RESOURCE_MANAGER_H




manager.h(68): error C2039: 'iterator' : is not a member of 'std::map<_Kty,_Ty,_Pr,_Alloc>'
        with
        [
            _Kty=std::string,
            _Ty=IBaseResourceWrapper *,
            _Pr=std::less<std::string>,
            _Alloc=std::allocator<std::pair<const std::string,IBaseResourceWrapper *>>
        ]
manager.h(68): error C2955: 'std::iterator' : use of class template requires template argument list
        c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xutility(66) : see declaration of 'std::iterator'
manager.h(126): error C2039: 'iterator' : is not a member of 'std::map<_Kty,_Ty,_Pr,_Alloc>'
        with
        [
            _Kty=std::string,
            _Ty=IBaseResourceWrapper *,
            _Pr=std::less<std::string>,
            _Alloc=std::allocator<std::pair<const std::string,IBaseResourceWrapper *>>
        ]
manager.h(126): error C2955: 'std::iterator' : use of class template requires template argument list
The code compiles fine in Dev-C++, with the standard compiler (MingW I think). Does anyone have an idea how to fix this? I've already tried to add 'typename' on line 69, but that only made matters worse.
Advertisement
Try typename ResourceMap::iterator.
Quote:Original post by mishikel
Try typename ResourceMap::iterator.


I think it might be ResourceMap::typename iterator but I didn't try running through a compiler (reasoning: the system allready knows ResourceMap is a typename, being delcared as such as one of the template arguments. What the system dosn't know at this point is that the iterator is a typename, because it can't inspect the code until instantiated).
Quote:Original post by mishikel
Try typename ResourceMap::iterator.


Thanks for the try, but I'd already tried that (see original post) without succes.

Quote:
I think it might be ResourceMap::typename iterator but I didn't try running through a compiler (reasoning: the system allready knows ResourceMap is a typename, being delcared as such as one of the template arguments. What the system dosn't know at this point is that the iterator is a typename, because it can't inspect the code until instantiated).


I'm afraid the compiler doesn't like this either. It says typename is an illegal token on right side of ::

This topic is closed to new replies.

Advertisement