mirror of https://github.com/libAthena/athena.git
Merge pull request #72 from lioncash/constexpr
DNAYaml: Make use of if constexpr where applicable
This commit is contained in:
commit
9a2277091f
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "athena/DNA.hpp"
|
||||
#include "athena/FileReader.hpp"
|
||||
|
@ -12,13 +11,12 @@
|
|||
namespace athena::io {
|
||||
|
||||
template <class T>
|
||||
inline std::string_view __GetDNAName(const T& dna, std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
|
||||
std::string_view __GetDNAName(const T& dna) {
|
||||
if constexpr (__IsDNAVRecord_v<T>) {
|
||||
return dna.DNATypeV();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline std::string_view __GetDNAName(const T& dna, std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
|
||||
} else {
|
||||
return dna.DNAType();
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <type_traits>
|
||||
|
||||
#include "athena/YAMLCommon.hpp"
|
||||
|
||||
|
@ -138,21 +139,23 @@ std::unique_ptr<YAMLNode> ValToNode(double val) {
|
|||
|
||||
template <typename RETURNTYPE>
|
||||
RETURNTYPE NodeToVec(const YAMLNode* node) {
|
||||
constexpr bool isDouble = std::is_same<RETURNTYPE, atVec2d>::value || std::is_same<RETURNTYPE, atVec3d>::value ||
|
||||
std::is_same<RETURNTYPE, atVec4d>::value;
|
||||
constexpr bool isDouble =
|
||||
std::is_same_v<RETURNTYPE, atVec2d> || std::is_same_v<RETURNTYPE, atVec3d> || std::is_same_v<RETURNTYPE, atVec4d>;
|
||||
RETURNTYPE retval = {};
|
||||
auto it = node->m_seqChildren.begin();
|
||||
simd_values<std::conditional_t<isDouble, double, float>> f;
|
||||
for (size_t i = 0; i < 4 && it != node->m_seqChildren.end(); ++i, ++it) {
|
||||
YAMLNode* snode = it->get();
|
||||
if (snode->m_type == YAML_SCALAR_NODE) {
|
||||
if (isDouble)
|
||||
if constexpr (isDouble) {
|
||||
f[i] = NodeToVal<double>(snode);
|
||||
else
|
||||
} else {
|
||||
f[i] = NodeToVal<float>(snode);
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
f[i] = 0.0;
|
||||
}
|
||||
}
|
||||
retval.simd.copy_from(f);
|
||||
return retval;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue