2015-06-24 20:56:23 +00:00
|
|
|
#ifndef __DNA_COMMON_HPP__
|
|
|
|
#define __DNA_COMMON_HPP__
|
|
|
|
|
2015-07-29 20:45:47 +00:00
|
|
|
#include <stdio.h>
|
2016-03-04 23:04:53 +00:00
|
|
|
#include <athena/DNAYaml.hpp>
|
|
|
|
#include <nod/DiscBase.hpp>
|
|
|
|
#include "hecl/hecl.hpp"
|
|
|
|
#include "hecl/Database.hpp"
|
2015-08-05 21:46:07 +00:00
|
|
|
#include "../SpecBase.hpp"
|
2015-06-24 20:56:23 +00:00
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
namespace DataSpec
|
2015-07-01 23:50:39 +00:00
|
|
|
{
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
extern logvisor::Module LogDNACommon;
|
2015-11-10 02:07:15 +00:00
|
|
|
extern SpecBase* g_curSpec;
|
2016-03-01 03:08:25 +00:00
|
|
|
extern class PAKRouterBase* g_PakRouter;
|
2015-07-16 01:57:34 +00:00
|
|
|
|
2015-06-24 20:56:23 +00:00
|
|
|
/* This comes up a great deal */
|
2016-03-04 23:04:53 +00:00
|
|
|
typedef athena::io::DNA<athena::BigEndian> BigDNA;
|
|
|
|
typedef athena::io::DNAYaml<athena::BigEndian> BigYAML;
|
2015-06-24 20:56:23 +00:00
|
|
|
|
2015-11-10 02:07:15 +00:00
|
|
|
/** FourCC with DNA read/write */
|
2016-03-04 23:04:53 +00:00
|
|
|
class DNAFourCC final : public BigYAML, public hecl::FourCC
|
2015-07-11 22:41:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-03-04 23:04:53 +00:00
|
|
|
DNAFourCC() : hecl::FourCC() {}
|
|
|
|
DNAFourCC(const hecl::FourCC& other)
|
|
|
|
: hecl::FourCC() {num = other.toUint32();}
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC(const char* name)
|
2016-03-04 23:04:53 +00:00
|
|
|
: hecl::FourCC(name) {}
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC(uint32_t n)
|
2016-03-04 23:04:53 +00:00
|
|
|
: hecl::FourCC(n) {}
|
2015-07-11 22:41:10 +00:00
|
|
|
|
|
|
|
Delete expl;
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::IStreamReader& reader)
|
2015-07-11 22:41:10 +00:00
|
|
|
{reader.readUBytesToBuf(fcc, 4);}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::IStreamWriter& writer) const
|
2015-07-11 22:41:10 +00:00
|
|
|
{writer.writeUBytes((atUint8*)fcc, 4);}
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::YAMLDocReader& reader)
|
2015-08-01 00:38:35 +00:00
|
|
|
{std::string rs = reader.readString(nullptr); strncpy(fcc, rs.c_str(), 4);}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::YAMLDocWriter& writer) const
|
2015-08-01 00:38:35 +00:00
|
|
|
{writer.writeString(nullptr, std::string(fcc, 4));}
|
2015-10-18 04:08:45 +00:00
|
|
|
size_t binarySize(size_t __isz) const
|
|
|
|
{return __isz + 4;}
|
2015-07-11 22:41:10 +00:00
|
|
|
};
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
using FourCC = hecl::FourCC;
|
2016-03-01 03:08:25 +00:00
|
|
|
class UniqueID32;
|
|
|
|
class UniqueID64;
|
|
|
|
class UniqueID128;
|
|
|
|
|
|
|
|
/** Common virtual interface for runtime ambiguity resolution */
|
|
|
|
class PAKRouterBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const SpecBase& m_dataSpec;
|
|
|
|
public:
|
|
|
|
PAKRouterBase(const SpecBase& dataSpec) : m_dataSpec(dataSpec) {}
|
2016-03-05 00:03:41 +00:00
|
|
|
hecl::Database::Project& getProject() const {return m_dataSpec.getProject();}
|
|
|
|
virtual hecl::ProjectPath getWorking(const UniqueID32&) const
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
2016-03-05 00:03:41 +00:00
|
|
|
LogDNACommon.report(logvisor::Fatal,
|
2016-03-02 07:29:19 +00:00
|
|
|
"PAKRouter IDType mismatch; expected UniqueID32 specialization");
|
2016-03-05 00:03:41 +00:00
|
|
|
return hecl::ProjectPath();
|
2016-03-01 03:08:25 +00:00
|
|
|
}
|
2016-03-05 00:03:41 +00:00
|
|
|
virtual hecl::ProjectPath getWorking(const UniqueID64&) const
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
2016-03-05 00:03:41 +00:00
|
|
|
LogDNACommon.report(logvisor::Fatal,
|
2016-03-02 07:29:19 +00:00
|
|
|
"PAKRouter IDType mismatch; expected UniqueID64 specialization");
|
2016-03-05 00:03:41 +00:00
|
|
|
return hecl::ProjectPath();
|
2016-03-01 03:08:25 +00:00
|
|
|
}
|
2016-03-05 00:03:41 +00:00
|
|
|
virtual hecl::ProjectPath getWorking(const UniqueID128&) const
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
2016-03-05 00:03:41 +00:00
|
|
|
LogDNACommon.report(logvisor::Fatal,
|
2016-03-02 07:29:19 +00:00
|
|
|
"PAKRouter IDType mismatch; expected UniqueID128 specialization");
|
2016-03-05 00:03:41 +00:00
|
|
|
return hecl::ProjectPath();
|
2016-03-01 03:08:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Globally-accessed manager allowing UniqueID* classes to directly
|
|
|
|
* lookup destination paths of resources */
|
|
|
|
class UniqueIDBridge
|
|
|
|
{
|
|
|
|
friend class UniqueID32;
|
|
|
|
friend class UniqueID64;
|
|
|
|
public:
|
|
|
|
template <class IDType>
|
2016-03-05 00:03:41 +00:00
|
|
|
static hecl::ProjectPath TranslatePakIdToPath(const IDType& id)
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
|
|
|
if (!g_PakRouter)
|
2016-03-05 00:03:41 +00:00
|
|
|
LogDNACommon.report(logvisor::Fatal,
|
2016-03-01 03:08:25 +00:00
|
|
|
"UniqueIDBridge::setPakRouter must be called before translatePakIdToPath");
|
2016-03-04 01:01:37 +00:00
|
|
|
return g_PakRouter->getWorking(id);
|
2016-03-01 03:08:25 +00:00
|
|
|
}
|
2016-03-05 00:03:41 +00:00
|
|
|
static hecl::ProjectPath MakePathFromString(const std::string& str)
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
2016-03-05 00:03:41 +00:00
|
|
|
return hecl::ProjectPath(g_PakRouter->getProject(), str);
|
2016-03-01 03:08:25 +00:00
|
|
|
}
|
|
|
|
template <class IDType>
|
|
|
|
static void TransformOldHashToNewHash(IDType& id)
|
|
|
|
{
|
|
|
|
id = TranslatePakIdToPath(id);
|
|
|
|
}
|
|
|
|
};
|
2015-08-23 06:42:29 +00:00
|
|
|
|
2015-11-10 02:07:15 +00:00
|
|
|
/** PAK 32-bit Unique ID */
|
2015-08-01 00:38:35 +00:00
|
|
|
class UniqueID32 : public BigYAML
|
2015-06-24 20:56:23 +00:00
|
|
|
{
|
2015-08-11 23:32:02 +00:00
|
|
|
uint32_t m_id = 0xffffffff;
|
2015-06-24 20:56:23 +00:00
|
|
|
public:
|
|
|
|
Delete expl;
|
2015-10-27 00:19:03 +00:00
|
|
|
operator bool() const {return m_id != 0xffffffff && m_id != 0;}
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::IStreamReader& reader)
|
2015-08-14 03:00:51 +00:00
|
|
|
{m_id = reader.readUint32Big();}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::IStreamWriter& writer) const
|
2015-08-14 03:00:51 +00:00
|
|
|
{writer.writeUint32Big(m_id);}
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::YAMLDocReader& reader)
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
|
|
|
*this = UniqueIDBridge::MakePathFromString(reader.readString(nullptr));
|
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::YAMLDocWriter& writer) const
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
2016-03-02 01:49:21 +00:00
|
|
|
if (!operator bool())
|
|
|
|
return;
|
2016-03-05 00:03:41 +00:00
|
|
|
hecl::ProjectPath path = UniqueIDBridge::TranslatePakIdToPath(*this);
|
2016-03-04 01:01:37 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
|
|
|
writer.writeString(nullptr, path.getRelativePathUTF8());
|
2016-03-01 03:08:25 +00:00
|
|
|
}
|
2015-10-18 04:08:45 +00:00
|
|
|
size_t binarySize(size_t __isz) const
|
|
|
|
{return __isz + 4;}
|
2015-07-06 01:33:06 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
UniqueID32& operator=(const hecl::ProjectPath& path)
|
2015-11-10 02:07:15 +00:00
|
|
|
{m_id = path.hash().val32(); return *this;}
|
|
|
|
|
2015-09-22 01:58:26 +00:00
|
|
|
bool operator!=(const UniqueID32& other) const {return m_id != other.m_id;}
|
|
|
|
bool operator==(const UniqueID32& other) const {return m_id == other.m_id;}
|
|
|
|
uint32_t toUint32() const {return m_id;}
|
2016-03-02 01:49:21 +00:00
|
|
|
uint64_t toUint64() const {return m_id;}
|
2015-09-22 01:58:26 +00:00
|
|
|
std::string toString() const
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
|
|
|
char buf[9];
|
|
|
|
snprintf(buf, 9, "%08X", m_id);
|
|
|
|
return std::string(buf);
|
|
|
|
}
|
2015-11-10 02:07:15 +00:00
|
|
|
void clear() {m_id = 0xffffffff;}
|
2015-10-19 03:28:47 +00:00
|
|
|
|
|
|
|
UniqueID32() = default;
|
2016-03-04 23:04:53 +00:00
|
|
|
UniqueID32(athena::io::IStreamReader& reader) {read(reader);}
|
|
|
|
UniqueID32(const hecl::ProjectPath& path) {*this = path;}
|
2015-10-19 03:28:47 +00:00
|
|
|
UniqueID32(const char* hexStr)
|
|
|
|
{
|
|
|
|
char copy[9];
|
|
|
|
strncpy(copy, hexStr, 8);
|
|
|
|
copy[8] = '\0';
|
|
|
|
m_id = strtoul(copy, nullptr, 16);
|
|
|
|
}
|
2015-11-10 20:12:43 +00:00
|
|
|
UniqueID32(const wchar_t* hexStr)
|
|
|
|
{
|
|
|
|
wchar_t copy[9];
|
|
|
|
wcsncpy(copy, hexStr, 8);
|
|
|
|
copy[8] = L'\0';
|
|
|
|
m_id = wcstoul(copy, nullptr, 16);
|
|
|
|
}
|
2015-11-10 02:07:15 +00:00
|
|
|
|
|
|
|
static constexpr size_t BinarySize() {return 4;}
|
2015-06-24 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
2015-11-10 02:07:15 +00:00
|
|
|
/** PAK 64-bit Unique ID */
|
2015-09-23 06:35:07 +00:00
|
|
|
class UniqueID64 : public BigYAML
|
2015-06-24 20:56:23 +00:00
|
|
|
{
|
2015-08-11 23:32:02 +00:00
|
|
|
uint64_t m_id = 0xffffffffffffffff;
|
2015-06-24 20:56:23 +00:00
|
|
|
public:
|
|
|
|
Delete expl;
|
2015-10-27 00:19:03 +00:00
|
|
|
operator bool() const {return m_id != 0xffffffffffffffff && m_id != 0;}
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::IStreamReader& reader)
|
2015-08-14 03:00:51 +00:00
|
|
|
{m_id = reader.readUint64Big();}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::IStreamWriter& writer) const
|
2015-08-14 03:00:51 +00:00
|
|
|
{writer.writeUint64Big(m_id);}
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::YAMLDocReader& reader)
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
|
|
|
*this = UniqueIDBridge::MakePathFromString(reader.readString(nullptr));
|
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::YAMLDocWriter& writer) const
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
2016-03-02 01:49:21 +00:00
|
|
|
if (!operator bool())
|
|
|
|
return;
|
2016-03-05 00:03:41 +00:00
|
|
|
hecl::ProjectPath path = UniqueIDBridge::TranslatePakIdToPath(*this);
|
2016-03-04 01:01:37 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
|
|
|
writer.writeString(nullptr, path.getRelativePathUTF8());
|
2016-03-01 03:08:25 +00:00
|
|
|
}
|
2015-10-18 04:08:45 +00:00
|
|
|
size_t binarySize(size_t __isz) const
|
|
|
|
{return __isz + 8;}
|
2015-07-06 01:33:06 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
UniqueID64& operator=(const hecl::ProjectPath& path)
|
2015-11-10 02:07:15 +00:00
|
|
|
{m_id = path.hash().val64(); return *this;}
|
|
|
|
|
2015-09-22 01:58:26 +00:00
|
|
|
bool operator!=(const UniqueID64& other) const {return m_id != other.m_id;}
|
|
|
|
bool operator==(const UniqueID64& other) const {return m_id == other.m_id;}
|
|
|
|
uint64_t toUint64() const {return m_id;}
|
|
|
|
std::string toString() const
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
|
|
|
char buf[17];
|
2015-08-31 21:26:46 +00:00
|
|
|
snprintf(buf, 17, "%016" PRIX64, m_id);
|
2015-07-06 01:33:06 +00:00
|
|
|
return std::string(buf);
|
|
|
|
}
|
2015-11-10 02:07:15 +00:00
|
|
|
void clear() {m_id = 0xffffffffffffffff;}
|
2015-10-19 03:28:47 +00:00
|
|
|
|
|
|
|
UniqueID64() = default;
|
2016-03-04 23:04:53 +00:00
|
|
|
UniqueID64(athena::io::IStreamReader& reader) {read(reader);}
|
|
|
|
UniqueID64(const hecl::ProjectPath& path) {*this = path;}
|
2015-10-19 03:28:47 +00:00
|
|
|
UniqueID64(const char* hexStr)
|
|
|
|
{
|
|
|
|
char copy[17];
|
|
|
|
strncpy(copy, hexStr, 16);
|
|
|
|
copy[16] = '\0';
|
2015-11-10 20:12:43 +00:00
|
|
|
#if _WIN32
|
|
|
|
m_id = _strtoui64(copy, nullptr, 16);
|
|
|
|
#else
|
2015-10-19 03:28:47 +00:00
|
|
|
m_id = strtouq(copy, nullptr, 16);
|
2015-11-10 20:12:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
UniqueID64(const wchar_t* hexStr)
|
|
|
|
{
|
|
|
|
wchar_t copy[17];
|
|
|
|
wcsncpy(copy, hexStr, 16);
|
|
|
|
copy[16] = L'\0';
|
|
|
|
#if _WIN32
|
|
|
|
m_id = _wcstoui64(copy, nullptr, 16);
|
|
|
|
#else
|
2015-11-11 07:04:17 +00:00
|
|
|
m_id = wcstoull(copy, nullptr, 16);
|
2015-11-10 20:12:43 +00:00
|
|
|
#endif
|
2015-10-19 03:28:47 +00:00
|
|
|
}
|
2015-11-10 02:07:15 +00:00
|
|
|
|
|
|
|
static constexpr size_t BinarySize() {return 8;}
|
2015-06-24 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
2015-11-10 02:07:15 +00:00
|
|
|
/** PAK 128-bit Unique ID */
|
2015-09-23 06:35:07 +00:00
|
|
|
class UniqueID128 : public BigYAML
|
2015-06-24 20:56:23 +00:00
|
|
|
{
|
2015-07-06 01:33:06 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
uint64_t m_id[2];
|
|
|
|
#if __SSE__
|
|
|
|
__m128i m_id128;
|
|
|
|
#endif
|
|
|
|
};
|
2015-06-24 20:56:23 +00:00
|
|
|
public:
|
|
|
|
Delete expl;
|
2015-08-11 23:32:02 +00:00
|
|
|
UniqueID128() {m_id[0]=0xffffffffffffffff; m_id[1]=0xffffffffffffffff;}
|
2015-09-22 01:58:26 +00:00
|
|
|
operator bool() const
|
2015-10-27 00:19:03 +00:00
|
|
|
{return m_id[0] != 0xffffffffffffffff && m_id[0] != 0 && m_id[1] != 0xffffffffffffffff && m_id[1] != 0;}
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::IStreamReader& reader)
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
2015-08-14 03:00:51 +00:00
|
|
|
m_id[0] = reader.readUint64Big();
|
|
|
|
m_id[1] = reader.readUint64Big();
|
2015-07-06 01:33:06 +00:00
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::IStreamWriter& writer) const
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
2015-08-14 03:00:51 +00:00
|
|
|
writer.writeUint64Big(m_id[0]);
|
|
|
|
writer.writeUint64Big(m_id[1]);
|
2015-07-06 01:33:06 +00:00
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::YAMLDocReader& reader)
|
2015-09-23 06:35:07 +00:00
|
|
|
{
|
2016-03-01 03:08:25 +00:00
|
|
|
*this = UniqueIDBridge::MakePathFromString(reader.readString(nullptr));
|
2015-09-23 06:35:07 +00:00
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::YAMLDocWriter& writer) const
|
2015-09-23 06:35:07 +00:00
|
|
|
{
|
2016-03-02 01:49:21 +00:00
|
|
|
if (!operator bool())
|
|
|
|
return;
|
2016-03-05 00:03:41 +00:00
|
|
|
hecl::ProjectPath path = UniqueIDBridge::TranslatePakIdToPath(*this);
|
2016-03-04 01:01:37 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
|
|
|
writer.writeString(nullptr, path.getRelativePathUTF8());
|
2015-09-23 06:35:07 +00:00
|
|
|
}
|
2015-10-18 04:08:45 +00:00
|
|
|
size_t binarySize(size_t __isz) const
|
|
|
|
{return __isz + 16;}
|
2015-07-06 01:33:06 +00:00
|
|
|
|
2016-03-05 00:03:41 +00:00
|
|
|
UniqueID128& operator=(const hecl::ProjectPath& path)
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
|
|
|
m_id[0] = path.hash().val64();
|
|
|
|
m_id[1] = 0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-09-22 01:58:26 +00:00
|
|
|
bool operator!=(const UniqueID128& other) const
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
|
|
|
#if __SSE__
|
2015-07-06 02:07:57 +00:00
|
|
|
__m128i vcmp = _mm_cmpeq_epi32(m_id128, other.m_id128);
|
|
|
|
int vmask = _mm_movemask_epi8(vcmp);
|
|
|
|
return vmask != 0xffff;
|
2015-07-06 01:33:06 +00:00
|
|
|
#else
|
|
|
|
return (m_id[0] != other.m_id[0]) || (m_id[1] != other.m_id[1]);
|
|
|
|
#endif
|
|
|
|
}
|
2015-09-22 01:58:26 +00:00
|
|
|
bool operator==(const UniqueID128& other) const
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
|
|
|
#if __SSE__
|
2015-07-06 02:07:57 +00:00
|
|
|
__m128i vcmp = _mm_cmpeq_epi32(m_id128, other.m_id128);
|
|
|
|
int vmask = _mm_movemask_epi8(vcmp);
|
|
|
|
return vmask == 0xffff;
|
2015-07-06 01:33:06 +00:00
|
|
|
#else
|
|
|
|
return (m_id[0] == other.m_id[0]) && (m_id[1] == other.m_id[1]);
|
|
|
|
#endif
|
|
|
|
}
|
2015-11-10 02:07:15 +00:00
|
|
|
void clear() {m_id[0] = 0xffffffffffffffff; m_id[1] = 0xffffffffffffffff;}
|
2015-09-22 01:58:26 +00:00
|
|
|
uint64_t toHighUint64() const {return m_id[0];}
|
|
|
|
uint64_t toLowUint64() const {return m_id[1];}
|
|
|
|
std::string toString() const
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
|
|
|
char buf[33];
|
2015-08-31 21:26:46 +00:00
|
|
|
snprintf(buf, 33, "%016" PRIX64 "%016" PRIX64, m_id[0], m_id[1]);
|
2015-07-06 01:33:06 +00:00
|
|
|
return std::string(buf);
|
|
|
|
}
|
2015-11-10 02:07:15 +00:00
|
|
|
|
|
|
|
static constexpr size_t BinarySize() {return 16;}
|
2015-06-24 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
2015-11-10 02:07:15 +00:00
|
|
|
/** Word Bitmap reader/writer */
|
2015-08-31 03:44:42 +00:00
|
|
|
class WordBitmap
|
2015-08-11 23:32:02 +00:00
|
|
|
{
|
|
|
|
std::vector<atUint32> m_words;
|
|
|
|
size_t m_bitCount = 0;
|
2015-08-31 03:44:42 +00:00
|
|
|
public:
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::IStreamReader& reader, size_t bitCount)
|
2015-08-11 23:32:02 +00:00
|
|
|
{
|
|
|
|
m_bitCount = bitCount;
|
|
|
|
size_t wordCount = (bitCount + 31) / 32;
|
|
|
|
m_words.clear();
|
|
|
|
m_words.reserve(wordCount);
|
|
|
|
for (size_t w=0 ; w<wordCount ; ++w)
|
2015-08-14 03:00:51 +00:00
|
|
|
m_words.push_back(reader.readUint32Big());
|
2015-08-11 23:32:02 +00:00
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::IStreamWriter& writer) const
|
2015-08-11 23:32:02 +00:00
|
|
|
{
|
|
|
|
for (atUint32 word : m_words)
|
|
|
|
writer.writeUint32(word);
|
|
|
|
}
|
2015-10-18 04:08:45 +00:00
|
|
|
size_t binarySize(size_t __isz) const
|
|
|
|
{
|
|
|
|
return __isz + m_words.size() * 4;
|
|
|
|
}
|
2015-08-11 23:32:02 +00:00
|
|
|
size_t getBitCount() const {return m_bitCount;}
|
|
|
|
bool getBit(size_t idx) const
|
|
|
|
{
|
|
|
|
size_t wordIdx = idx / 32;
|
|
|
|
if (wordIdx >= m_words.size())
|
|
|
|
return false;
|
|
|
|
size_t wordCur = idx % 32;
|
|
|
|
return (m_words[wordIdx] >> wordCur) & 0x1;
|
|
|
|
}
|
|
|
|
void setBit(size_t idx)
|
|
|
|
{
|
|
|
|
size_t wordIdx = idx / 32;
|
|
|
|
while (wordIdx >= m_words.size())
|
|
|
|
m_words.push_back(0);
|
|
|
|
size_t wordCur = idx % 32;
|
|
|
|
m_words[wordIdx] |= (1 << wordCur);
|
|
|
|
}
|
|
|
|
void unsetBit(size_t idx)
|
|
|
|
{
|
|
|
|
size_t wordIdx = idx / 32;
|
|
|
|
while (wordIdx >= m_words.size())
|
|
|
|
m_words.push_back(0);
|
|
|
|
size_t wordCur = idx % 32;
|
|
|
|
m_words[wordIdx] &= ~(1 << wordCur);
|
|
|
|
}
|
2015-11-10 02:07:15 +00:00
|
|
|
void clear() {m_words.clear();}
|
2015-08-11 23:32:02 +00:00
|
|
|
|
|
|
|
class Iterator : public std::iterator<std::forward_iterator_tag, bool>
|
|
|
|
{
|
|
|
|
friend class WordBitmap;
|
|
|
|
const WordBitmap& m_bmp;
|
|
|
|
size_t m_idx = 0;
|
|
|
|
Iterator(const WordBitmap& bmp, size_t idx) : m_bmp(bmp), m_idx(idx) {}
|
|
|
|
public:
|
|
|
|
Iterator& operator++() {++m_idx; return *this;}
|
|
|
|
bool operator*() {return m_bmp.getBit(m_idx);}
|
|
|
|
bool operator!=(const Iterator& other) const {return m_idx != other.m_idx;}
|
|
|
|
};
|
|
|
|
Iterator begin() const {return Iterator(*this, 0);}
|
|
|
|
Iterator end() const {return Iterator(*this, m_bitCount);}
|
|
|
|
};
|
|
|
|
|
2015-11-10 02:07:15 +00:00
|
|
|
/** Resource cooker function */
|
2016-03-04 23:04:53 +00:00
|
|
|
typedef std::function<bool(const hecl::ProjectPath&, const hecl::ProjectPath&)> ResCooker;
|
2015-07-10 05:28:08 +00:00
|
|
|
|
2015-07-06 01:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Hash template-specializations for UniqueID types */
|
|
|
|
namespace std
|
2015-06-24 20:56:23 +00:00
|
|
|
{
|
2015-07-13 06:29:12 +00:00
|
|
|
template<>
|
2016-02-13 09:02:47 +00:00
|
|
|
struct hash<DataSpec::DNAFourCC>
|
2015-07-13 06:29:12 +00:00
|
|
|
{
|
2016-02-13 09:02:47 +00:00
|
|
|
size_t operator()(const DataSpec::DNAFourCC& fcc) const
|
2015-07-13 06:29:12 +00:00
|
|
|
{return fcc.toUint32();}
|
|
|
|
};
|
|
|
|
|
2015-07-06 01:33:06 +00:00
|
|
|
template<>
|
2016-02-13 09:02:47 +00:00
|
|
|
struct hash<DataSpec::UniqueID32>
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
2016-02-13 09:02:47 +00:00
|
|
|
size_t operator()(const DataSpec::UniqueID32& id) const
|
2015-07-06 02:07:57 +00:00
|
|
|
{return id.toUint32();}
|
2015-07-06 01:33:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2016-02-13 09:02:47 +00:00
|
|
|
struct hash<DataSpec::UniqueID64>
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
2016-02-13 09:02:47 +00:00
|
|
|
size_t operator()(const DataSpec::UniqueID64& id) const
|
2015-07-06 02:07:57 +00:00
|
|
|
{return id.toUint64();}
|
2015-06-24 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
2015-07-06 01:33:06 +00:00
|
|
|
template<>
|
2016-02-13 09:02:47 +00:00
|
|
|
struct hash<DataSpec::UniqueID128>
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
2016-02-13 09:02:47 +00:00
|
|
|
size_t operator()(const DataSpec::UniqueID128& id) const
|
2015-07-06 02:07:57 +00:00
|
|
|
{return id.toHighUint64() ^ id.toLowUint64();}
|
2015-07-06 01:33:06 +00:00
|
|
|
};
|
2015-07-01 23:50:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 20:56:23 +00:00
|
|
|
#endif // __DNA_COMMON_HPP__
|