43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
|
|
#include <map>
|
|
#include <string>
|
|
#include "LoadFile.h"
|
|
|
|
typedef struct {
|
|
const char * filename;
|
|
unsigned char * data;
|
|
int length;
|
|
} fileref_t;
|
|
|
|
/* 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
|
|
* is directly included instead of compiling it separately.
|
|
*/
|
|
#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)
|
|
{
|
|
if (LoadFileMap == NULL)
|
|
{
|
|
LoadFileMap = new std::map< std::string, fileref_t * >();
|
|
for (int i = 0; i < numFiles; i++)
|
|
{
|
|
(*LoadFileMap)[std::string(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;
|
|
}
|
|
|