reworked for new wfobj interface
git-svn-id: svn://anubis/dwscr/trunk@122 5bef9df8-b654-44bb-925b-0ff18baa8f8c
This commit is contained in:
1 parent
e2e552e338
commit
580597f389
6 files changed
+82
-52
No files matched your search
+26
-27
@@ -1,13 +1,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "LoadFile.h"
|
||||
|
||||
typedef struct {
|
||||
const char * filename;
|
||||
unsigned char * data;
|
||||
int length;
|
||||
} fileref_t;
|
||||
using namespace std;
|
||||
|
||||
/* The data section is generated by a perl script. The contents of the
|
||||
* included file are part of this logical program unit, which is why it
|
||||
@@ -15,28 +9,33 @@ typedef struct {
|
||||
*/
|
||||
#include "LoadFile-gen.inc"
|
||||
|
||||
const static int numFiles = sizeof(LoadFileData)/sizeof(fileref_t);
|
||||
|
||||
static std::map< std::string, fileref_t * > * LoadFileMap = NULL;
|
||||
|
||||
void * LoadFile(const char * filename, unsigned int * length)
|
||||
LoadFile::LoadFile()
|
||||
{
|
||||
if (LoadFileMap == NULL)
|
||||
for (unsigned int i = 0;
|
||||
i < sizeof(LoadFileData)/sizeof(LoadFileData[0]);
|
||||
i++)
|
||||
{
|
||||
LoadFileMap = new std::map< std::string, fileref_t * >();
|
||||
for (int i = 0; i < numFiles; i++)
|
||||
{
|
||||
(*LoadFileMap)[std::string(LoadFileData[i].filename)] = &LoadFileData[i];
|
||||
}
|
||||
m_filemap[LoadFileData[i].filename] = &LoadFileData[i];
|
||||
}
|
||||
|
||||
std::map< std::string, fileref_t * >::iterator it =
|
||||
LoadFileMap->find(std::string(filename));
|
||||
|
||||
if (it == LoadFileMap->end())
|
||||
return NULL;
|
||||
|
||||
*length = it->second->length;
|
||||
return it->second->data;
|
||||
}
|
||||
|
||||
FileLoader::Buffer LoadFile::load(const FileLoader::Path & path)
|
||||
{
|
||||
map<string, fileref_t *>::iterator it = m_filemap.find(path.shortPath);
|
||||
|
||||
if (it == m_filemap.end())
|
||||
return Buffer(0);
|
||||
|
||||
return Buffer((char *) it->second->data, it->second->length);
|
||||
}
|
||||
|
||||
int LoadFile::getSize(const FileLoader::Path & path)
|
||||
{
|
||||
map<string, fileref_t *>::iterator it = m_filemap.find(path.shortPath);
|
||||
|
||||
if (it == m_filemap.end())
|
||||
return 0;
|
||||
|
||||
return it->second->length;
|
||||
}
|
||||
|
||||
+24
-1
@@ -1,2 +1,25 @@
|
||||
|
||||
void * LoadFile(const char * filename, unsigned int * length);
|
||||
#ifndef LOADFILE_H
|
||||
#define LOADFILE_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "FileLoader/FileLoader.h"
|
||||
|
||||
typedef struct {
|
||||
const char * filename;
|
||||
unsigned char * data;
|
||||
int length;
|
||||
} fileref_t;
|
||||
|
||||
class LoadFile : public FileLoader
|
||||
{
|
||||
public:
|
||||
LoadFile();
|
||||
int getSize(const Path & path);
|
||||
Buffer load(const Path & path);
|
||||
protected:
|
||||
std::map< std::string, fileref_t * > m_filemap;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user