mirror of https://github.com/libAthena/athena.git
Merge pull request #76 from lioncash/dependent
DNAOp: Make use of template keyword for dependent templates
This commit is contained in:
commit
ec43f653a7
|
@ -147,18 +147,20 @@ struct BinarySize {
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
|
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
|
||||||
for (auto& v : var)
|
for (auto& v : var) {
|
||||||
BinarySize<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
|
BinarySize<PropOp>::template Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
||||||
BinarySize<PropOp>::Do<T, DNAE>(id, var, s);
|
BinarySize<PropOp>::template Do<T, DNAE>(id, var, s);
|
||||||
}
|
}
|
||||||
template <class T, class S, Endian DNAE>
|
template <class T, class S, Endian DNAE>
|
||||||
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
||||||
StreamT& s) {
|
StreamT& s) {
|
||||||
for (T& v : vector)
|
for (T& v : vector) {
|
||||||
BinarySize<PropOp>::Do<T, DNAE>(id, v, s);
|
BinarySize<PropOp>::template Do<T, DNAE>(id, v, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <class T, class S, Endian DNAE>
|
template <class T, class S, Endian DNAE>
|
||||||
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
||||||
|
@ -255,7 +257,7 @@ struct PropCount {
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
||||||
PropCount<PropOp>::Do<T, DNAE>(id, var, s);
|
PropCount<PropOp>::template Do<T, DNAE>(id, var, s);
|
||||||
}
|
}
|
||||||
template <class T, class S, Endian DNAE>
|
template <class T, class S, Endian DNAE>
|
||||||
static void Do(const PropId& id, std::vector<T>& vector, const S& count, StreamT& s) {
|
static void Do(const PropId& id, std::vector<T>& vector, const S& count, StreamT& s) {
|
||||||
|
@ -327,12 +329,13 @@ struct Read {
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
|
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
|
||||||
for (auto& v : var)
|
for (auto& v : var) {
|
||||||
Read<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
|
Read<PropOp>::template Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
||||||
Read<PropOp>::Do<T, DNAE>(id, var, s);
|
Read<PropOp>::template Do<T, DNAE>(id, var, s);
|
||||||
}
|
}
|
||||||
template <class T, class S, Endian DNAE>
|
template <class T, class S, Endian DNAE>
|
||||||
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
||||||
|
@ -341,7 +344,7 @@ struct Read {
|
||||||
vector.reserve(count);
|
vector.reserve(count);
|
||||||
for (size_t i = 0; i < static_cast<size_t>(count); ++i) {
|
for (size_t i = 0; i < static_cast<size_t>(count); ++i) {
|
||||||
vector.emplace_back();
|
vector.emplace_back();
|
||||||
Read<PropOp>::Do<T, DNAE>(id, vector.back(), r);
|
Read<PropOp>::template Do<T, DNAE>(id, vector.back(), r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <class T, class S, Endian DNAE>
|
template <class T, class S, Endian DNAE>
|
||||||
|
@ -483,18 +486,20 @@ struct Write {
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
|
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
|
||||||
for (auto& v : var)
|
for (auto& v : var) {
|
||||||
Write<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
|
Write<PropOp>::template Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
||||||
Write<PropOp>::Do<T, DNAE>(id, var, s);
|
Write<PropOp>::template Do<T, DNAE>(id, var, s);
|
||||||
}
|
}
|
||||||
template <class T, class S, Endian DNAE>
|
template <class T, class S, Endian DNAE>
|
||||||
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
||||||
StreamT& w) {
|
StreamT& w) {
|
||||||
for (T& v : vector)
|
for (T& v : vector) {
|
||||||
Write<PropOp>::Do<T, DNAE>(id, v, w);
|
Write<PropOp>::template Do<T, DNAE>(id, v, w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <class T, class S, Endian DNAE>
|
template <class T, class S, Endian DNAE>
|
||||||
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
||||||
|
@ -596,9 +601,11 @@ struct ReadYaml {
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& r) {
|
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& r) {
|
||||||
size_t _count;
|
size_t _count;
|
||||||
if (auto __v = r.enterSubVector(id.name, _count))
|
if (auto __v = r.enterSubVector(id.name, _count)) {
|
||||||
for (size_t i = 0; i < _count && i < std::extent_v<T>; ++i)
|
for (size_t i = 0; i < _count && i < std::extent_v<T>; ++i) {
|
||||||
ReadYaml<PropOp>::Do<std::remove_reference_t<decltype(var[i])>, DNAE>({}, var[i], r);
|
ReadYaml<PropOp>::template Do<std::remove_reference_t<decltype(var[i])>, DNAE>({}, var[i], r);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
||||||
|
@ -613,7 +620,7 @@ struct ReadYaml {
|
||||||
vector.reserve(_count);
|
vector.reserve(_count);
|
||||||
for (size_t i = 0; i < _count; ++i) {
|
for (size_t i = 0; i < _count; ++i) {
|
||||||
vector.emplace_back();
|
vector.emplace_back();
|
||||||
ReadYaml<PropOp>::Do<T, DNAE>({}, vector.back(), r);
|
ReadYaml<PropOp>::template Do<T, DNAE>({}, vector.back(), r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Horrible reference abuse (but it works) */
|
/* Horrible reference abuse (but it works) */
|
||||||
|
@ -712,9 +719,11 @@ struct WriteYaml {
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& w) {
|
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& w) {
|
||||||
if (auto __v = w.enterSubVector(id.name))
|
if (auto __v = w.enterSubVector(id.name)) {
|
||||||
for (auto& v : var)
|
for (auto& v : var) {
|
||||||
WriteYaml<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>({}, v, w);
|
WriteYaml<PropOp>::template Do<std::remove_reference_t<decltype(v)>, DNAE>({}, v, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
static void DoSize(const PropId& id, T& var, StreamT& s) {
|
||||||
|
@ -723,9 +732,11 @@ struct WriteYaml {
|
||||||
template <class T, class S, Endian DNAE>
|
template <class T, class S, Endian DNAE>
|
||||||
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
||||||
StreamT& w) {
|
StreamT& w) {
|
||||||
if (auto __v = w.enterSubVector(id.name))
|
if (auto __v = w.enterSubVector(id.name)) {
|
||||||
for (T& v : vector)
|
for (T& v : vector) {
|
||||||
WriteYaml<PropOp>::Do<T, DNAE>(id, v, w);
|
WriteYaml<PropOp>::template Do<T, DNAE>(id, v, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
template <class T, class S, Endian DNAE>
|
template <class T, class S, Endian DNAE>
|
||||||
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
|
||||||
|
|
|
@ -21,7 +21,7 @@ MemoryReader::MemoryReader(const void* data, atUint64 length, bool takeOwnership
|
||||||
|
|
||||||
MemoryReader::~MemoryReader() {
|
MemoryReader::~MemoryReader() {
|
||||||
if (m_owns)
|
if (m_owns)
|
||||||
delete[] reinterpret_cast<const atUint8*>(m_data);
|
delete[] static_cast<const atUint8*>(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryCopyReader::MemoryCopyReader(const void* data, atUint64 length) : MemoryReader(data, length, false) {
|
MemoryCopyReader::MemoryCopyReader(const void* data, atUint64 length) : MemoryReader(data, length, false) {
|
||||||
|
@ -111,7 +111,7 @@ atUint64 MemoryReader::readUBytesToBuf(void* buf, atUint64 length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
length = std::min(length, m_length - m_position);
|
length = std::min(length, m_length - m_position);
|
||||||
memmove(buf, reinterpret_cast<const atUint8*>(m_data) + m_position, length);
|
memmove(buf, static_cast<const atUint8*>(m_data) + m_position, length);
|
||||||
m_position += length;
|
m_position += length;
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,7 +233,7 @@ void MemoryWriter::writeUBytes(const atUint8* data, atUint64 length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memmove(reinterpret_cast<atInt8*>(m_data + m_position), data, length);
|
memmove(m_data + m_position, data, length);
|
||||||
|
|
||||||
m_position += length;
|
m_position += length;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ void MemoryCopyWriter::writeUBytes(const atUint8* data, atUint64 length) {
|
||||||
if (m_position + length > m_length)
|
if (m_position + length > m_length)
|
||||||
resize(m_position + length);
|
resize(m_position + length);
|
||||||
|
|
||||||
memmove(reinterpret_cast<atInt8*>(m_data + m_position), data, length);
|
memmove(m_data + m_position, data, length);
|
||||||
|
|
||||||
m_position += length;
|
m_position += length;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue