mirror of https://github.com/libAthena/athena.git
MSVC SFINAE bug fixes
This commit is contained in:
parent
2381e65d0d
commit
2b41d0234a
|
@ -237,6 +237,10 @@ install(EXPORT AthenaTargets DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT athena)
|
||||||
|
|
||||||
if(NOT GEKKO)
|
if(NOT GEKKO)
|
||||||
add_subdirectory(atdna)
|
add_subdirectory(atdna)
|
||||||
|
# Test target
|
||||||
|
atdna(atdna_test.cpp atdna/test.hpp)
|
||||||
|
add_executable(atdna-test atdna/test.cpp atdna_test.cpp atdna/test.hpp)
|
||||||
|
target_link_libraries(atdna-test athena-core athena-libyaml)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#########
|
#########
|
||||||
|
|
|
@ -234,9 +234,4 @@ macro(atdna out)
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
# Test target
|
|
||||||
atdna(atdna_test.cpp test.hpp)
|
|
||||||
add_executable(atdna-test test.cpp atdna_test.cpp test.hpp)
|
|
||||||
target_link_libraries(atdna-test athena-core athena-libyaml)
|
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "YAMLDocReader.hpp"
|
#include "YAMLDocReader.hpp"
|
||||||
#include "YAMLDocWriter.hpp"
|
#include "YAMLDocWriter.hpp"
|
||||||
#include "ChecksumsLiterals.hpp"
|
#include "ChecksumsLiterals.hpp"
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace athena::io
|
namespace athena::io
|
||||||
{
|
{
|
||||||
|
@ -65,16 +66,15 @@ enum class PropType
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static inline constexpr bool __IsPODType()
|
using __IsPODType = typename std::disjunction<std::is_arithmetic<T>,
|
||||||
{
|
std::is_convertible<T&, atVec2f&>,
|
||||||
return std::is_arithmetic_v<T> ||
|
std::is_convertible<T&, atVec3f&>,
|
||||||
std::is_convertible_v<T&, atVec2f&> ||
|
std::is_convertible<T&, atVec4f&>,
|
||||||
std::is_convertible_v<T&, atVec3f&> ||
|
std::is_convertible<T&, atVec2d&>,
|
||||||
std::is_convertible_v<T&, atVec4f&> ||
|
std::is_convertible<T&, atVec3d&>,
|
||||||
std::is_convertible_v<T&, atVec2d&> ||
|
std::is_convertible<T&, atVec4d&>>;
|
||||||
std::is_convertible_v<T&, atVec3d&> ||
|
template <class T>
|
||||||
std::is_convertible_v<T&, atVec4d&>;
|
inline constexpr bool __IsPODType_v = __IsPODType<T>::value;
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
using __CastPODType = typename std::conditional_t<std::is_convertible_v<T&, atVec2f&>, atVec2f,
|
using __CastPODType = typename std::conditional_t<std::is_convertible_v<T&, atVec2f&>, atVec2f,
|
||||||
|
@ -139,7 +139,7 @@ struct BinarySize
|
||||||
BinarySize<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), s);
|
BinarySize<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), s);
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static typename std::enable_if_t<__IsPODType<T>()>
|
static typename std::enable_if_t<__IsPODType_v<T>>
|
||||||
Do(const PropId& id, T& var, StreamT& s)
|
Do(const PropId& id, T& var, StreamT& s)
|
||||||
{
|
{
|
||||||
if (PropOp != PropType::None)
|
if (PropOp != PropType::None)
|
||||||
|
@ -151,7 +151,7 @@ struct BinarySize
|
||||||
BinarySize<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), s);
|
BinarySize<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), s);
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static typename std::enable_if_t<__IsDNARecord<T>() && PropOp != PropType::None>
|
static typename std::enable_if_t<__IsDNARecord_v<T> && PropOp != PropType::None>
|
||||||
Do(const PropId& id, T& var, StreamT& s)
|
Do(const PropId& id, T& var, StreamT& s)
|
||||||
{
|
{
|
||||||
/* Accessed via Enumerate, header */
|
/* Accessed via Enumerate, header */
|
||||||
|
@ -159,7 +159,7 @@ struct BinarySize
|
||||||
var.template Enumerate<BinarySize<PropOp>>(s);
|
var.template Enumerate<BinarySize<PropOp>>(s);
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static typename std::enable_if_t<__IsDNARecord<T>() && PropOp == PropType::None>
|
static typename std::enable_if_t<__IsDNARecord_v<T> && PropOp == PropType::None>
|
||||||
Do(const PropId& id, T& var, StreamT& s)
|
Do(const PropId& id, T& var, StreamT& s)
|
||||||
{
|
{
|
||||||
var.template Enumerate<BinarySize<PropType::None>>(s);
|
var.template Enumerate<BinarySize<PropType::None>>(s);
|
||||||
|
@ -347,7 +347,7 @@ struct Read
|
||||||
Read<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
|
Read<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static typename std::enable_if_t<__IsPODType<T>()>
|
static typename std::enable_if_t<__IsPODType_v<T>>
|
||||||
Do(const PropId& id, T& var, StreamT& r)
|
Do(const PropId& id, T& var, StreamT& r)
|
||||||
{
|
{
|
||||||
using CastT = __CastPODType<T>;
|
using CastT = __CastPODType<T>;
|
||||||
|
@ -398,7 +398,7 @@ struct Read
|
||||||
{
|
{
|
||||||
vector.clear();
|
vector.clear();
|
||||||
vector.reserve(count);
|
vector.reserve(count);
|
||||||
for (size_t i = 0; i < 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>::Do<T, DNAE>(id, vector.back(), r);
|
||||||
|
@ -518,7 +518,7 @@ struct Write
|
||||||
Write<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
|
Write<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static typename std::enable_if_t<__IsPODType<T>()>
|
static typename std::enable_if_t<__IsPODType_v<T>>
|
||||||
Do(const PropId& id, T& var, StreamT& w)
|
Do(const PropId& id, T& var, StreamT& w)
|
||||||
{
|
{
|
||||||
using CastT = __CastPODType<T>;
|
using CastT = __CastPODType<T>;
|
||||||
|
@ -679,14 +679,14 @@ struct ReadYaml
|
||||||
ReadYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
|
ReadYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static typename std::enable_if_t<__IsPODType<T>()>
|
static typename std::enable_if_t<__IsPODType_v<T>>
|
||||||
Do(const PropId& id, T& var, StreamT& r)
|
Do(const PropId& id, T& var, StreamT& r)
|
||||||
{
|
{
|
||||||
using CastT = __CastPODType<T>;
|
using CastT = __CastPODType<T>;
|
||||||
ReadYaml<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), r);
|
ReadYaml<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), r);
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static typename std::enable_if_t<__IsDNARecord<T>()>
|
static typename std::enable_if_t<__IsDNARecord_v<T>>
|
||||||
Do(const PropId& id, T& var, StreamT& r)
|
Do(const PropId& id, T& var, StreamT& r)
|
||||||
{
|
{
|
||||||
if (auto rec = r.enterSubRecord(id.name))
|
if (auto rec = r.enterSubRecord(id.name))
|
||||||
|
@ -818,14 +818,14 @@ struct WriteYaml
|
||||||
WriteYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
|
WriteYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static typename std::enable_if_t<__IsPODType<T>()>
|
static typename std::enable_if_t<__IsPODType_v<T>>
|
||||||
Do(const PropId& id, T& var, StreamT& w)
|
Do(const PropId& id, T& var, StreamT& w)
|
||||||
{
|
{
|
||||||
using CastT = __CastPODType<T>;
|
using CastT = __CastPODType<T>;
|
||||||
WriteYaml<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), w);
|
WriteYaml<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), w);
|
||||||
}
|
}
|
||||||
template <class T, Endian DNAE>
|
template <class T, Endian DNAE>
|
||||||
static typename std::enable_if_t<__IsDNARecord<T>()>
|
static typename std::enable_if_t<__IsDNARecord_v<T>>
|
||||||
Do(const PropId& id, T& var, StreamT& w)
|
Do(const PropId& id, T& var, StreamT& w)
|
||||||
{
|
{
|
||||||
if (auto rec = w.enterSubRecord(id.name))
|
if (auto rec = w.enterSubRecord(id.name))
|
||||||
|
|
|
@ -12,14 +12,14 @@ namespace athena::io
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static inline const char* __GetDNAName(const T& dna,
|
static inline const char* __GetDNAName(const T& dna,
|
||||||
typename std::enable_if_t<athena::io::__IsDNAVRecord<T>()>* = 0)
|
typename std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = 0)
|
||||||
{
|
{
|
||||||
return dna.DNATypeV();
|
return dna.DNATypeV();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static inline const char* __GetDNAName(const T& dna,
|
static inline const char* __GetDNAName(const T& dna,
|
||||||
typename std::enable_if_t<!athena::io::__IsDNAVRecord<T>()>* = 0)
|
typename std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = 0)
|
||||||
{
|
{
|
||||||
return dna.DNAType();
|
return dna.DNAType();
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,17 +146,16 @@ template <Endian DNAE>
|
||||||
struct DNAV;
|
struct DNAV;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static inline constexpr bool __IsDNARecord()
|
using __IsDNARecord = typename std::disjunction<std::is_base_of<DNA<Endian::Big>, T>,
|
||||||
{
|
std::is_base_of<DNA<Endian::Little>, T>>;
|
||||||
return std::is_base_of_v<DNA<Endian::Big>, T> ||
|
|
||||||
std::is_base_of_v<DNA<Endian::Little>, T>;
|
|
||||||
}
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static inline constexpr bool __IsDNAVRecord()
|
inline constexpr bool __IsDNARecord_v = __IsDNARecord<T>::value;
|
||||||
{
|
|
||||||
return std::is_base_of_v<DNAV<Endian::Big>, T> ||
|
template <class T>
|
||||||
std::is_base_of_v<DNAV<Endian::Little>, T>;
|
using __IsDNAVRecord = typename std::disjunction<std::is_base_of<DNAV<Endian::Big>, T>,
|
||||||
}
|
std::is_base_of<DNAV<Endian::Little>, T>>;
|
||||||
|
template <class T>
|
||||||
|
inline constexpr bool __IsDNAVRecord_v = __IsDNAVRecord<T>::value;
|
||||||
}
|
}
|
||||||
} // Athena
|
} // Athena
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include <yaml.h>
|
#include <yaml.h>
|
||||||
#include <utf8proc.h>
|
#include <utf8proc.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
#include <functional>
|
||||||
#include "Global.hpp"
|
#include "Global.hpp"
|
||||||
|
|
||||||
namespace athena::io
|
namespace athena::io
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void enumerate(const char* name, T& record,
|
void enumerate(const char* name, T& record,
|
||||||
typename std::enable_if_t<__IsDNARecord<T>()>* = 0)
|
typename std::enable_if_t<__IsDNARecord_v<T>>* = 0)
|
||||||
{
|
{
|
||||||
if (auto rec = enterSubRecord(name))
|
if (auto rec = enterSubRecord(name))
|
||||||
record.read(*this);
|
record.read(*this);
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void enumerate(const char* name, T& record,
|
void enumerate(const char* name, T& record,
|
||||||
typename std::enable_if_t<__IsDNARecord<T>()>* = 0)
|
typename std::enable_if_t<__IsDNARecord_v<T>>* = 0)
|
||||||
{
|
{
|
||||||
if (auto rec = enterSubRecord(name))
|
if (auto rec = enterSubRecord(name))
|
||||||
record.write(*this);
|
record.write(*this);
|
||||||
|
|
Loading…
Reference in New Issue