bool polymorphic_feature::isParentClass(const descriptor& childClass) const { const polymorphic_feature* pcf = dynamic_cast<const polymorphic_feature*>(childClass.feature(Feature::POLYMORPHIC)); if (!pcf) return false; if (!pcf->has_parent()) return false; return ( (pcf->parent().name()) == this->desc().name()) ? true : this->isParentClass(pcf->parent()); }
void oarchive_json::serializeFields(const descriptor& cd, const any& value) { std::string s; const polymorphic_feature* pcf = dynamic_cast<const polymorphic_feature*>(cd.feature(Feature::POLYMORPHIC)); const any_feature* acf = NULL; if (pcf && pcf->has_parent()) this->serializeFields(pcf->parent(),value); if (cd.has(descriptor::Flags::FIELDS) == false) return; void* ptrObject = value.ptr(); any fieldValue; for (const std::unique_ptr<field>& patt : cd.get_fields()) { const field& att = *patt; if (att.need_support()) continue; this->completeLastLine(); att.get(value,fieldValue); const format* fieldFormat = dynamic_cast<const format*>(att.annotations().get(JSON::ANNOTATION_NAME, ANNOTATION_FORMAT_ALL)); if ( fieldFormat ) { this->printFieldName(att); this->_data << "\""; fieldFormat->write(this->_data , fieldValue); this->_data << "\""; continue; } const format* typeFormat = dynamic_cast<const format*>(att.desc().annotations().get(JSON::ANNOTATION_NAME, ANNOTATION_FORMAT_ALL)); if (typeFormat) { this->printFieldName(att); this->_data << "\""; typeFormat->write(this->_data,fieldValue); this->_data << "\""; continue; } const descriptor& acd = att.desc(); void* vptr = att.ptr(ptrObject); if (acd.has(descriptor::Flags::FIELDS)) { this->printFieldName(att); if (!this->_compact) this->_data << std::endl; this->serializeObject(fieldValue); } else if (acd.hasFeature(Feature::CONTAINER)) { this->printFieldName(att); if (!this->_compact) this->_data << std::endl; this->serializeObject(fieldValue); } else { if ( att.ignore_if_default_value()) { if (acd.equals(att.default_value(),fieldValue)) continue; } this->printFieldName(att); bool isString = false; att.tos(value,s); if (acd.type() == typeid(std::string)) isString = true; else { if (acd.has(descriptor::Flags::NUMERIC_VALUE) == false) isString |= !is_integer(s); else isString = true; } if (isString) this->_data << "\""; this->_data << s; if (isString) this->_data << "\""; } } }
void oarchive_json::serializeElements(const descriptor& cd, const any& value) { const container_feature* ccf = dynamic_cast<const container_feature*>(cd.feature(Feature::CONTAINER)); if (!ccf) return; bool hasKey = ccf->hasKey(); const descriptor* ecd = ccf->elementDescriptor(); const descriptor* kcd = hasKey ? ccf->keyDescriptor() : NULL; any element, key, mapped; std::string keystr, elementstr; ccf->begin(value); for (literator it = ccf->begin(value); it != ccf->end(value); ++it) { this->completeLastLine(); // get key if ( hasKey ) { key = it.key(); keystr = std::move (kcd->atos(key)); } else { keystr = ecd->name(); } element = *it; const format* typeFormat = dynamic_cast<const format*>(ecd->annotations().get(JSON::ANNOTATION_NAME)); if (typeFormat) { if ( hasKey ) this->_data << this->_tab << keystr << " = " ; typeFormat->write(this->_data,element); continue; } if (ecd->has(descriptor::Flags::FIELDS)) { if (ccf->areElementsPointers()) { if (element.empty()) continue; this->serializeObject(element); } else { this->serializeObject(element); } } else { if ( hasKey ) this->_data << this->_tab << keystr << " = " ; elementstr = std::move (ecd->atos(element)); bool isString = false; if (ecd->type() == typeid(std::string)) isString = true; else isString |= !is_integer(elementstr); if (isString) this->_data << "\""; this->_data << elementstr; if (isString) this->_data << "\""; if (!this->_compact) this->_data << std::endl; } } }