mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#ifndef OPENMW_COMPONENTS_ESM_INDEXREFID_HPP
|
|
#define OPENMW_COMPONENTS_ESM_INDEXREFID_HPP
|
|
|
|
#include <functional>
|
|
#include <iosfwd>
|
|
|
|
#include "defs.hpp"
|
|
|
|
namespace ESM
|
|
{
|
|
class IndexRefId
|
|
{
|
|
public:
|
|
constexpr explicit IndexRefId(RecNameInts recordType, std::uint32_t value) noexcept
|
|
: mRecordType(recordType)
|
|
, mValue(value)
|
|
{
|
|
}
|
|
|
|
constexpr RecNameInts getRecordType() const { return mRecordType; }
|
|
|
|
constexpr std::uint32_t getValue() const { return mValue; }
|
|
|
|
std::string toString() const;
|
|
|
|
std::string toDebugString() const;
|
|
|
|
friend inline constexpr auto tie(const IndexRefId& value) noexcept
|
|
{
|
|
return std::tie(value.mRecordType, value.mValue);
|
|
}
|
|
|
|
constexpr bool operator==(IndexRefId rhs) const noexcept { return tie(*this) == tie(rhs); }
|
|
|
|
constexpr bool operator<(IndexRefId rhs) const noexcept { return tie(*this) < tie(rhs); }
|
|
|
|
friend std::ostream& operator<<(std::ostream& stream, IndexRefId value);
|
|
|
|
friend struct std::hash<IndexRefId>;
|
|
|
|
private:
|
|
RecNameInts mRecordType;
|
|
std::uint32_t mValue;
|
|
};
|
|
|
|
static_assert(sizeof(IndexRefId) <= sizeof(std::uint64_t));
|
|
}
|
|
|
|
namespace std
|
|
{
|
|
template <>
|
|
struct hash<ESM::IndexRefId>
|
|
{
|
|
std::size_t operator()(ESM::IndexRefId value) const noexcept
|
|
{
|
|
return std::hash<std::uint64_t>{}((static_cast<std::uint64_t>(value.mRecordType) << 32) | value.mValue);
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif
|