bool TickDbClassDescriptorImpl::parseDescriptors()

in src/dxapi/native/tickdb/http/xml/tickdb_class_descriptor.cpp [182:249]


bool TickDbClassDescriptorImpl::parseDescriptors(vector<TickDbClassDescriptor> &classes, XMLElement *root, bool parseFields)
{
    if (NULL == root)
        return false;

    FOR_XML_ELEMENTS(root, child, "classDescriptor") {
        const char *name = getText(child, "name");
        const char *guid = getText(child, "guid");
        XMLElement *parent = child->FirstChildElement("parent");
        const char *classType = child->Attribute("xsi:type");
        if (/*some qql result sets may not have type name NULL != name && */ 
            NULL != guid) {
            TickDbClassDescriptorImpl cls;
            if (!cls.fromXML(child, parseFields)) {
                return false;
            }

            classes.push_back(cls);
        }
    }

    intptr_t contentClassIndex = 0;
    FOR_XML_ELEMENTS(root, i, "contentClassId") {
        const char *contentGuid = i->GetText();
        if (NULL != contentGuid) {
            for (intptr_t j = contentClassIndex, count = (intptr_t)classes.size(); j < count; ++j) {
                auto &cl = classes[j];
                if (contentGuid == cl.guid) {
                    cl.isContentClass = true;
                    // All content classes will be moved on top of the array and sorted in the order of appereance of their <contentClassId>
                    swap(cl, classes[contentClassIndex++]);
                    break;
                }
            }
        }
    }


    // Hmm, O(n^2)
    intptr_t nClasses = classes.size();
    for (auto &c : classes) {
        const string &parentGuid = c.parentGuid;
        // Find parent class and link to it
        if (0 != parentGuid.length()) {
            forn(j, nClasses) {
                const string &parentGuid2 = classes[j].guid;
                if (parentGuid2 == parentGuid) {
                    c.parentIndex = j;
                    // TODO: FIX IT! LOST REFERENCE (python) + check getClassDescriptors() result
                    // TODO: check if switch to indices fixed whatever problems existed before
                    break;
                }
            }
        }
        for (auto &field : c.fields) {
            if ("enum" == field.dataType.typeName) {
                const string &enumClassGuid = field.dataType.descriptorGuid;
                for (auto &c2 : classes) {
                    if (enumClassGuid == c2.guid) {
                        field.dataType.descriptor = FieldTypeDescriptor(c2.enumType, 0, field.dataType.isNullable);
                    }
                }
            }
        }
    }

    return true;
}