|
@@ -6,6 +6,7 @@
|
|
#include <fstream>
|
|
#include <fstream>
|
|
#include <set>
|
|
#include <set>
|
|
#include <map>
|
|
#include <map>
|
|
|
|
+#include <boost/unordered_set.hpp>
|
|
|
|
|
|
/*
|
|
/*
|
|
* CLodhandler.h, part of VCMI engine
|
|
* CLodhandler.h, part of VCMI engine
|
|
@@ -52,6 +53,7 @@ enum LodFileType{
|
|
FILE_OTHER
|
|
FILE_OTHER
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+
|
|
struct Entry
|
|
struct Entry
|
|
{
|
|
{
|
|
// Info extracted from LOD file
|
|
// Info extracted from LOD file
|
|
@@ -62,12 +64,6 @@ struct Entry
|
|
size; //and with
|
|
size; //and with
|
|
LodFileType type;// file type determined by extension
|
|
LodFileType type;// file type determined by extension
|
|
|
|
|
|
- bool operator<(const Entry & comp) const
|
|
|
|
- {
|
|
|
|
- return type==comp.type ? name<comp.name
|
|
|
|
- : type<comp.type;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
bool operator == (const Entry & comp) const
|
|
bool operator == (const Entry & comp) const
|
|
{
|
|
{
|
|
return (type==comp.type || comp.type== FILE_ANY) && name==comp.name;
|
|
return (type==comp.type || comp.type== FILE_ANY) && name==comp.name;
|
|
@@ -78,6 +74,18 @@ struct Entry
|
|
Entry(){};
|
|
Entry(){};
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+template<>
|
|
|
|
+struct boost::hash<Entry> : public std::unary_function<Entry, std::size_t> {
|
|
|
|
+private:
|
|
|
|
+ boost::hash<std::string> stringHasher;
|
|
|
|
+public:
|
|
|
|
+ std::size_t operator()(Entry const& en) const
|
|
|
|
+ {
|
|
|
|
+ //do NOT improve this hash function as we need same-name hash collisions for find to work properly
|
|
|
|
+ return stringHasher(en.name);
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
class DLL_EXPORT CLodHandler
|
|
class DLL_EXPORT CLodHandler
|
|
{
|
|
{
|
|
std::map<std::string, LodFileType> extMap;// to convert extensions to file type
|
|
std::map<std::string, LodFileType> extMap;// to convert extensions to file type
|
|
@@ -88,12 +96,11 @@ class DLL_EXPORT CLodHandler
|
|
std::string myDir; //load files from this dir instead of .lod file
|
|
std::string myDir; //load files from this dir instead of .lod file
|
|
|
|
|
|
void initEntry(Entry &e, const std::string name);
|
|
void initEntry(Entry &e, const std::string name);
|
|
- Entry getEntry(const std::string name, LodFileType);
|
|
|
|
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
|
|
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
|
|
|
|
|
|
public:
|
|
public:
|
|
|
|
|
|
- std::set<Entry> entries;
|
|
|
|
|
|
+ boost::unordered_set<Entry> entries;
|
|
|
|
|
|
CLodHandler();
|
|
CLodHandler();
|
|
~CLodHandler();
|
|
~CLodHandler();
|