1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*
* ResourceID.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
/**
* Specifies the resource type.
*
* Supported file extensions:
*
* Text: .txt .json
* Animation: .def
* Mask: .msk .msg
* Campaign: .h3c
* Map: .h3m
* Font: .fnt
* Image: .bmp, .jpg, .pcx, .png, .tga
* Sound: .wav .82m
* Video: .smk, .bik .mjpg .mpg
* Music: .mp3, .ogg
* Archive: .lod, .snd, .vid .pac .zip
* Palette: .pal
* Savegame: .v*gm1
*/
namespace EResType
{
enum Type
{
TEXT,
ANIMATION,
MASK,
CAMPAIGN,
MAP,
BMP_FONT,
TTF_FONT,
IMAGE,
VIDEO,
SOUND,
MUSIC,
ARCHIVE_VID,
ARCHIVE_ZIP,
ARCHIVE_SND,
ARCHIVE_LOD,
PALETTE,
CLIENT_SAVEGAME,
SERVER_SAVEGAME,
DIRECTORY,
ERM,
ERT,
ERS,
OTHER,
UNDEFINED
};
}
/**
* A struct which identifies a resource clearly.
*/
class DLL_LINKAGE ResourceID
{
public:
/**
* Default c-tor.
*/
//ResourceID();
/**
* Ctor. Can be used to create identifier for resource loading using one parameter
*
* @param fullName The resource name including extension.
*/
explicit ResourceID(std::string fullName);
/**
* Ctor.
*
* @param name The resource name.
* @param type The resource type. A constant from the enumeration EResType.
*/
ResourceID(std::string name, EResType::Type type);
/**
* Compares this object with a another resource identifier.
*
* @param other The other resource identifier.
* @return Returns true if both are equally, false if not.
*/
inline bool operator==(ResourceID const & other) const
{
return name == other.name && type == other.type;
}
std::string getName() const {return name;}
EResType::Type getType() const {return type;}
//void setName(std::string name);
//void setType(EResType::Type type);
private:
/**
* Specifies the resource type. EResType::OTHER if not initialized.
* Required to prevent conflicts if files with different types (e.g. text and image) have the same name.
*/
EResType::Type type;
/** Specifies the resource name. No extension so .pcx and .png can override each other, always in upper case. **/
std::string name;
};
namespace std
{
template <> struct hash<ResourceID>
{
size_t operator()(const ResourceID & resourceIdent) const
{
std::hash<int> intHasher;
std::hash<std::string> stringHasher;
return stringHasher(resourceIdent.getName()) ^ intHasher(static_cast<int>(resourceIdent.getType()));
}
};
}
/**
* A helper class which provides a functionality to convert extension strings to EResTypes.
*/
class DLL_LINKAGE EResTypeHelper
{
public:
/**
* Converts a extension string to a EResType enum object.
*
* @param extension The extension string e.g. .BMP, .PNG
* @return Returns a EResType enum object
*/
static EResType::Type getTypeFromExtension(std::string extension);
/**
* Gets the EResType as a string representation.
*
* @param type the EResType
* @return the type as a string representation
*/
static std::string getEResTypeAsString(EResType::Type type);
};
|