void XSDElement::Load(xmlNodePtr node) { if (node != nullptr) { xmlChar *name = xmlGetProp(node, (const xmlChar *)"name"); if (name != nullptr) { mName = (char *)name; xmlFree(name); } xmlNsPtr ns = nullptr; xmlChar *type = xmlGetProp(node, (const xmlChar *)"type"); if (type != nullptr) { mType = (char *)type; xmlFree(type); ns = FindNamespace(node, mType); } else { ns = FindNamespace(node); } if (ns != nullptr) { if (ns->href != nullptr) { mNamespace = (char *)ns->href; } if (ns->prefix != nullptr) { mPrefix = (char *)ns->prefix; if(mType.length() > 0) mType = mType.substr(mPrefix.length() + 1); } } } }
Enumeration* DeclarationContext::FindEnum(const std::string& Name, bool Create) { auto entries = split<std::string>(Name, "::"); if (entries.size() == 1) { auto foundEnum = std::find_if(Enums.begin(), Enums.end(), [&](Enumeration* _enum) { return _enum->Name == Name; }); if (foundEnum != Enums.end()) return *foundEnum; if (!Create) return nullptr; auto _enum = new Enumeration(); _enum->Name = Name; _enum->_Namespace = this; Enums.push_back(_enum); return _enum; } auto enumName = entries[entries.size() - 1]; std::vector<std::string> namespaces; std::copy_n(entries.begin(), entries.size() - 1, std::back_inserter(namespaces)); auto _namespace = FindNamespace(namespaces); if (!_namespace) return nullptr; return _namespace->FindEnum(enumName, Create); }
Class* DeclarationContext::FindClass(const std::string& Name) { if (Name.empty()) return nullptr; auto entries = split<std::string>(Name, "::"); if (entries.size() == 1) { auto _class = std::find_if(Classes.begin(), Classes.end(), [&](Class* klass) { return klass->Name == Name; }); return _class != Classes.end() ? *_class : nullptr; } auto className = entries[entries.size() - 1]; std::vector<std::string> namespaces; std::copy_n(entries.begin(), entries.size() - 1, std::back_inserter(namespaces)); auto _namespace = FindNamespace(namespaces); if (!_namespace) return nullptr; return _namespace->FindClass(className); }
Namespace* DeclarationContext::FindCreateNamespace(const std::string& Name) { auto _namespace = FindNamespace(Name); if (!_namespace) { _namespace = new Namespace(); _namespace->Name = Name; _namespace->_Namespace = this; Namespaces.push_back(_namespace); } return _namespace; }