mirror of https://github.com/OpenMW/openmw.git
Support index RefId as pair of record type and std::uint32_t
parent
86293af084
commit
e6cf516e12
@ -0,0 +1,26 @@
|
||||
#include "indexrefid.hpp"
|
||||
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "esmcommon.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
std::string IndexRefId::toString() const
|
||||
{
|
||||
return ESM::NAME(mRecordType).toString() + ", " + std::to_string(mValue);
|
||||
}
|
||||
|
||||
std::string IndexRefId::toDebugString() const
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << *this;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, IndexRefId value)
|
||||
{
|
||||
return stream << "Index{" << ESM::NAME(value.mRecordType).toStringView() << ", " << value.mValue << '}';
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
#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) | value.mValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue