[ox/model] Rename ioOp and op to model and field

This commit is contained in:
2019-03-17 13:18:46 -05:00
parent bf6469b4a3
commit bbd1d187b2
12 changed files with 145 additions and 145 deletions

View File

@@ -36,7 +36,7 @@ const TypeStore &TypeDescReader<ReaderBase>::typeStore() const {
template<typename ReaderBase, typename T>
int readMCDef(uint8_t *buff, std::size_t buffLen, T *val) {
TypeDescReader<ReaderBase> reader(buff, buffLen);
return ioOp(&reader, val);
return model(&reader, val);
}
}

View File

@@ -117,56 +117,56 @@ struct DescriptorType {
template<typename T>
Error ioOp(T *io, DescriptorType *type) {
Error model(T *io, DescriptorType *type) {
Error err = 0;
io->setTypeInfo("ox::DescriptorType", 4);
err |= io->op("typeName", &type->typeName);
err |= io->op("primitiveType", &type->primitiveType);
err |= io->op("fieldList", &type->fieldList);
err |= io->op("length", &type->length);
err |= io->field("typeName", &type->typeName);
err |= io->field("primitiveType", &type->primitiveType);
err |= io->field("fieldList", &type->fieldList);
err |= io->field("length", &type->length);
return err;
}
template<typename T>
Error ioOpWrite(T *io, DescriptorField *field) {
Error modelWrite(T *io, DescriptorField *field) {
Error err = 0;
io->setTypeInfo("ox::DescriptorField", 4);
if (field->ownsType) {
err |= io->op("typeName", "");
err |= io->op("type", field->type);
err |= io->field("typeName", "");
err |= io->field("type", field->type);
} else {
err |= io->op("typeName", &field->type->typeName);
err |= io->op("type", static_cast<decltype(field->type)>(nullptr));
err |= io->field("typeName", &field->type->typeName);
err |= io->field("type", static_cast<decltype(field->type)>(nullptr));
}
err |= io->op("fieldName", &field->fieldName);
err |= io->field("fieldName", &field->fieldName);
// defaultValue is unused now, but leave placeholder for backwards compatibility
const int DefaultValue = 0;
err |= io->op("defaultValue", &DefaultValue);
err |= io->field("defaultValue", &DefaultValue);
return err;
}
template<typename T>
Error ioOpRead(T *io, DescriptorField *field) {
Error modelRead(T *io, DescriptorField *field) {
Error err = 0;
auto &typeStore = io->typeStore();
io->setTypeInfo("ox::DescriptorField", 4);
err |= io->op("typeName", &field->typeName);
err |= io->field("typeName", &field->typeName);
if (field->typeName == "") {
field->ownsType = true;
if (field->type == nullptr) {
field->type = new DescriptorType;
}
err |= io->op("type", field->type);
err |= io->field("type", field->type);
typeStore[field->type->typeName] = field->type;
} else {
// should be empty, so discard
DescriptorType t;
err |= io->op("type", &t);
err |= io->field("type", &t);
field->type = typeStore[field->typeName];
}
err |= io->op("fieldName", &field->fieldName);
err |= io->field("fieldName", &field->fieldName);
// defaultValue is unused now, but placeholder for backwards compatibility
err |= io->op("defaultValue", nullptr);
err |= io->field("defaultValue", nullptr);
return err;
}

View File

@@ -43,12 +43,12 @@ class TypeDescWriter {
}
template<typename T>
constexpr ox::Error op(const char*, T*, std::size_t) noexcept {
constexpr ox::Error field(const char*, T*, std::size_t) noexcept {
return OxError(0);
}
template<typename T>
constexpr ox::Error op(const char*, T*) noexcept {
constexpr ox::Error field(const char*, T*) noexcept {
return OxError(0);
}
@@ -64,13 +64,13 @@ class TypeDescWriter {
~TypeDescWriter();
template<typename T>
ox::Error op(const char *name, T *val, std::size_t valLen);
ox::Error field(const char *name, T *val, std::size_t valLen);
template<typename T>
ox::Error op(const char *name, ox::Vector<T> *val);
ox::Error field(const char *name, ox::Vector<T> *val);
template<typename T>
ox::Error op(const char *name, T *val);
ox::Error field(const char *name, T *val);
void setTypeInfo(const char *name, int fields);
@@ -110,12 +110,12 @@ class TypeDescWriter {
// array handler
template<typename T>
ox::Error TypeDescWriter::op(const char *name, T *val, std::size_t) {
ox::Error TypeDescWriter::field(const char *name, T *val, std::size_t) {
if (m_type) {
constexpr typename ox::remove_pointer<decltype(val)>::type *p = nullptr;
bool alreadyExisted = false;
const auto t = type(p, &alreadyExisted);
oxAssert(t != nullptr, "op(const char *name, T *val, std::size_t): Type not found or generated");
oxAssert(t != nullptr, "field(const char *name, T *val, std::size_t): Type not found or generated");
if (t == nullptr) {
type(p, &alreadyExisted);
}
@@ -126,16 +126,16 @@ ox::Error TypeDescWriter::op(const char *name, T *val, std::size_t) {
}
template<typename T>
ox::Error TypeDescWriter::op(const char *name, ox::Vector<T> *val) {
return op(name, val->data(), val->size());
ox::Error TypeDescWriter::field(const char *name, ox::Vector<T> *val) {
return field(name, val->data(), val->size());
}
template<typename T>
ox::Error TypeDescWriter::op(const char *name, T *val) {
ox::Error TypeDescWriter::field(const char *name, T *val) {
if (m_type) {
bool alreadyExisted = false;
const auto t = type(val, &alreadyExisted);
oxAssert(t != nullptr, "op(const char *name, T *val): Type not found or generated");
oxAssert(t != nullptr, "field(const char *name, T *val): Type not found or generated");
m_type->fieldList.emplace_back(t, name, 0, alreadyExisted ? t->typeName : "", !alreadyExisted);
return OxError(0);
}
@@ -150,13 +150,13 @@ DescriptorType *TypeDescWriter::type(BString<sz> *val, bool *alreadyExisted) {
template<typename T>
DescriptorType *TypeDescWriter::type(T *val, bool *alreadyExisted) {
NameCatcher nc;
ioOp(&nc, val);
model(&nc, val);
if (m_typeStore->contains(nc.name)) {
*alreadyExisted = true;
return m_typeStore->at(nc.name);
} else {
TypeDescWriter dw(m_typeStore);
oxLogError(ioOp(&dw, val));
oxLogError(model(&dw, val));
*alreadyExisted = false;
return dw.m_type;
}
@@ -165,7 +165,7 @@ DescriptorType *TypeDescWriter::type(T *val, bool *alreadyExisted) {
template<typename T>
[[nodiscard]] ValErr<DescriptorType*> buildMCDef(T *val) {
TypeDescWriter writer;
Error err = ioOp(&writer, val);
Error err = model(&writer, val);
return {writer.definition(), err};
}

View File

@@ -18,31 +18,31 @@ enum class OpType {
WriteDefinition = 3,
};
// empty default implementations of ioOp functions
// empty default implementations of model functions
template<typename T, typename O>
ox::Error ioOpRead(T*, O*) {
ox::Error modelRead(T*, O*) {
return OxError(1);
}
template<typename T, typename O>
ox::Error ioOpWrite(T*, O*) {
ox::Error modelWrite(T*, O*) {
return OxError(1);
}
template<typename T, typename O>
ox::Error ioOpWriteDefinition(T*, O*) {
ox::Error modelWriteDefinition(T*, O*) {
return OxError(1);
}
template<typename T, typename O>
ox::Error ioOp(T *io, O *obj) {
ox::Error model(T *io, O *obj) {
if constexpr(T::opType() == ox::OpType::Read) {
return ioOpRead(io, obj);
return modelRead(io, obj);
} else if constexpr(T::opType() == ox::OpType::Write) {
return ioOpWrite(io, obj);
return modelWrite(io, obj);
} else if constexpr(T::opType() == ox::OpType::WriteDefinition) {
return ioOpWriteDefinition(io, obj);
return modelWriteDefinition(io, obj);
}
return OxError(1);
}

View File

@@ -113,13 +113,13 @@ static ox::Error parseField(const DescriptorField &field, Reader *rdr, DataWalke
if (rdr->fieldPresent()) {
auto child = rdr->child();
walker->pushType(field.type);
oxReturnError(ioOp(&child, walker));
oxReturnError(model(&child, walker));
walker->popType();
rdr->nextField();
} else {
// skip and discard absent field
int discard;
oxReturnError(rdr->op("", &discard));
oxReturnError(rdr->field("", &discard));
}
break;
}
@@ -129,7 +129,7 @@ static ox::Error parseField(const DescriptorField &field, Reader *rdr, DataWalke
}
template<typename Reader, typename FH>
ox::Error ioOp(Reader *rdr, DataWalker<Reader, FH> *walker) {
ox::Error model(Reader *rdr, DataWalker<Reader, FH> *walker) {
auto type = walker->type();
if (!type) {
return OxError(1);