Move present_if_default check out of IsDefault
MODIFY
src/reader_struct.cpp
src/reader_struct.cpp
@@ -118,7 +118,7 @@ void Struct<S>::WriteLcf(const S& obj, LcfWriter& stream) {
<< " after " << last
<< " in struct " << name
<< std::endl;
- if (field->IsDefault(obj, ref)) {
+ if (!field->present_if_default && field->IsDefault(obj, ref)) {
continue;
}
stream.WriteInt(field->id);
@@ -143,8 +143,9 @@ int Struct<S>::LcfSize(const S& obj, LcfWriter& stream) {
continue;
}
//printf("%s\n", field->name);
- if (field->IsDefault(obj, ref))
+ if (!field->present_if_default && field->IsDefault(obj, ref)) {
continue;
+ }
result += LcfReader::IntSize(field->id);
int size = field->LcfSize(obj, stream);
result += LcfReader::IntSize(size);

MODIFY
src/reader_struct.h
src/reader_struct.h
@@ -418,9 +418,6 @@ struct TypedField : public Field<S> {
TypeReader<T>::ParseXml(obj.*ref, data);
}
bool IsDefault(const S& a, const S& b) const {
- if (this->present_if_default) {
- return false;
- }
return Compare_Traits<T>::IsEqual(a.*ref, b.*ref);
}
@@ -474,9 +471,6 @@ struct EmptyField : public Field<S> {
void ParseXml(S& obj, const std::string& data) const { }
bool IsDefault(const S& a, const S& b) const {
- if (this->present_if_default) {
- return false;
- }
return true;
}
@@ -513,9 +507,6 @@ struct SizeField : public Field<S> {
// no-op
}
bool IsDefault(const S& a, const S& b) const {
- if (this->present_if_default) {
- return false;
- }
return (a.*ref).size() == (b.*ref).size();
}

Move present_if_default check out of IsDefault