Rename YAML methods as read/write overloads

This commit is contained in:
Jack Andersen 2016-01-03 19:23:38 -10:00
parent 375a68c48a
commit 9c880813ac
2 changed files with 30 additions and 28 deletions

View File

@ -567,7 +567,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor>
if (isDNARecord(rDecl, baseDNA, isYAML)) if (isDNARecord(rDecl, baseDNA, isYAML))
{ {
isDNATypeOut = true; isDNATypeOut = true;
return "toYAML(" ATHENA_YAML_WRITER ");"; return "write(" ATHENA_YAML_WRITER ");";
} }
} }
} }
@ -688,7 +688,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor>
if (isDNARecord(rDecl, baseDNA, isYAML)) if (isDNARecord(rDecl, baseDNA, isYAML))
{ {
isDNATypeOut = true; isDNATypeOut = true;
return "fromYAML(" ATHENA_YAML_READER ");"; return "read(" ATHENA_YAML_READER ");";
} }
} }
} }
@ -1825,16 +1825,16 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor>
for (int p=0 ; p<2 ; ++p) for (int p=0 ; p<2 ; ++p)
{ {
if (p) if (p)
fileOut << "void " << decl->getQualifiedNameAsString() << "::toYAML(Athena::io::YAMLDocWriter& " ATHENA_YAML_WRITER ") const\n{\n"; fileOut << "void " << decl->getQualifiedNameAsString() << "::write(Athena::io::YAMLDocWriter& " ATHENA_YAML_WRITER ") const\n{\n";
else else
fileOut << "void " << decl->getQualifiedNameAsString() << "::fromYAML(Athena::io::YAMLDocReader& " ATHENA_YAML_READER ")\n{\n"; fileOut << "void " << decl->getQualifiedNameAsString() << "::read(Athena::io::YAMLDocReader& " ATHENA_YAML_READER ")\n{\n";
if (baseDNA.size()) if (baseDNA.size())
{ {
if (p) if (p)
fileOut << " " << baseDNA << "::toYAML(" ATHENA_YAML_WRITER ");\n"; fileOut << " " << baseDNA << "::write(" ATHENA_YAML_WRITER ");\n";
else else
fileOut << " " << baseDNA << "::fromYAML(" ATHENA_YAML_READER ");\n"; fileOut << " " << baseDNA << "::read(" ATHENA_YAML_READER ");\n";
} }
for (const clang::FieldDecl* field : decl->fields()) for (const clang::FieldDecl* field : decl->fields())

View File

@ -544,7 +544,7 @@ public:
void enumerate(const char* name, T& record) void enumerate(const char* name, T& record)
{ {
enterSubRecord(name); enterSubRecord(name);
record.fromYAML(*this); record.read(*this);
leaveSubRecord(); leaveSubRecord();
} }
@ -586,7 +586,7 @@ public:
{ {
vector.emplace_back(); vector.emplace_back();
enterSubRecord(nullptr); enterSubRecord(nullptr);
vector.back().fromYAML(*this); vector.back().read(*this);
leaveSubRecord(); leaveSubRecord();
} }
leaveSubVector(); leaveSubVector();
@ -811,7 +811,7 @@ public:
void enumerate(const char* name, T& record) void enumerate(const char* name, T& record)
{ {
enterSubRecord(name); enterSubRecord(name);
record.toYAML(*this); record.write(*this);
leaveSubRecord(); leaveSubRecord();
} }
@ -849,7 +849,7 @@ public:
for (const T& item : vector) for (const T& item : vector)
{ {
enterSubRecord(nullptr); enterSubRecord(nullptr);
item.toYAML(*this); item.write(*this);
leaveSubRecord(); leaveSubRecord();
} }
leaveSubVector(); leaveSubVector();
@ -1053,8 +1053,10 @@ struct DNAYaml : DNA<DNAE>
{ {
virtual ~DNAYaml() {} virtual ~DNAYaml() {}
virtual void toYAML(YAMLDocWriter& out) const=0; using DNA<DNAE>::read;
virtual void fromYAML(YAMLDocReader& in)=0; using DNA<DNAE>::write;
virtual void read(YAMLDocReader& in)=0;
virtual void write(YAMLDocWriter& out) const=0;
static const char* DNAType() {return nullptr;} static const char* DNAType() {return nullptr;}
virtual const char* DNATypeV() const {return nullptr;} virtual const char* DNATypeV() const {return nullptr;}
@ -1092,7 +1094,7 @@ struct DNAYaml : DNA<DNAE>
} }
{ {
YAMLDocWriter docWriter(DNATypeV()); YAMLDocWriter docWriter(DNATypeV());
toYAML(docWriter); write(docWriter);
if (!docWriter.finish(&emitter)) if (!docWriter.finish(&emitter))
{ {
yaml_emitter_delete(&emitter); yaml_emitter_delete(&emitter);
@ -1129,7 +1131,7 @@ struct DNAYaml : DNA<DNAE>
yaml_parser_delete(&parser); yaml_parser_delete(&parser);
return false; return false;
} }
fromYAML(docReader); read(docReader);
yaml_parser_delete(&parser); yaml_parser_delete(&parser);
return true; return true;
} }
@ -1171,7 +1173,7 @@ struct DNAYaml : DNA<DNAE>
} }
{ {
YAMLDocWriter docWriter(DNATypeV()); YAMLDocWriter docWriter(DNATypeV());
toYAML(docWriter); write(docWriter);
if (!docWriter.finish(&emitter)) if (!docWriter.finish(&emitter))
{ {
yaml_emitter_delete(&emitter); yaml_emitter_delete(&emitter);
@ -1207,7 +1209,7 @@ struct DNAYaml : DNA<DNAE>
yaml_parser_delete(&parser); yaml_parser_delete(&parser);
return false; return false;
} }
fromYAML(docReader); read(docReader);
yaml_parser_delete(&parser); yaml_parser_delete(&parser);
return true; return true;
} }
@ -1253,9 +1255,9 @@ struct BufferYaml : public DNAYaml<VE>, public std::unique_ptr<atUint8[]>
{ {
return __isz + sizeVar; return __isz + sizeVar;
} }
void fromYAML(Athena::io::YAMLDocReader& reader) void read(Athena::io::YAMLDocReader& reader)
{*this = reader.readUBytes(nullptr);} {*this = reader.readUBytes(nullptr);}
void toYAML(Athena::io::YAMLDocWriter& writer) const void write(Athena::io::YAMLDocWriter& writer) const
{writer.writeUBytes(nullptr, *this, sizeVar);} {writer.writeUBytes(nullptr, *this, sizeVar);}
}; };
@ -1269,9 +1271,9 @@ struct StringYaml : public DNAYaml<VE>, public std::string
{writer.writeString(*this, sizeVar);} {writer.writeString(*this, sizeVar);}
size_t binarySize(size_t __isz) const size_t binarySize(size_t __isz) const
{return __isz + ((sizeVar<0)?(this->size()+1):sizeVar);} {return __isz + ((sizeVar<0)?(this->size()+1):sizeVar);}
void fromYAML(Athena::io::YAMLDocReader& reader) void read(Athena::io::YAMLDocReader& reader)
{this->assign(std::move(reader.readString(nullptr)));} {this->assign(std::move(reader.readString(nullptr)));}
void toYAML(Athena::io::YAMLDocWriter& writer) const void write(Athena::io::YAMLDocWriter& writer) const
{writer.writeString(nullptr, *this);} {writer.writeString(nullptr, *this);}
std::string& operator=(const std::string& __str) std::string& operator=(const std::string& __str)
{return this->assign(__str);} {return this->assign(__str);}
@ -1295,9 +1297,9 @@ struct WStringYaml : public DNAYaml<VE>, public std::wstring
} }
size_t binarySize(size_t __isz) const size_t binarySize(size_t __isz) const
{return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);} {return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);}
void fromYAML(Athena::io::YAMLDocReader& reader) void read(Athena::io::YAMLDocReader& reader)
{this->assign(std::move(reader.readWString(nullptr)));} {this->assign(std::move(reader.readWString(nullptr)));}
void toYAML(Athena::io::YAMLDocWriter& writer) const void write(Athena::io::YAMLDocWriter& writer) const
{writer.writeWString(nullptr, *this);} {writer.writeWString(nullptr, *this);}
std::wstring& operator=(const std::wstring& __str) std::wstring& operator=(const std::wstring& __str)
{return this->assign(__str);} {return this->assign(__str);}
@ -1315,9 +1317,9 @@ struct WStringAsStringYaml : public DNAYaml<VE>, public std::string
{writer.writeStringAsWString(*this, sizeVar);} {writer.writeStringAsWString(*this, sizeVar);}
size_t binarySize(size_t __isz) const size_t binarySize(size_t __isz) const
{return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);} {return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);}
void fromYAML(Athena::io::YAMLDocReader& reader) void read(Athena::io::YAMLDocReader& reader)
{this->assign(std::move(reader.readString(nullptr)));} {this->assign(std::move(reader.readString(nullptr)));}
void toYAML(Athena::io::YAMLDocWriter& writer) const void write(Athena::io::YAMLDocWriter& writer) const
{writer.writeString(nullptr, *this);} {writer.writeString(nullptr, *this);}
std::string& operator=(const std::string& __str) std::string& operator=(const std::string& __str)
{return this->assign(__str);} {return this->assign(__str);}
@ -1328,15 +1330,15 @@ struct WStringAsStringYaml : public DNAYaml<VE>, public std::string
/** Macro to automatically declare YAML read/write methods in subclasses */ /** Macro to automatically declare YAML read/write methods in subclasses */
#define DECL_YAML \ #define DECL_YAML \
DECL_DNA \ DECL_DNA \
void fromYAML(Athena::io::YAMLDocReader&); \ void read(Athena::io::YAMLDocReader&); \
void toYAML(Athena::io::YAMLDocWriter&) const; \ void write(Athena::io::YAMLDocWriter&) const; \
static const char* DNAType(); \ static const char* DNAType(); \
const char* DNATypeV() const {return DNAType();} \ const char* DNATypeV() const {return DNAType();} \
/** Macro to automatically declare YAML read/write methods with client-code's definition */ /** Macro to automatically declare YAML read/write methods with client-code's definition */
#define DECL_EXPLICIT_YAML \ #define DECL_EXPLICIT_YAML \
void fromYAML(Athena::io::YAMLDocReader&); \ void read(Athena::io::YAMLDocReader&); \
void toYAML(Athena::io::YAMLDocWriter&) const; \ void write(Athena::io::YAMLDocWriter&) const; \
static const char* DNAType(); \ static const char* DNAType(); \
const char* DNATypeV() const {return DNAType();} \ const char* DNATypeV() const {return DNAType();} \