mirror of https://github.com/libAthena/athena.git
Numerous code style improvements
This commit is contained in:
parent
132c7def65
commit
c7b6744509
|
@ -91,9 +91,9 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
bool hasWrite = false;
|
bool hasWrite = false;
|
||||||
for (const clang::CXXMethodDecl* method : rDecl->methods()) {
|
for (const clang::CXXMethodDecl* method : rDecl->methods()) {
|
||||||
std::string compName = method->getDeclName().getAsString();
|
std::string compName = method->getDeclName().getAsString();
|
||||||
if (!compName.compare("read"))
|
if (compName == "read")
|
||||||
hasRead = true;
|
hasRead = true;
|
||||||
else if (!compName.compare("write"))
|
else if (compName == "write")
|
||||||
hasWrite = true;
|
hasWrite = true;
|
||||||
}
|
}
|
||||||
if (hasRead && hasWrite) {
|
if (hasRead && hasWrite) {
|
||||||
|
@ -130,7 +130,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
} else if (theType->isRecordType()) {
|
} else if (theType->isRecordType()) {
|
||||||
const clang::CXXRecordDecl* rDecl = theType->getAsCXXRecordDecl();
|
const clang::CXXRecordDecl* rDecl = theType->getAsCXXRecordDecl();
|
||||||
for (const clang::FieldDecl* field : rDecl->fields()) {
|
for (const clang::FieldDecl* field : rDecl->fields()) {
|
||||||
if (!field->getName().compare("clangVec")) {
|
if (field->getName() == "clangVec") {
|
||||||
const auto* vType = static_cast<const clang::VectorType*>(field->getType().getTypePtr());
|
const auto* vType = static_cast<const clang::VectorType*>(field->getType().getTypePtr());
|
||||||
if (vType->isVectorType()) {
|
if (vType->isVectorType()) {
|
||||||
const auto* eType = static_cast<const clang::BuiltinType*>(vType->getElementType().getTypePtr());
|
const auto* eType = static_cast<const clang::BuiltinType*>(vType->getElementType().getTypePtr());
|
||||||
|
@ -164,7 +164,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
|
|
||||||
static std::string GetPropIdExpr(const clang::FieldDecl* field, const std::string& fieldName) {
|
static std::string GetPropIdExpr(const clang::FieldDecl* field, const std::string& fieldName) {
|
||||||
std::string fieldStr = GetFieldString(fieldName);
|
std::string fieldStr = GetFieldString(fieldName);
|
||||||
std::string propIdExpr = "\"" + fieldStr + "\"";
|
std::string propIdExpr = "\"" + fieldStr + "\"sv";
|
||||||
for (clang::Attr* attr : field->attrs()) {
|
for (clang::Attr* attr : field->attrs()) {
|
||||||
if (clang::AnnotateAttr* annot = clang::dyn_cast_or_null<clang::AnnotateAttr>(attr)) {
|
if (clang::AnnotateAttr* annot = clang::dyn_cast_or_null<clang::AnnotateAttr>(attr)) {
|
||||||
llvm::StringRef textRef = annot->getAnnotation();
|
llvm::StringRef textRef = annot->getAnnotation();
|
||||||
|
@ -172,7 +172,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
unsigned long num = strtoul(textRef.data() + 7, nullptr, 16);
|
unsigned long num = strtoul(textRef.data() + 7, nullptr, 16);
|
||||||
std::string tmpS;
|
std::string tmpS;
|
||||||
llvm::raw_string_ostream s(tmpS);
|
llvm::raw_string_ostream s(tmpS);
|
||||||
s << llvm::format("\"%s\", 0x%08X", fieldStr.c_str(), num);
|
s << llvm::format("\"%s\"sv, 0x%08X", fieldStr.c_str(), num);
|
||||||
propIdExpr = s.str();
|
propIdExpr = s.str();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
const clang::TemplateDecl* tsDecl = tsType->getTemplateName().getAsTemplateDecl();
|
const clang::TemplateDecl* tsDecl = tsType->getTemplateName().getAsTemplateDecl();
|
||||||
const clang::TemplateParameterList* classParms = tsDecl->getTemplateParameters();
|
const clang::TemplateParameterList* classParms = tsDecl->getTemplateParameters();
|
||||||
|
|
||||||
if (!tsDecl->getName().compare("Value")) {
|
if (tsDecl->getName() == "Value") {
|
||||||
llvm::APSInt endian(64, -1);
|
llvm::APSInt endian(64, -1);
|
||||||
std::string endianExprStr;
|
std::string endianExprStr;
|
||||||
bool defaultEndian = true;
|
bool defaultEndian = true;
|
||||||
|
@ -407,7 +407,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
}
|
}
|
||||||
|
|
||||||
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
||||||
} else if (!tsDecl->getName().compare("Vector")) {
|
} else if (tsDecl->getName() == "Vector") {
|
||||||
llvm::APSInt endian(64, -1);
|
llvm::APSInt endian(64, -1);
|
||||||
std::string endianExprStr;
|
std::string endianExprStr;
|
||||||
bool defaultEndian = true;
|
bool defaultEndian = true;
|
||||||
|
@ -483,7 +483,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
}
|
}
|
||||||
|
|
||||||
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
||||||
} else if (!tsDecl->getName().compare("Buffer")) {
|
} else if (tsDecl->getName() == "Buffer") {
|
||||||
const clang::Expr* sizeExpr = nullptr;
|
const clang::Expr* sizeExpr = nullptr;
|
||||||
std::string sizeExprStr;
|
std::string sizeExprStr;
|
||||||
for (const clang::TemplateArgument& arg : *tsType) {
|
for (const clang::TemplateArgument& arg : *tsType) {
|
||||||
|
@ -516,7 +516,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
std::string ioOp = GetVectorOpString(fieldName, propIdExpr, sizeExprStr);
|
std::string ioOp = GetVectorOpString(fieldName, propIdExpr, sizeExprStr);
|
||||||
|
|
||||||
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
||||||
} else if (!tsDecl->getName().compare("String")) {
|
} else if (tsDecl->getName() == "String") {
|
||||||
std::string sizeExprStr;
|
std::string sizeExprStr;
|
||||||
for (const clang::TemplateArgument& arg : *tsType) {
|
for (const clang::TemplateArgument& arg : *tsType) {
|
||||||
if (arg.getKind() == clang::TemplateArgument::Expression) {
|
if (arg.getKind() == clang::TemplateArgument::Expression) {
|
||||||
|
@ -543,7 +543,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
ioOp = GetOpString(fieldName, propIdExpr);
|
ioOp = GetOpString(fieldName, propIdExpr);
|
||||||
|
|
||||||
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
||||||
} else if (!tsDecl->getName().compare("WString")) {
|
} else if (tsDecl->getName() == "WString") {
|
||||||
llvm::APSInt endian(64, -1);
|
llvm::APSInt endian(64, -1);
|
||||||
std::string endianExprStr;
|
std::string endianExprStr;
|
||||||
bool defaultEndian = true;
|
bool defaultEndian = true;
|
||||||
|
@ -597,7 +597,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
}
|
}
|
||||||
|
|
||||||
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
outputNodes.emplace_back(NodeType::Do, fieldName, ioOp, false);
|
||||||
} else if (!tsDecl->getName().compare("Seek")) {
|
} else if (tsDecl->getName() == "Seek") {
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
std::string offsetExprStr;
|
std::string offsetExprStr;
|
||||||
llvm::APSInt direction(64, 0);
|
llvm::APSInt direction(64, 0);
|
||||||
|
@ -659,7 +659,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
else if (directionVal == 2)
|
else if (directionVal == 2)
|
||||||
outputNodes.emplace_back(NodeType::DoSeek, fieldName, "<Op>("s + offsetExprStr + ", athena::End, s)",
|
outputNodes.emplace_back(NodeType::DoSeek, fieldName, "<Op>("s + offsetExprStr + ", athena::End, s)",
|
||||||
false);
|
false);
|
||||||
} else if (!tsDecl->getName().compare("Align")) {
|
} else if (tsDecl->getName() == "Align") {
|
||||||
llvm::APSInt align(64, 0);
|
llvm::APSInt align(64, 0);
|
||||||
bool bad = false;
|
bool bad = false;
|
||||||
for (const clang::TemplateArgument& arg : *tsType) {
|
for (const clang::TemplateArgument& arg : *tsType) {
|
||||||
|
@ -758,7 +758,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
const clang::TemplateDecl* tsDecl = tsType->getTemplateName().getAsTemplateDecl();
|
const clang::TemplateDecl* tsDecl = tsType->getTemplateName().getAsTemplateDecl();
|
||||||
const clang::TemplateParameterList* classParms = tsDecl->getTemplateParameters();
|
const clang::TemplateParameterList* classParms = tsDecl->getTemplateParameters();
|
||||||
|
|
||||||
if (!tsDecl->getName().compare("Value")) {
|
if (tsDecl->getName() == "Value") {
|
||||||
llvm::APSInt endian(64, -1);
|
llvm::APSInt endian(64, -1);
|
||||||
std::string endianExprStr;
|
std::string endianExprStr;
|
||||||
bool defaultEndian = true;
|
bool defaultEndian = true;
|
||||||
|
@ -802,7 +802,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
<< " Do" << ioOp << ";\n"
|
<< " Do" << ioOp << ";\n"
|
||||||
<< " return true;\n";
|
<< " return true;\n";
|
||||||
|
|
||||||
} else if (!tsDecl->getName().compare("Vector")) {
|
} else if (tsDecl->getName() == "Vector") {
|
||||||
llvm::APSInt endian(64, -1);
|
llvm::APSInt endian(64, -1);
|
||||||
std::string endianExprStr;
|
std::string endianExprStr;
|
||||||
bool defaultEndian = true;
|
bool defaultEndian = true;
|
||||||
|
@ -869,7 +869,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
fileOut << " AT_PROP_CASE(" << propIdExpr << "):\n"
|
fileOut << " AT_PROP_CASE(" << propIdExpr << "):\n"
|
||||||
<< " Do" << ioOp << ";\n"
|
<< " Do" << ioOp << ";\n"
|
||||||
<< " return true;\n";
|
<< " return true;\n";
|
||||||
} else if (!tsDecl->getName().compare("Buffer")) {
|
} else if (tsDecl->getName() == "Buffer") {
|
||||||
const clang::Expr* sizeExpr = nullptr;
|
const clang::Expr* sizeExpr = nullptr;
|
||||||
std::string sizeExprStr;
|
std::string sizeExprStr;
|
||||||
for (const clang::TemplateArgument& arg : *tsType) {
|
for (const clang::TemplateArgument& arg : *tsType) {
|
||||||
|
@ -904,7 +904,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
fileOut << " AT_PROP_CASE(" << propIdExpr << "):\n"
|
fileOut << " AT_PROP_CASE(" << propIdExpr << "):\n"
|
||||||
<< " Do" << ioOp << ";\n"
|
<< " Do" << ioOp << ";\n"
|
||||||
<< " return true;\n";
|
<< " return true;\n";
|
||||||
} else if (!tsDecl->getName().compare("String")) {
|
} else if (tsDecl->getName() == "String") {
|
||||||
std::string sizeExprStr;
|
std::string sizeExprStr;
|
||||||
for (const clang::TemplateArgument& arg : *tsType) {
|
for (const clang::TemplateArgument& arg : *tsType) {
|
||||||
if (arg.getKind() == clang::TemplateArgument::Expression) {
|
if (arg.getKind() == clang::TemplateArgument::Expression) {
|
||||||
|
@ -933,7 +933,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
|
||||||
fileOut << " AT_PROP_CASE(" << propIdExpr << "):\n"
|
fileOut << " AT_PROP_CASE(" << propIdExpr << "):\n"
|
||||||
<< " Do" << ioOp << ";\n"
|
<< " Do" << ioOp << ";\n"
|
||||||
<< " return true;\n";
|
<< " return true;\n";
|
||||||
} else if (!tsDecl->getName().compare("WString")) {
|
} else if (tsDecl->getName() == "WString") {
|
||||||
llvm::APSInt endian(64, -1);
|
llvm::APSInt endian(64, -1);
|
||||||
std::string endianExprStr;
|
std::string endianExprStr;
|
||||||
bool defaultEndian = true;
|
bool defaultEndian = true;
|
||||||
|
@ -1038,8 +1038,7 @@ public:
|
||||||
bool isYamlDNA = false;
|
bool isYamlDNA = false;
|
||||||
for (const clang::CXXMethodDecl* method : decl->methods())
|
for (const clang::CXXMethodDecl* method : decl->methods())
|
||||||
if (method->getDeclName().isIdentifier() &&
|
if (method->getDeclName().isIdentifier() &&
|
||||||
(!method->getName().compare(llvm::StringLiteral("read")) ||
|
(method->getName() == "read" || method->getName() == "write") &&
|
||||||
!method->getName().compare(llvm::StringLiteral("write"))) &&
|
|
||||||
method->getNumParams() == 1 &&
|
method->getNumParams() == 1 &&
|
||||||
method->getParamDecl(0)->getType().getAsString() == "athena::io::YAMLDocReader &") {
|
method->getParamDecl(0)->getType().getAsString() == "athena::io::YAMLDocReader &") {
|
||||||
isYamlDNA = true;
|
isYamlDNA = true;
|
||||||
|
@ -1050,7 +1049,7 @@ public:
|
||||||
bool isPropDNA = false;
|
bool isPropDNA = false;
|
||||||
for (const clang::Decl* d : decl->decls())
|
for (const clang::Decl* d : decl->decls())
|
||||||
if (const clang::FunctionTemplateDecl* m = clang::dyn_cast_or_null<clang::FunctionTemplateDecl>(d))
|
if (const clang::FunctionTemplateDecl* m = clang::dyn_cast_or_null<clang::FunctionTemplateDecl>(d))
|
||||||
if (m->getDeclName().isIdentifier() && !m->getName().compare(llvm::StringLiteral("Lookup"))) {
|
if (m->getDeclName().isIdentifier() && m->getName() == "Lookup") {
|
||||||
isPropDNA = true;
|
isPropDNA = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1062,7 +1061,7 @@ public:
|
||||||
if (regType) {
|
if (regType) {
|
||||||
const clang::CXXRecordDecl* rDecl = regType->getAsCXXRecordDecl();
|
const clang::CXXRecordDecl* rDecl = regType->getAsCXXRecordDecl();
|
||||||
if (rDecl) {
|
if (rDecl) {
|
||||||
if (!rDecl->getName().compare("Delete")) {
|
if (rDecl->getName() == "Delete") {
|
||||||
const clang::CXXRecordDecl* rParentDecl = llvm::dyn_cast_or_null<clang::CXXRecordDecl>(rDecl->getParent());
|
const clang::CXXRecordDecl* rParentDecl = llvm::dyn_cast_or_null<clang::CXXRecordDecl>(rDecl->getParent());
|
||||||
if (rParentDecl) {
|
if (rParentDecl) {
|
||||||
std::string parentCheck = rParentDecl->getTypeForDecl()->getCanonicalTypeInternal().getAsString();
|
std::string parentCheck = rParentDecl->getTypeForDecl()->getCanonicalTypeInternal().getAsString();
|
||||||
|
@ -1093,8 +1092,8 @@ public:
|
||||||
for (const auto& specialization : specializations) {
|
for (const auto& specialization : specializations) {
|
||||||
for (int i = 0; i < specialization.second; ++i)
|
for (int i = 0; i < specialization.second; ++i)
|
||||||
fileOut << "template <>\n";
|
fileOut << "template <>\n";
|
||||||
fileOut << "const char* " << specialization.first << "::DNAType() {\n return \"" << specialization.first
|
fileOut << "std::string_view " << specialization.first << "::DNAType() {\n return \"" << specialization.first
|
||||||
<< "\";\n}\n";
|
<< "\"sv;\n}\n";
|
||||||
}
|
}
|
||||||
fileOut << "\n\n";
|
fileOut << "\n\n";
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include "athena/IStreamReader.hpp"
|
#include "athena/IStreamReader.hpp"
|
||||||
#include "athena/IStreamWriter.hpp"
|
#include "athena/IStreamWriter.hpp"
|
||||||
|
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
namespace athena::io {
|
namespace athena::io {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,7 +129,7 @@ struct DNAV : DNA<DNAE> {
|
||||||
virtual void read(athena::io::IStreamReader& r) = 0;
|
virtual void read(athena::io::IStreamReader& r) = 0;
|
||||||
virtual void write(athena::io::IStreamWriter& w) const = 0;
|
virtual void write(athena::io::IStreamWriter& w) const = 0;
|
||||||
virtual void binarySize(size_t& s) const = 0;
|
virtual void binarySize(size_t& s) const = 0;
|
||||||
virtual const char* DNATypeV() const = 0;
|
virtual std::string_view DNATypeV() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <Endian DNAE>
|
template <Endian DNAE>
|
||||||
|
|
|
@ -15,20 +15,20 @@
|
||||||
namespace athena::io {
|
namespace athena::io {
|
||||||
|
|
||||||
struct PropId {
|
struct PropId {
|
||||||
const char* name = nullptr;
|
std::string_view name;
|
||||||
uint32_t rcrc32 = 0xffffffff;
|
uint32_t rcrc32 = 0xffffffff;
|
||||||
uint64_t crc64 = 0x0;
|
uint64_t crc64 = 0x0;
|
||||||
template <class T>
|
template <class T>
|
||||||
constexpr T opget() const;
|
constexpr T opget() const;
|
||||||
constexpr PropId() = default;
|
constexpr PropId() = default;
|
||||||
constexpr explicit PropId(const char* name, uint32_t rcrc32, uint64_t crc64)
|
constexpr explicit PropId(std::string_view name, uint32_t rcrc32, uint64_t crc64)
|
||||||
: name(name), rcrc32(rcrc32), crc64(crc64) {}
|
: name(name), rcrc32(rcrc32), crc64(crc64) {}
|
||||||
constexpr explicit PropId(const char* name)
|
constexpr explicit PropId(std::string_view name)
|
||||||
: name(name)
|
: name(name)
|
||||||
, rcrc32(athena::checksums::literals::rcrc32_rec(0xFFFFFFFF, name))
|
, rcrc32(athena::checksums::literals::rcrc32_rec(0xFFFFFFFF, name.data()))
|
||||||
, crc64(athena::checksums::literals::crc64_rec(0xFFFFFFFFFFFFFFFF, name)) {}
|
, crc64(athena::checksums::literals::crc64_rec(0xFFFFFFFFFFFFFFFF, name.data())) {}
|
||||||
constexpr PropId(const char* name, uint32_t rcrc32)
|
constexpr PropId(std::string_view name, uint32_t rcrc32)
|
||||||
: name(name), rcrc32(rcrc32), crc64(athena::checksums::literals::crc64_rec(0xFFFFFFFFFFFFFFFF, name)) {}
|
: name(name), rcrc32(rcrc32), crc64(athena::checksums::literals::crc64_rec(0xFFFFFFFFFFFFFFFF, name.data())) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -628,7 +628,7 @@ struct ReadYaml {
|
||||||
if (auto __v = r.enterSubVector(id.name, _count)) {
|
if (auto __v = r.enterSubVector(id.name, _count)) {
|
||||||
vector.reserve(_count);
|
vector.reserve(_count);
|
||||||
for (size_t i = 0; i < _count; ++i)
|
for (size_t i = 0; i < _count; ++i)
|
||||||
vector.push_back(r.readBool(nullptr));
|
vector.push_back(r.readBool());
|
||||||
}
|
}
|
||||||
/* Horrible reference abuse (but it works) */
|
/* Horrible reference abuse (but it works) */
|
||||||
const_cast<S&>(count) = vector.size();
|
const_cast<S&>(count) = vector.size();
|
||||||
|
@ -733,7 +733,7 @@ struct WriteYaml {
|
||||||
/* libc++ specializes vector<bool> as a bitstream */
|
/* libc++ specializes vector<bool> as a bitstream */
|
||||||
if (auto __v = w.enterSubVector(id.name))
|
if (auto __v = w.enterSubVector(id.name))
|
||||||
for (const T& v : vector)
|
for (const T& v : vector)
|
||||||
w.writeBool(nullptr, v);
|
w.writeBool(v);
|
||||||
}
|
}
|
||||||
static void Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, StreamT& w) {
|
static void Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, StreamT& w) {
|
||||||
w.writeUBytes(id.name, buf, count);
|
w.writeUBytes(id.name, buf, count);
|
||||||
|
@ -944,7 +944,7 @@ void __BinarySizeProp64(const T& obj, size_t& s) {
|
||||||
} \
|
} \
|
||||||
template <class Op> \
|
template <class Op> \
|
||||||
void Enumerate(typename Op::StreamT& s); \
|
void Enumerate(typename Op::StreamT& s); \
|
||||||
static const char* DNAType();
|
static std::string_view DNAType();
|
||||||
|
|
||||||
#define AT_DECL_DNA \
|
#define AT_DECL_DNA \
|
||||||
AT_DECL_DNA_DO \
|
AT_DECL_DNA_DO \
|
||||||
|
@ -985,7 +985,7 @@ void __BinarySizeProp64(const T& obj, size_t& s) {
|
||||||
void read(athena::io::IStreamReader& r) override { athena::io::__Read(*this, r); } \
|
void read(athena::io::IStreamReader& r) override { athena::io::__Read(*this, r); } \
|
||||||
void write(athena::io::IStreamWriter& w) const override { athena::io::__Write(*this, w); } \
|
void write(athena::io::IStreamWriter& w) const override { athena::io::__Write(*this, w); } \
|
||||||
void binarySize(size_t& s) const override { athena::io::__BinarySize(*this, s); } \
|
void binarySize(size_t& s) const override { athena::io::__BinarySize(*this, s); } \
|
||||||
const char* DNATypeV() const override { return DNAType(); }
|
std::string_view DNATypeV() const override { return DNAType(); }
|
||||||
|
|
||||||
#define AT_DECL_DNAV_NO_TYPE \
|
#define AT_DECL_DNAV_NO_TYPE \
|
||||||
AT_DECL_DNA_DO \
|
AT_DECL_DNA_DO \
|
||||||
|
@ -1055,7 +1055,7 @@ void __BinarySizeProp64(const T& obj, size_t& s) {
|
||||||
void Enumerate(typename Op::StreamT& s); \
|
void Enumerate(typename Op::StreamT& s); \
|
||||||
template <class Op> \
|
template <class Op> \
|
||||||
bool Lookup(uint64_t hash, typename Op::StreamT& s); \
|
bool Lookup(uint64_t hash, typename Op::StreamT& s); \
|
||||||
static const char* DNAType(); \
|
static std::string_view DNAType(); \
|
||||||
void read(athena::io::IStreamReader& r) { athena::io::__Read(*this, r); } \
|
void read(athena::io::IStreamReader& r) { athena::io::__Read(*this, r); } \
|
||||||
void write(athena::io::IStreamWriter& w) const { athena::io::__Write(*this, w); } \
|
void write(athena::io::IStreamWriter& w) const { athena::io::__Write(*this, w); } \
|
||||||
void binarySize(size_t& s) const { athena::io::__BinarySize(*this, s); } \
|
void binarySize(size_t& s) const { athena::io::__BinarySize(*this, s); } \
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
namespace athena::io {
|
namespace athena::io {
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
const char* __GetDNAName(const T& dna, std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
|
inline std::string_view __GetDNAName(const T& dna, std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
|
||||||
return dna.DNATypeV();
|
return dna.DNATypeV();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
const char* __GetDNAName(const T& dna, std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
|
inline std::string_view __GetDNAName(const T& dna, std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
|
||||||
return dna.DNAType();
|
return dna.DNAType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,16 +27,16 @@ struct YAMLNode {
|
||||||
|
|
||||||
YAMLNode(yaml_node_type_t type) : m_type(type) {}
|
YAMLNode(yaml_node_type_t type) : m_type(type) {}
|
||||||
|
|
||||||
const YAMLNode* findMapChild(std::string_view key) const {
|
YAMLNode* findMapChild(std::string_view key) const {
|
||||||
for (const auto& item : m_mapChildren)
|
for (const auto& item : m_mapChildren)
|
||||||
if (!item.first.compare(key))
|
if (item.first == key)
|
||||||
return item.second.get();
|
return item.second.get();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void assignMapChild(std::string_view key, std::unique_ptr<YAMLNode>&& node) {
|
void assignMapChild(std::string_view key, std::unique_ptr<YAMLNode>&& node) {
|
||||||
for (auto& item : m_mapChildren)
|
for (auto& item : m_mapChildren)
|
||||||
if (!item.first.compare(key)) {
|
if (item.first == key) {
|
||||||
item.second = std::move(node);
|
item.second = std::move(node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ public:
|
||||||
|
|
||||||
bool parse(athena::io::IStreamReader* reader);
|
bool parse(athena::io::IStreamReader* reader);
|
||||||
|
|
||||||
bool ClassTypeOperation(std::function<bool(const char* dnaType)> func);
|
bool ClassTypeOperation(std::function<bool(std::string_view dnaType)> func);
|
||||||
bool ValidateClassType(const char* expectedType);
|
bool ValidateClassType(std::string_view expectedType);
|
||||||
|
|
||||||
const YAMLNode* getRootNode() const { return m_rootNode.get(); }
|
const YAMLNode* getRootNode() const { return m_rootNode.get(); }
|
||||||
const YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
|
const YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
|
||||||
|
@ -59,10 +59,10 @@ public:
|
||||||
};
|
};
|
||||||
friend class RecordRAII;
|
friend class RecordRAII;
|
||||||
|
|
||||||
RecordRAII enterSubRecord(const char* name);
|
RecordRAII enterSubRecord(std::string_view name = {});
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void enumerate(const char* name, T& record, std::enable_if_t<__IsDNARecord_v<T>>* = nullptr) {
|
void enumerate(std::string_view name, T& record, std::enable_if_t<__IsDNARecord_v<T>>* = nullptr) {
|
||||||
if (auto rec = enterSubRecord(name))
|
if (auto rec = enterSubRecord(name))
|
||||||
record.read(*this);
|
record.read(*this);
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,11 @@ public:
|
||||||
};
|
};
|
||||||
friend class VectorRAII;
|
friend class VectorRAII;
|
||||||
|
|
||||||
VectorRAII enterSubVector(const char* name, size_t& countOut);
|
VectorRAII enterSubVector(std::string_view name, size_t& countOut);
|
||||||
|
VectorRAII enterSubVector(size_t& countOut) { return enterSubVector({}, countOut); }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
size_t enumerate(const char* name, std::vector<T>& vector,
|
size_t enumerate(std::string_view name, std::vector<T>& vector,
|
||||||
std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_same_v<T, atVec2f> &&
|
std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_same_v<T, atVec2f> &&
|
||||||
!std::is_same_v<T, atVec3f> && !std::is_same_v<T, atVec4f>>* = nullptr) {
|
!std::is_same_v<T, atVec3f> && !std::is_same_v<T, atVec4f>>* = nullptr) {
|
||||||
size_t countOut;
|
size_t countOut;
|
||||||
|
@ -94,7 +95,7 @@ public:
|
||||||
vector.reserve(countOut);
|
vector.reserve(countOut);
|
||||||
for (size_t i = 0; i < countOut; ++i) {
|
for (size_t i = 0; i < countOut; ++i) {
|
||||||
vector.emplace_back();
|
vector.emplace_back();
|
||||||
if (auto rec = enterSubRecord(nullptr))
|
if (auto rec = enterSubRecord())
|
||||||
vector.back().read(*this);
|
vector.back().read(*this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +103,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
size_t enumerate(const char* name, std::vector<T>& vector,
|
size_t enumerate(std::string_view name, std::vector<T>& vector,
|
||||||
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> ||
|
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> ||
|
||||||
std::is_same_v<T, atVec3f> || std::is_same_v<T, atVec4f>>* = nullptr) {
|
std::is_same_v<T, atVec3f> || std::is_same_v<T, atVec4f>>* = nullptr) {
|
||||||
size_t countOut;
|
size_t countOut;
|
||||||
|
@ -116,53 +117,53 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
size_t enumerate(const char* name, std::vector<T>& vector, std::function<void(YAMLDocReader&, T&)> readf) {
|
size_t enumerate(std::string_view name, std::vector<T>& vector, std::function<void(YAMLDocReader&, T&)> readf) {
|
||||||
size_t countOut;
|
size_t countOut;
|
||||||
if (auto v = enterSubVector(name, countOut)) {
|
if (auto v = enterSubVector(name, countOut)) {
|
||||||
vector.clear();
|
vector.clear();
|
||||||
vector.reserve(countOut);
|
vector.reserve(countOut);
|
||||||
for (size_t i = 0; i < countOut; ++i) {
|
for (size_t i = 0; i < countOut; ++i) {
|
||||||
vector.emplace_back();
|
vector.emplace_back();
|
||||||
if (auto rec = enterSubRecord(nullptr))
|
if (auto rec = enterSubRecord())
|
||||||
readf(*this, vector.back());
|
readf(*this, vector.back());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return countOut;
|
return countOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasVal(const char* name) const {
|
bool hasVal(std::string_view name) const {
|
||||||
if (m_subStack.size()) {
|
if (m_subStack.size()) {
|
||||||
const YAMLNode* mnode = m_subStack.back();
|
const YAMLNode* mnode = m_subStack.back();
|
||||||
if (mnode->m_type == YAML_MAPPING_NODE && name)
|
if (mnode->m_type == YAML_MAPPING_NODE && !name.empty())
|
||||||
for (const auto& item : mnode->m_mapChildren)
|
for (const auto& item : mnode->m_mapChildren)
|
||||||
if (!item.first.compare(name))
|
if (item.first == name)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename RETURNTYPE>
|
template <typename RETURNTYPE>
|
||||||
RETURNTYPE readVal(const char* name);
|
RETURNTYPE readVal(std::string_view name = {});
|
||||||
bool readBool(const char* name);
|
bool readBool(std::string_view name = {});
|
||||||
atInt8 readByte(const char* name);
|
atInt8 readByte(std::string_view name = {});
|
||||||
atUint8 readUByte(const char* name);
|
atUint8 readUByte(std::string_view name = {});
|
||||||
atInt16 readInt16(const char* name);
|
atInt16 readInt16(std::string_view name = {});
|
||||||
atUint16 readUint16(const char* name);
|
atUint16 readUint16(std::string_view name = {});
|
||||||
atInt32 readInt32(const char* name);
|
atInt32 readInt32(std::string_view name = {});
|
||||||
atUint32 readUint32(const char* name);
|
atUint32 readUint32(std::string_view name = {});
|
||||||
atInt64 readInt64(const char* name);
|
atInt64 readInt64(std::string_view name = {});
|
||||||
atUint64 readUint64(const char* name);
|
atUint64 readUint64(std::string_view name = {});
|
||||||
float readFloat(const char* name);
|
float readFloat(std::string_view name = {});
|
||||||
double readDouble(const char* name);
|
double readDouble(std::string_view name = {});
|
||||||
atVec2f readVec2f(const char* name);
|
atVec2f readVec2f(std::string_view name = {});
|
||||||
atVec3f readVec3f(const char* name);
|
atVec3f readVec3f(std::string_view name = {});
|
||||||
atVec4f readVec4f(const char* name);
|
atVec4f readVec4f(std::string_view name = {});
|
||||||
atVec2d readVec2d(const char* name);
|
atVec2d readVec2d(std::string_view name = {});
|
||||||
atVec3d readVec3d(const char* name);
|
atVec3d readVec3d(std::string_view name = {});
|
||||||
atVec4d readVec4d(const char* name);
|
atVec4d readVec4d(std::string_view name = {});
|
||||||
std::unique_ptr<atUint8[]> readUBytes(const char* name);
|
std::unique_ptr<atUint8[]> readUBytes(std::string_view name = {});
|
||||||
std::string readString(const char* name);
|
std::string readString(std::string_view name = {});
|
||||||
std::wstring readWString(const char* name);
|
std::wstring readWString(std::string_view name = {});
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace athena::io
|
} // namespace athena::io
|
||||||
|
|
|
@ -20,7 +20,8 @@ class YAMLDocWriter {
|
||||||
void _leaveSubVector();
|
void _leaveSubVector();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader = nullptr);
|
explicit YAMLDocWriter(std::string_view classType, athena::io::IStreamReader* reader = nullptr);
|
||||||
|
explicit YAMLDocWriter(athena::io::IStreamReader* reader = nullptr) : YAMLDocWriter({}, reader) {}
|
||||||
~YAMLDocWriter();
|
~YAMLDocWriter();
|
||||||
|
|
||||||
yaml_emitter_t* getEmitter() { return &m_emitter; }
|
yaml_emitter_t* getEmitter() { return &m_emitter; }
|
||||||
|
@ -44,10 +45,10 @@ public:
|
||||||
};
|
};
|
||||||
friend class RecordRAII;
|
friend class RecordRAII;
|
||||||
|
|
||||||
RecordRAII enterSubRecord(const char* name);
|
RecordRAII enterSubRecord(std::string_view name = {});
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void enumerate(const char* name, T& record, std::enable_if_t<__IsDNARecord_v<T>>* = nullptr) {
|
void enumerate(std::string_view name, T& record, std::enable_if_t<__IsDNARecord_v<T>>* = nullptr) {
|
||||||
if (auto rec = enterSubRecord(name))
|
if (auto rec = enterSubRecord(name))
|
||||||
record.write(*this);
|
record.write(*this);
|
||||||
}
|
}
|
||||||
|
@ -67,64 +68,90 @@ public:
|
||||||
};
|
};
|
||||||
friend class VectorRAII;
|
friend class VectorRAII;
|
||||||
|
|
||||||
VectorRAII enterSubVector(const char* name);
|
VectorRAII enterSubVector(std::string_view name = {});
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
enumerate(const char* name, const std::vector<T>& vector,
|
enumerate(std::string_view name, const std::vector<T>& vector,
|
||||||
std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_same_v<T, atVec2f> && !std::is_same_v<T, atVec3f> &&
|
std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_same_v<T, atVec2f> && !std::is_same_v<T, atVec3f> &&
|
||||||
!std::is_same_v<T, atVec4f> && !std::is_same_v<T, atVec2d> &&
|
!std::is_same_v<T, atVec4f> && !std::is_same_v<T, atVec2d> &&
|
||||||
!std::is_same_v<T, atVec3d> && !std::is_same_v<T, atVec4d>>* = nullptr) {
|
!std::is_same_v<T, atVec3d> && !std::is_same_v<T, atVec4d>>* = nullptr) {
|
||||||
if (auto v = enterSubVector(name))
|
if (auto v = enterSubVector(name))
|
||||||
for (const T& item : vector)
|
for (const T& item : vector)
|
||||||
if (auto rec = enterSubRecord(nullptr))
|
if (auto rec = enterSubRecord())
|
||||||
item.write(*this);
|
item.write(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void enumerate(const char* name, const std::vector<T>& vector,
|
void enumerate(std::string_view name, const std::vector<T>& vector,
|
||||||
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> || std::is_same_v<T, atVec3f> ||
|
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> || std::is_same_v<T, atVec3f> ||
|
||||||
std::is_same_v<T, atVec4f> || std::is_same_v<T, atVec2d> ||
|
std::is_same_v<T, atVec4f> || std::is_same_v<T, atVec2d> ||
|
||||||
std::is_same_v<T, atVec3d> || std::is_same_v<T, atVec4d>>* = nullptr) {
|
std::is_same_v<T, atVec3d> || std::is_same_v<T, atVec4d>>* = nullptr) {
|
||||||
if (auto v = enterSubVector(name))
|
if (auto v = enterSubVector(name))
|
||||||
for (T item : vector)
|
for (T item : vector)
|
||||||
writeVal<T>(nullptr, item);
|
writeVal<T>(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void enumerate(const char* name, const std::vector<T>& vector, std::function<void(YAMLDocWriter&, const T&)> writef) {
|
void enumerate(std::string_view name, const std::vector<T>& vector, std::function<void(YAMLDocWriter&, const T&)> writef) {
|
||||||
if (auto v = enterSubVector(name))
|
if (auto v = enterSubVector(name))
|
||||||
for (const T& item : vector)
|
for (const T& item : vector)
|
||||||
if (auto rec = enterSubRecord(nullptr))
|
if (auto rec = enterSubRecord())
|
||||||
writef(*this, item);
|
writef(*this, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename INTYPE>
|
template <typename INTYPE>
|
||||||
void writeVal(const char* name, const INTYPE& val);
|
void writeVal(std::string_view name, const INTYPE& val);
|
||||||
template <typename INTYPE>
|
template <typename INTYPE>
|
||||||
void writeVal(const char* name, const INTYPE& val, size_t byteCount);
|
void writeVal(const INTYPE& val) { writeVal<INTYPE>(std::string_view{}, val); }
|
||||||
void writeBool(const char* name, const bool& val);
|
template <typename INTYPE>
|
||||||
void writeByte(const char* name, const atInt8& val);
|
void writeVal(std::string_view name, const INTYPE& val, size_t byteCount);
|
||||||
void writeUByte(const char* name, const atUint8& val);
|
template <typename INTYPE>
|
||||||
void writeInt16(const char* name, const atInt16& val);
|
void writeVal(const INTYPE& val, size_t byteCount) { writeVal<INTYPE>(std::string_view{}, val, byteCount); }
|
||||||
void writeUint16(const char* name, const atUint16& val);
|
void writeBool(std::string_view name, const bool& val);
|
||||||
void writeInt32(const char* name, const atInt32& val);
|
void writeBool(const bool& val) { writeBool({}, val); }
|
||||||
void writeUint32(const char* name, const atUint32& val);
|
void writeByte(std::string_view name, const atInt8& val);
|
||||||
void writeInt64(const char* name, const atInt64& val);
|
void writeByte(const atInt8& val) { writeByte({}, val); }
|
||||||
void writeUint64(const char* name, const atUint64& val);
|
void writeUByte(std::string_view name, const atUint8& val);
|
||||||
void writeFloat(const char* name, const float& val);
|
void writeUByte(const atUint8& val) { writeUByte({}, val); }
|
||||||
void writeDouble(const char* name, const double& val);
|
void writeInt16(std::string_view name, const atInt16& val);
|
||||||
void writeVec2f(const char* name, const atVec2f& val);
|
void writeInt16(const atInt16& val) { writeInt16({}, val); }
|
||||||
void writeVec3f(const char* name, const atVec3f& val);
|
void writeUint16(std::string_view name, const atUint16& val);
|
||||||
void writeVec4f(const char* name, const atVec4f& val);
|
void writeUint16(const atUint16& val) { writeUint16({}, val); }
|
||||||
void writeVec2d(const char* name, const atVec2d& val);
|
void writeInt32(std::string_view name, const atInt32& val);
|
||||||
void writeVec3d(const char* name, const atVec3d& val);
|
void writeInt32(const atInt32& val) { writeInt32({}, val); }
|
||||||
void writeVec4d(const char* name, const atVec4d& val);
|
void writeUint32(std::string_view name, const atUint32& val);
|
||||||
void writeUBytes(const char* name, const std::unique_ptr<atUint8[]>& val, size_t byteCount);
|
void writeUint32(const atUint32& val) { writeUint32({}, val); }
|
||||||
void writeString(const char* name, std::string_view val);
|
void writeInt64(std::string_view name, const atInt64& val);
|
||||||
void writeWString(const char* name, std::wstring_view val);
|
void writeInt64(const atInt64& val) { writeInt64({}, val); }
|
||||||
void writeU16String(const char* name, std::u16string_view val);
|
void writeUint64(std::string_view name, const atUint64& val);
|
||||||
void writeU32String(const char* name, std::u32string_view val);
|
void writeUint64(const atUint64& val) { writeUint64({}, val); }
|
||||||
|
void writeFloat(std::string_view name, const float& val);
|
||||||
|
void writeFloat(const float& val) { writeFloat({}, val); }
|
||||||
|
void writeDouble(std::string_view name, const double& val);
|
||||||
|
void writeDouble(const double& val) { writeDouble({}, val); }
|
||||||
|
void writeVec2f(std::string_view name, const atVec2f& val);
|
||||||
|
void writeVec2f(const atVec2f& val) { writeVec2f({}, val); }
|
||||||
|
void writeVec3f(std::string_view name, const atVec3f& val);
|
||||||
|
void writeVec3f(const atVec3f& val) { writeVec3f({}, val); }
|
||||||
|
void writeVec4f(std::string_view name, const atVec4f& val);
|
||||||
|
void writeVec4f(const atVec4f& val) { writeVec4f({}, val); }
|
||||||
|
void writeVec2d(std::string_view name, const atVec2d& val);
|
||||||
|
void writeVec2d(const atVec2d& val) { writeVec2d({}, val); }
|
||||||
|
void writeVec3d(std::string_view name, const atVec3d& val);
|
||||||
|
void writeVec3d(const atVec3d& val) { writeVec3d({}, val); }
|
||||||
|
void writeVec4d(std::string_view name, const atVec4d& val);
|
||||||
|
void writeVec4d(const atVec4d& val) { writeVec4d({}, val); }
|
||||||
|
void writeUBytes(std::string_view name, const std::unique_ptr<atUint8[]>& val, size_t byteCount);
|
||||||
|
void writeUBytes(const std::unique_ptr<atUint8[]>& val, size_t byteCount) { writeUBytes({}, val, byteCount); }
|
||||||
|
void writeString(std::string_view name, std::string_view val);
|
||||||
|
void writeString(std::string_view val) { writeString({}, val); }
|
||||||
|
void writeWString(std::string_view name, std::wstring_view val);
|
||||||
|
void writeWString(std::wstring_view val) { writeWString({}, val); }
|
||||||
|
void writeU16String(std::string_view name, std::u16string_view val);
|
||||||
|
void writeU16String(std::u16string_view val) { writeU16String({}, val); }
|
||||||
|
void writeU32String(std::string_view name, std::u32string_view val);
|
||||||
|
void writeU32String(std::u32string_view val) { writeU32String({}, val); }
|
||||||
|
|
||||||
void setStyle(YAMLNodeStyle s);
|
void setStyle(YAMLNodeStyle s);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "athena/YAMLCommon.hpp"
|
#include "athena/YAMLCommon.hpp"
|
||||||
|
|
||||||
namespace athena::io {
|
namespace athena::io {
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
bool NodeToVal(const YAMLNode* node) {
|
bool NodeToVal(const YAMLNode* node) {
|
||||||
|
@ -344,26 +345,26 @@ std::unique_ptr<YAMLNode> ValToNode(std::u32string_view val) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* ErrorString(yaml_error_type_t errt) {
|
static std::string_view ErrorString(yaml_error_type_t errt) {
|
||||||
switch (errt) {
|
switch (errt) {
|
||||||
case YAML_NO_ERROR:
|
case YAML_NO_ERROR:
|
||||||
return "No Error";
|
return "No Error"sv;
|
||||||
case YAML_MEMORY_ERROR:
|
case YAML_MEMORY_ERROR:
|
||||||
return "Memory Error";
|
return "Memory Error"sv;
|
||||||
case YAML_READER_ERROR:
|
case YAML_READER_ERROR:
|
||||||
return "Reader Error";
|
return "Reader Error"sv;
|
||||||
case YAML_SCANNER_ERROR:
|
case YAML_SCANNER_ERROR:
|
||||||
return "Scanner Error";
|
return "Scanner Error"sv;
|
||||||
case YAML_PARSER_ERROR:
|
case YAML_PARSER_ERROR:
|
||||||
return "Parser Error";
|
return "Parser Error"sv;
|
||||||
case YAML_COMPOSER_ERROR:
|
case YAML_COMPOSER_ERROR:
|
||||||
return "Composer Error";
|
return "Composer Error"sv;
|
||||||
case YAML_WRITER_ERROR:
|
case YAML_WRITER_ERROR:
|
||||||
return "Writer Error";
|
return "Writer Error"sv;
|
||||||
case YAML_EMITTER_ERROR:
|
case YAML_EMITTER_ERROR:
|
||||||
return "Emitter Error";
|
return "Emitter Error"sv;
|
||||||
}
|
}
|
||||||
return "Unknown Error";
|
return "Unknown Error"sv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleYAMLParserError(yaml_parser_t* parser) {
|
void HandleYAMLParserError(yaml_parser_t* parser) {
|
||||||
|
@ -403,7 +404,7 @@ int YAMLAthenaWriter(athena::io::IStreamWriter* writer, unsigned char* buffer, s
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
YAMLDocWriter::YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader) {
|
YAMLDocWriter::YAMLDocWriter(std::string_view classType, athena::io::IStreamReader* reader) {
|
||||||
if (!yaml_emitter_initialize(&m_emitter)) {
|
if (!yaml_emitter_initialize(&m_emitter)) {
|
||||||
HandleYAMLEmitterError(&m_emitter);
|
HandleYAMLEmitterError(&m_emitter);
|
||||||
return;
|
return;
|
||||||
|
@ -422,7 +423,7 @@ YAMLDocWriter::YAMLDocWriter(const char* classType, athena::io::IStreamReader* r
|
||||||
}
|
}
|
||||||
|
|
||||||
m_subStack.emplace_back(m_rootNode.get());
|
m_subStack.emplace_back(m_rootNode.get());
|
||||||
if (classType) {
|
if (!classType.empty()) {
|
||||||
auto classVal = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
|
auto classVal = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
|
||||||
classVal->m_scalarString.assign(classType);
|
classVal->m_scalarString.assign(classType);
|
||||||
m_rootNode->assignMapChild("DNAType", std::move(classVal));
|
m_rootNode->assignMapChild("DNAType", std::move(classVal));
|
||||||
|
@ -467,13 +468,13 @@ bool YAMLDocWriter::finish(athena::io::IStreamWriter* fout) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
YAMLDocWriter::RecordRAII YAMLDocWriter::enterSubRecord(const char* name) {
|
YAMLDocWriter::RecordRAII YAMLDocWriter::enterSubRecord(std::string_view name) {
|
||||||
YAMLNode* curSub = m_subStack.back();
|
YAMLNode* curSub = m_subStack.back();
|
||||||
if (curSub->m_type != YAML_MAPPING_NODE && curSub->m_type != YAML_SEQUENCE_NODE)
|
if (curSub->m_type != YAML_MAPPING_NODE && curSub->m_type != YAML_SEQUENCE_NODE)
|
||||||
return {};
|
return {};
|
||||||
YAMLNode* newNode = new YAMLNode(YAML_MAPPING_NODE);
|
YAMLNode* newNode = new YAMLNode(YAML_MAPPING_NODE);
|
||||||
if (curSub->m_type == YAML_MAPPING_NODE)
|
if (curSub->m_type == YAML_MAPPING_NODE)
|
||||||
curSub->assignMapChild(name ? name : std::string_view{}, std::unique_ptr<YAMLNode>(newNode));
|
curSub->assignMapChild(!name.empty() ? name : std::string_view{}, std::unique_ptr<YAMLNode>(newNode));
|
||||||
else if (curSub->m_type == YAML_SEQUENCE_NODE)
|
else if (curSub->m_type == YAML_SEQUENCE_NODE)
|
||||||
curSub->m_seqChildren.emplace_back(newNode);
|
curSub->m_seqChildren.emplace_back(newNode);
|
||||||
m_subStack.push_back(newNode);
|
m_subStack.push_back(newNode);
|
||||||
|
@ -502,13 +503,13 @@ void YAMLDocWriter::_leaveSubRecord() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YAMLDocWriter::VectorRAII YAMLDocWriter::enterSubVector(const char* name) {
|
YAMLDocWriter::VectorRAII YAMLDocWriter::enterSubVector(std::string_view name) {
|
||||||
YAMLNode* curSub = m_subStack.back();
|
YAMLNode* curSub = m_subStack.back();
|
||||||
if (curSub->m_type != YAML_MAPPING_NODE && curSub->m_type != YAML_SEQUENCE_NODE)
|
if (curSub->m_type != YAML_MAPPING_NODE && curSub->m_type != YAML_SEQUENCE_NODE)
|
||||||
return {};
|
return {};
|
||||||
YAMLNode* newNode = new YAMLNode(YAML_SEQUENCE_NODE);
|
YAMLNode* newNode = new YAMLNode(YAML_SEQUENCE_NODE);
|
||||||
if (curSub->m_type == YAML_MAPPING_NODE)
|
if (curSub->m_type == YAML_MAPPING_NODE)
|
||||||
curSub->assignMapChild(name ? name : std::string_view{}, std::unique_ptr<YAMLNode>(newNode));
|
curSub->assignMapChild(!name.empty() ? name : std::string_view{}, std::unique_ptr<YAMLNode>(newNode));
|
||||||
else if (curSub->m_type == YAML_SEQUENCE_NODE)
|
else if (curSub->m_type == YAML_SEQUENCE_NODE)
|
||||||
curSub->m_seqChildren.emplace_back(newNode);
|
curSub->m_seqChildren.emplace_back(newNode);
|
||||||
m_subStack.push_back(newNode);
|
m_subStack.push_back(newNode);
|
||||||
|
@ -521,82 +522,82 @@ void YAMLDocWriter::_leaveSubVector() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename INTYPE>
|
template <typename INTYPE>
|
||||||
void YAMLDocWriter::writeVal(const char* name, const INTYPE& val) {
|
void YAMLDocWriter::writeVal(std::string_view name, const INTYPE& val) {
|
||||||
YAMLNode* curSub = m_subStack.back();
|
YAMLNode* curSub = m_subStack.back();
|
||||||
if (curSub->m_type == YAML_MAPPING_NODE)
|
if (curSub->m_type == YAML_MAPPING_NODE)
|
||||||
curSub->assignMapChild(name ? name : std::string_view{}, std::move(ValToNode(val)));
|
curSub->assignMapChild(!name.empty() ? name : std::string_view{}, ValToNode(val));
|
||||||
else if (curSub->m_type == YAML_SEQUENCE_NODE)
|
else if (curSub->m_type == YAML_SEQUENCE_NODE)
|
||||||
curSub->m_seqChildren.emplace_back(std::move(ValToNode(val)));
|
curSub->m_seqChildren.emplace_back(ValToNode(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
template void YAMLDocWriter::writeVal<atInt8>(const char* name, const atInt8& val);
|
template void YAMLDocWriter::writeVal<atInt8>(std::string_view name, const atInt8& val);
|
||||||
template void YAMLDocWriter::writeVal<atUint8>(const char* name, const atUint8& val);
|
template void YAMLDocWriter::writeVal<atUint8>(std::string_view name, const atUint8& val);
|
||||||
template void YAMLDocWriter::writeVal<atInt16>(const char* name, const atInt16& val);
|
template void YAMLDocWriter::writeVal<atInt16>(std::string_view name, const atInt16& val);
|
||||||
template void YAMLDocWriter::writeVal<atUint16>(const char* name, const atUint16& val);
|
template void YAMLDocWriter::writeVal<atUint16>(std::string_view name, const atUint16& val);
|
||||||
template void YAMLDocWriter::writeVal<atInt32>(const char* name, const atInt32& val);
|
template void YAMLDocWriter::writeVal<atInt32>(std::string_view name, const atInt32& val);
|
||||||
template void YAMLDocWriter::writeVal<atUint32>(const char* name, const atUint32& val);
|
template void YAMLDocWriter::writeVal<atUint32>(std::string_view name, const atUint32& val);
|
||||||
template void YAMLDocWriter::writeVal<float>(const char* name, const float& val);
|
template void YAMLDocWriter::writeVal<float>(std::string_view name, const float& val);
|
||||||
template void YAMLDocWriter::writeVal<double>(const char* name, const double& val);
|
template void YAMLDocWriter::writeVal<double>(std::string_view name, const double& val);
|
||||||
template void YAMLDocWriter::writeVal<atVec3f>(const char* name, const atVec3f& val);
|
template void YAMLDocWriter::writeVal<atVec3f>(std::string_view name, const atVec3f& val);
|
||||||
template void YAMLDocWriter::writeVal<atVec4f>(const char* name, const atVec4f& val);
|
template void YAMLDocWriter::writeVal<atVec4f>(std::string_view name, const atVec4f& val);
|
||||||
template void YAMLDocWriter::writeVal<bool>(const char* name, const bool& val);
|
template void YAMLDocWriter::writeVal<bool>(std::string_view name, const bool& val);
|
||||||
|
|
||||||
template <typename INTYPE>
|
template <typename INTYPE>
|
||||||
void YAMLDocWriter::writeVal(const char* name, const INTYPE& val, size_t byteCount) {
|
void YAMLDocWriter::writeVal(std::string_view name, const INTYPE& val, size_t byteCount) {
|
||||||
YAMLNode* curSub = m_subStack.back();
|
YAMLNode* curSub = m_subStack.back();
|
||||||
if (curSub->m_type == YAML_MAPPING_NODE)
|
if (curSub->m_type == YAML_MAPPING_NODE)
|
||||||
curSub->assignMapChild(name ? name : std::string_view{}, std::move(ValToNode(val, byteCount)));
|
curSub->assignMapChild(!name.empty() ? name : std::string_view{}, ValToNode(val, byteCount));
|
||||||
else if (curSub->m_type == YAML_SEQUENCE_NODE)
|
else if (curSub->m_type == YAML_SEQUENCE_NODE)
|
||||||
curSub->m_seqChildren.emplace_back(std::move(ValToNode(val, byteCount)));
|
curSub->m_seqChildren.emplace_back(ValToNode(val, byteCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
void YAMLDocWriter::writeBool(const char* name, const bool& val) { writeVal<bool>(name, val); }
|
void YAMLDocWriter::writeBool(std::string_view name, const bool& val) { writeVal<bool>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeByte(const char* name, const atInt8& val) { writeVal<atInt8>(name, val); }
|
void YAMLDocWriter::writeByte(std::string_view name, const atInt8& val) { writeVal<atInt8>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeUByte(const char* name, const atUint8& val) { writeVal<atUint8>(name, val); }
|
void YAMLDocWriter::writeUByte(std::string_view name, const atUint8& val) { writeVal<atUint8>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeInt16(const char* name, const atInt16& val) { writeVal<atInt16>(name, val); }
|
void YAMLDocWriter::writeInt16(std::string_view name, const atInt16& val) { writeVal<atInt16>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeUint16(const char* name, const atUint16& val) { writeVal<atUint16>(name, val); }
|
void YAMLDocWriter::writeUint16(std::string_view name, const atUint16& val) { writeVal<atUint16>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeInt32(const char* name, const atInt32& val) { writeVal<atInt32>(name, val); }
|
void YAMLDocWriter::writeInt32(std::string_view name, const atInt32& val) { writeVal<atInt32>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeUint32(const char* name, const atUint32& val) { writeVal<atUint32>(name, val); }
|
void YAMLDocWriter::writeUint32(std::string_view name, const atUint32& val) { writeVal<atUint32>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeInt64(const char* name, const atInt64& val) { writeVal<atInt64>(name, val); }
|
void YAMLDocWriter::writeInt64(std::string_view name, const atInt64& val) { writeVal<atInt64>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeUint64(const char* name, const atUint64& val) { writeVal<atUint64>(name, val); }
|
void YAMLDocWriter::writeUint64(std::string_view name, const atUint64& val) { writeVal<atUint64>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeFloat(const char* name, const float& val) { writeVal<float>(name, val); }
|
void YAMLDocWriter::writeFloat(std::string_view name, const float& val) { writeVal<float>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeDouble(const char* name, const double& val) { writeVal<double>(name, val); }
|
void YAMLDocWriter::writeDouble(std::string_view name, const double& val) { writeVal<double>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeVec2f(const char* name, const atVec2f& val) { writeVal<atVec2f>(name, val); }
|
void YAMLDocWriter::writeVec2f(std::string_view name, const atVec2f& val) { writeVal<atVec2f>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeVec3f(const char* name, const atVec3f& val) { writeVal<atVec3f>(name, val); }
|
void YAMLDocWriter::writeVec3f(std::string_view name, const atVec3f& val) { writeVal<atVec3f>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeVec4f(const char* name, const atVec4f& val) { writeVal<atVec4f>(name, val); }
|
void YAMLDocWriter::writeVec4f(std::string_view name, const atVec4f& val) { writeVal<atVec4f>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeVec2d(const char* name, const atVec2d& val) { writeVal<atVec2d>(name, val); }
|
void YAMLDocWriter::writeVec2d(std::string_view name, const atVec2d& val) { writeVal<atVec2d>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeVec3d(const char* name, const atVec3d& val) { writeVal<atVec3d>(name, val); }
|
void YAMLDocWriter::writeVec3d(std::string_view name, const atVec3d& val) { writeVal<atVec3d>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeVec4d(const char* name, const atVec4d& val) { writeVal<atVec4d>(name, val); }
|
void YAMLDocWriter::writeVec4d(std::string_view name, const atVec4d& val) { writeVal<atVec4d>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeUBytes(const char* name, const std::unique_ptr<atUint8[]>& val, size_t byteCount) {
|
void YAMLDocWriter::writeUBytes(std::string_view name, const std::unique_ptr<atUint8[]>& val, size_t byteCount) {
|
||||||
writeVal<const std::unique_ptr<atUint8[]>&>(name, val, byteCount);
|
writeVal<const std::unique_ptr<atUint8[]>&>(name, val, byteCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YAMLDocWriter::writeString(const char* name, std::string_view val) { writeVal<std::string_view>(name, val); }
|
void YAMLDocWriter::writeString(std::string_view name, std::string_view val) { writeVal<std::string_view>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeWString(const char* name, std::wstring_view val) { writeVal<std::wstring_view>(name, val); }
|
void YAMLDocWriter::writeWString(std::string_view name, std::wstring_view val) { writeVal<std::wstring_view>(name, val); }
|
||||||
|
|
||||||
void YAMLDocWriter::writeU16String(const char* name, std::u16string_view val) {
|
void YAMLDocWriter::writeU16String(std::string_view name, std::u16string_view val) {
|
||||||
writeVal<std::u16string_view>(name, val);
|
writeVal<std::u16string_view>(name, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YAMLDocWriter::writeU32String(const char* name, std::u32string_view val) {
|
void YAMLDocWriter::writeU32String(std::string_view name, std::u32string_view val) {
|
||||||
writeVal<std::u32string_view>(name, val);
|
writeVal<std::u32string_view>(name, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -711,7 +712,7 @@ bool YAMLDocReader::parse(athena::io::IStreamReader* reader) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YAMLDocReader::ClassTypeOperation(std::function<bool(const char* dnaType)> func) {
|
bool YAMLDocReader::ClassTypeOperation(std::function<bool(std::string_view dnaType)> func) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
if (!yaml_parser_parse(&m_parser, &event)) {
|
if (!yaml_parser_parse(&m_parser, &event)) {
|
||||||
HandleYAMLParserError(&m_parser);
|
HandleYAMLParserError(&m_parser);
|
||||||
|
@ -762,14 +763,14 @@ bool YAMLDocReader::ClassTypeOperation(std::function<bool(const char* dnaType)>
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YAMLDocReader::ValidateClassType(const char* expectedType) {
|
bool YAMLDocReader::ValidateClassType(std::string_view expectedType) {
|
||||||
if (!expectedType)
|
if (expectedType.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return ClassTypeOperation([&](const char* dnaType) -> bool { return (strcmp(expectedType, dnaType) == 0); });
|
return ClassTypeOperation([&](std::string_view dnaType) { return expectedType == dnaType; });
|
||||||
}
|
}
|
||||||
|
|
||||||
YAMLDocReader::RecordRAII YAMLDocReader::enterSubRecord(const char* name) {
|
YAMLDocReader::RecordRAII YAMLDocReader::enterSubRecord(std::string_view name) {
|
||||||
YAMLNode* curSub = m_subStack.back();
|
YAMLNode* curSub = m_subStack.back();
|
||||||
if (curSub->m_type == YAML_SEQUENCE_NODE) {
|
if (curSub->m_type == YAML_SEQUENCE_NODE) {
|
||||||
int& seqIdx = m_seqTrackerStack.back();
|
int& seqIdx = m_seqTrackerStack.back();
|
||||||
|
@ -777,11 +778,11 @@ YAMLDocReader::RecordRAII YAMLDocReader::enterSubRecord(const char* name) {
|
||||||
if (m_subStack.back()->m_type == YAML_SEQUENCE_NODE)
|
if (m_subStack.back()->m_type == YAML_SEQUENCE_NODE)
|
||||||
m_seqTrackerStack.push_back(0);
|
m_seqTrackerStack.push_back(0);
|
||||||
return RecordRAII{this};
|
return RecordRAII{this};
|
||||||
} else if (!name) {
|
} else if (name.empty()) {
|
||||||
atError(fmt("Expected YAML sequence"));
|
atError(fmt("Expected YAML sequence"));
|
||||||
}
|
}
|
||||||
for (const auto& item : curSub->m_mapChildren) {
|
for (const auto& item : curSub->m_mapChildren) {
|
||||||
if (!item.first.compare(name)) {
|
if (item.first == name) {
|
||||||
m_subStack.push_back(item.second.get());
|
m_subStack.push_back(item.second.get());
|
||||||
if (m_subStack.back()->m_type == YAML_SEQUENCE_NODE)
|
if (m_subStack.back()->m_type == YAML_SEQUENCE_NODE)
|
||||||
m_seqTrackerStack.push_back(0);
|
m_seqTrackerStack.push_back(0);
|
||||||
|
@ -799,16 +800,16 @@ void YAMLDocReader::_leaveSubRecord() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YAMLDocReader::VectorRAII YAMLDocReader::enterSubVector(const char* name, size_t& countOut) {
|
YAMLDocReader::VectorRAII YAMLDocReader::enterSubVector(std::string_view name, size_t& countOut) {
|
||||||
YAMLNode* curSub = m_subStack.back();
|
YAMLNode* curSub = m_subStack.back();
|
||||||
if (!name && curSub->m_type == YAML_SEQUENCE_NODE) {
|
if (name.empty() && curSub->m_type == YAML_SEQUENCE_NODE) {
|
||||||
m_subStack.push_back(curSub);
|
m_subStack.push_back(curSub);
|
||||||
m_seqTrackerStack.push_back(0);
|
m_seqTrackerStack.push_back(0);
|
||||||
countOut = curSub->m_seqChildren.size();
|
countOut = curSub->m_seqChildren.size();
|
||||||
return VectorRAII{this};
|
return VectorRAII{this};
|
||||||
} else {
|
} else {
|
||||||
for (const auto& item : curSub->m_mapChildren) {
|
for (const auto& item : curSub->m_mapChildren) {
|
||||||
if (!item.first.compare(name)) {
|
if (item.first == name) {
|
||||||
YAMLNode* nextSub = item.second.get();
|
YAMLNode* nextSub = item.second.get();
|
||||||
if (nextSub->m_type == YAML_SEQUENCE_NODE) {
|
if (nextSub->m_type == YAML_SEQUENCE_NODE) {
|
||||||
countOut = nextSub->m_seqChildren.size();
|
countOut = nextSub->m_seqChildren.size();
|
||||||
|
@ -834,7 +835,7 @@ void YAMLDocReader::_leaveSubVector() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename RETURNTYPE>
|
template <typename RETURNTYPE>
|
||||||
RETURNTYPE YAMLDocReader::readVal(const char* name) {
|
RETURNTYPE YAMLDocReader::readVal(std::string_view name) {
|
||||||
if (m_subStack.size()) {
|
if (m_subStack.size()) {
|
||||||
const YAMLNode* mnode = m_subStack.back();
|
const YAMLNode* mnode = m_subStack.back();
|
||||||
if (mnode->m_type == YAML_SCALAR_NODE) {
|
if (mnode->m_type == YAML_SCALAR_NODE) {
|
||||||
|
@ -842,75 +843,75 @@ RETURNTYPE YAMLDocReader::readVal(const char* name) {
|
||||||
} else if (mnode->m_type == YAML_SEQUENCE_NODE) {
|
} else if (mnode->m_type == YAML_SEQUENCE_NODE) {
|
||||||
int& seqIdx = m_seqTrackerStack.back();
|
int& seqIdx = m_seqTrackerStack.back();
|
||||||
return NodeToVal<RETURNTYPE>(mnode->m_seqChildren[seqIdx++].get());
|
return NodeToVal<RETURNTYPE>(mnode->m_seqChildren[seqIdx++].get());
|
||||||
} else if (mnode->m_type == YAML_MAPPING_NODE && name) {
|
} else if (mnode->m_type == YAML_MAPPING_NODE && !name.empty()) {
|
||||||
for (const auto& item : mnode->m_mapChildren) {
|
for (const auto& item : mnode->m_mapChildren) {
|
||||||
if (!item.first.compare(name)) {
|
if (item.first == name) {
|
||||||
return NodeToVal<RETURNTYPE>(item.second.get());
|
return NodeToVal<RETURNTYPE>(item.second.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (name)
|
if (!name.empty())
|
||||||
atWarning(fmt("Unable to find field '{}'; returning 0"), name);
|
atWarning(fmt("Unable to find field '{}'; returning 0"), name);
|
||||||
return RETURNTYPE();
|
return RETURNTYPE();
|
||||||
}
|
}
|
||||||
|
|
||||||
template atInt8 YAMLDocReader::readVal<atInt8>(const char* name);
|
template atInt8 YAMLDocReader::readVal<atInt8>(std::string_view name);
|
||||||
template atUint8 YAMLDocReader::readVal<atUint8>(const char* name);
|
template atUint8 YAMLDocReader::readVal<atUint8>(std::string_view name);
|
||||||
template atInt16 YAMLDocReader::readVal<atInt16>(const char* name);
|
template atInt16 YAMLDocReader::readVal<atInt16>(std::string_view name);
|
||||||
template atUint16 YAMLDocReader::readVal<atUint16>(const char* name);
|
template atUint16 YAMLDocReader::readVal<atUint16>(std::string_view name);
|
||||||
template atInt32 YAMLDocReader::readVal<atInt32>(const char* name);
|
template atInt32 YAMLDocReader::readVal<atInt32>(std::string_view name);
|
||||||
template atUint32 YAMLDocReader::readVal<atUint32>(const char* name);
|
template atUint32 YAMLDocReader::readVal<atUint32>(std::string_view name);
|
||||||
template float YAMLDocReader::readVal<float>(const char* name);
|
template float YAMLDocReader::readVal<float>(std::string_view name);
|
||||||
template double YAMLDocReader::readVal<double>(const char* name);
|
template double YAMLDocReader::readVal<double>(std::string_view name);
|
||||||
template atVec3f YAMLDocReader::readVal<atVec3f>(const char* name);
|
template atVec3f YAMLDocReader::readVal<atVec3f>(std::string_view name);
|
||||||
template atVec4f YAMLDocReader::readVal<atVec4f>(const char* name);
|
template atVec4f YAMLDocReader::readVal<atVec4f>(std::string_view name);
|
||||||
template bool YAMLDocReader::readVal<bool>(const char* name);
|
template bool YAMLDocReader::readVal<bool>(std::string_view name);
|
||||||
|
|
||||||
bool YAMLDocReader::readBool(const char* name) { return readVal<bool>(name); }
|
bool YAMLDocReader::readBool(std::string_view name) { return readVal<bool>(name); }
|
||||||
|
|
||||||
atInt8 YAMLDocReader::readByte(const char* name) { return readVal<atInt8>(name); }
|
atInt8 YAMLDocReader::readByte(std::string_view name) { return readVal<atInt8>(name); }
|
||||||
|
|
||||||
atUint8 YAMLDocReader::readUByte(const char* name) { return readVal<atUint8>(name); }
|
atUint8 YAMLDocReader::readUByte(std::string_view name) { return readVal<atUint8>(name); }
|
||||||
|
|
||||||
atInt16 YAMLDocReader::readInt16(const char* name) { return readVal<atInt16>(name); }
|
atInt16 YAMLDocReader::readInt16(std::string_view name) { return readVal<atInt16>(name); }
|
||||||
|
|
||||||
atUint16 YAMLDocReader::readUint16(const char* name) { return readVal<atUint16>(name); }
|
atUint16 YAMLDocReader::readUint16(std::string_view name) { return readVal<atUint16>(name); }
|
||||||
|
|
||||||
atInt32 YAMLDocReader::readInt32(const char* name) { return readVal<atInt32>(name); }
|
atInt32 YAMLDocReader::readInt32(std::string_view name) { return readVal<atInt32>(name); }
|
||||||
|
|
||||||
atUint32 YAMLDocReader::readUint32(const char* name) { return readVal<atUint32>(name); }
|
atUint32 YAMLDocReader::readUint32(std::string_view name) { return readVal<atUint32>(name); }
|
||||||
|
|
||||||
atInt64 YAMLDocReader::readInt64(const char* name) { return readVal<atInt64>(name); }
|
atInt64 YAMLDocReader::readInt64(std::string_view name) { return readVal<atInt64>(name); }
|
||||||
|
|
||||||
atUint64 YAMLDocReader::readUint64(const char* name) { return readVal<atUint64>(name); }
|
atUint64 YAMLDocReader::readUint64(std::string_view name) { return readVal<atUint64>(name); }
|
||||||
|
|
||||||
float YAMLDocReader::readFloat(const char* name) { return readVal<float>(name); }
|
float YAMLDocReader::readFloat(std::string_view name) { return readVal<float>(name); }
|
||||||
|
|
||||||
double YAMLDocReader::readDouble(const char* name) { return readVal<double>(name); }
|
double YAMLDocReader::readDouble(std::string_view name) { return readVal<double>(name); }
|
||||||
|
|
||||||
atVec2f YAMLDocReader::readVec2f(const char* name) { return readVal<atVec2f>(name); }
|
atVec2f YAMLDocReader::readVec2f(std::string_view name) { return readVal<atVec2f>(name); }
|
||||||
|
|
||||||
atVec3f YAMLDocReader::readVec3f(const char* name) { return readVal<atVec3f>(name); }
|
atVec3f YAMLDocReader::readVec3f(std::string_view name) { return readVal<atVec3f>(name); }
|
||||||
atVec4f YAMLDocReader::readVec4f(const char* name) { return readVal<atVec4f>(name); }
|
atVec4f YAMLDocReader::readVec4f(std::string_view name) { return readVal<atVec4f>(name); }
|
||||||
|
|
||||||
atVec2d YAMLDocReader::readVec2d(const char* name) { return readVal<atVec2d>(name); }
|
atVec2d YAMLDocReader::readVec2d(std::string_view name) { return readVal<atVec2d>(name); }
|
||||||
|
|
||||||
atVec3d YAMLDocReader::readVec3d(const char* name) { return readVal<atVec3d>(name); }
|
atVec3d YAMLDocReader::readVec3d(std::string_view name) { return readVal<atVec3d>(name); }
|
||||||
|
|
||||||
atVec4d YAMLDocReader::readVec4d(const char* name) { return readVal<atVec4d>(name); }
|
atVec4d YAMLDocReader::readVec4d(std::string_view name) { return readVal<atVec4d>(name); }
|
||||||
|
|
||||||
std::unique_ptr<atUint8[]> YAMLDocReader::readUBytes(const char* name) {
|
std::unique_ptr<atUint8[]> YAMLDocReader::readUBytes(std::string_view name) {
|
||||||
return readVal<std::unique_ptr<atUint8[]>>(name);
|
return readVal<std::unique_ptr<atUint8[]>>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string YAMLDocReader::readString(const char* name) { return readVal<std::string>(name); }
|
std::string YAMLDocReader::readString(std::string_view name) { return readVal<std::string>(name); }
|
||||||
|
|
||||||
std::wstring YAMLDocReader::readWString(const char* name) { return readVal<std::wstring>(name); }
|
std::wstring YAMLDocReader::readWString(std::string_view name) { return readVal<std::wstring>(name); }
|
||||||
|
|
||||||
static bool EmitKeyScalar(yaml_emitter_t* doc, const char* val) {
|
static bool EmitKeyScalar(yaml_emitter_t* doc, std::string_view val) {
|
||||||
yaml_event_t event;
|
yaml_event_t event;
|
||||||
if (!yaml_scalar_event_initialize(&event, nullptr, nullptr, (yaml_char_t*)val, strlen(val), true, true,
|
if (!yaml_scalar_event_initialize(&event, nullptr, nullptr, (yaml_char_t*)val.data(), val.size(), true, true,
|
||||||
YAML_PLAIN_SCALAR_STYLE))
|
YAML_PLAIN_SCALAR_STYLE))
|
||||||
return false;
|
return false;
|
||||||
return yaml_emitter_emit(doc, &event) != 0;
|
return yaml_emitter_emit(doc, &event) != 0;
|
||||||
|
|
|
@ -71,7 +71,7 @@ bool parseBool(std::string_view boolean, bool* valid) {
|
||||||
tolower(val);
|
tolower(val);
|
||||||
|
|
||||||
// Check for true first
|
// Check for true first
|
||||||
if (!val.compare("true") || !val.compare("1") || !val.compare("yes") || !val.compare("on")) {
|
if (val == "true" || val == "1" || val == "yes" || val == "on") {
|
||||||
if (valid)
|
if (valid)
|
||||||
*valid = true;
|
*valid = true;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ bool parseBool(std::string_view boolean, bool* valid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now false
|
// Now false
|
||||||
if (!val.compare("false") || !val.compare("0") || !val.compare("no") || !val.compare("off")) {
|
if (val == "false" || val == "0" || val == "no" || val == "off") {
|
||||||
if (valid)
|
if (valid)
|
||||||
*valid = true;
|
*valid = true;
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ void WiiFile::addChild(WiiFile* file) {
|
||||||
tmpName = tmpName.substr(0, tmpName.find('/'));
|
tmpName = tmpName.substr(0, tmpName.find('/'));
|
||||||
|
|
||||||
for (atUint32 i = 0; i < m_children.size(); i++) {
|
for (atUint32 i = 0; i < m_children.size(); i++) {
|
||||||
if (!m_children[i]->filename().compare(tmpName)) {
|
if (m_children[i]->filename() == tmpName) {
|
||||||
std::string newName = file->filename();
|
std::string newName = file->filename();
|
||||||
newName = newName.substr(newName.rfind("/") + 1, newName.size() - newName.rfind("/"));
|
newName = newName.substr(newName.rfind("/") + 1, newName.size() - newName.rfind("/"));
|
||||||
file->setFilename(newName);
|
file->setFilename(newName);
|
||||||
|
@ -114,7 +114,7 @@ void WiiFile::addChild(WiiFile* file) {
|
||||||
|
|
||||||
WiiFile* WiiFile::child(const std::string& name) {
|
WiiFile* WiiFile::child(const std::string& name) {
|
||||||
std::vector<WiiFile*>::iterator iter =
|
std::vector<WiiFile*>::iterator iter =
|
||||||
std::find_if(m_children.begin(), m_children.end(), [&name](WiiFile* f) { return !f->filename().compare(name); });
|
std::find_if(m_children.begin(), m_children.end(), [&name](WiiFile* f) { return f->filename() == name; });
|
||||||
|
|
||||||
if (iter != m_children.end())
|
if (iter != m_children.end())
|
||||||
return *iter;
|
return *iter;
|
||||||
|
|
|
@ -41,7 +41,7 @@ ZQuestFile* ZQuestFileReader::read() {
|
||||||
gameString = std::string((const char*)readBytes(0x0A).get(), 0x0A);
|
gameString = std::string((const char*)readBytes(0x0A).get(), 0x0A);
|
||||||
|
|
||||||
for (size_t i = 0; i < ZQuestFile::gameStringList().size(); i++) {
|
for (size_t i = 0; i < ZQuestFile::gameStringList().size(); i++) {
|
||||||
if (!ZQuestFile::gameStringList().at(i).substr(0, 0x0A).compare(gameString)) {
|
if (ZQuestFile::gameStringList().at(i).substr(0, 0x0A) == gameString) {
|
||||||
gameString = ZQuestFile::gameStringList().at(i);
|
gameString = ZQuestFile::gameStringList().at(i);
|
||||||
game = (ZQuestFile::Game)i;
|
game = (ZQuestFile::Game)i;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue