Instances::Instances(const string &name, std::vector<Attribute*> &attInfo, const int capacity) { // check whether the attribute names are unique std::unordered_set<string> attr_names; string nonUniqueNames = ""; for (auto att : attInfo) { if (std::find(attr_names.begin(), attr_names.end(), att->name()) != attr_names.end()) { nonUniqueNames.append(string("'") + att->name() + string("' ")); } attr_names.insert(att->name()); } if (attr_names.size() != attInfo.size()) { throw std::invalid_argument(string("Attribute names are not unique!") + string(" Causes: ") + nonUniqueNames); } attr_names.clear(); mRelationName = name; mClassIndex = -1; mAttributes = attInfo; mNamesToAttributeIndices = std::unordered_map<string, int>(static_cast<int>(numAttributes() / 0.75)); for (int i = 0; i < numAttributes(); i++) { attribute(i).setIndex(i); mNamesToAttributeIndices[(attribute(i)).name()] = i; } mInstances = std::vector<Instance*>(capacity); }
UXMLAttribute* UXMLElement::getAttribute(const UString& attributeName) { U_TRACE(0, "UXMLElement::getAttribute(%.*S)", U_STRING_TO_TRACE(attributeName)) uint32_t n = numAttributes(); if (n) { UXMLAttribute* entry; UString szAccessor, szNamespace; splitNamespaceAndName(attributeName, szNamespace, szAccessor); for (uint32_t i = 0; i < n; ++i) { entry = attributeAt(i); if ((entry->getAccessor() == attributeName) && (szNamespace.empty() || (entry->getNamespaceName() == szNamespace))) { // We found the attribute U_RETURN_POINTER(entry, UXMLAttribute); } } } U_RETURN_POINTER(0, UXMLAttribute); }
void Instances::setClassIndex(const int classIndex) { if (classIndex >= numAttributes()) { throw string("Invalid class index: ") + std::to_string(classIndex); } mClassIndex = classIndex; }
void Reader::dumpNode(bsl::ostream & os) const { const char *name = nodeName(); const char *value = nodeValue(); const char *nsUri = nodeNamespaceUri(); int line = getLineNumber(); int column = getColumnNumber(); int depth = nodeDepth(); NodeType type = nodeType(); bsl::string strPad((bsl::string::size_type)depth*2, ' '); os << strPad << "Node pos=" << line << ":" << column << " type=" << type << "(" << nodeTypeAsString(type) << ") empty=" << isEmptyElement() << " hasValue=" << nodeHasValue() << " name=" << CHK(name) << " value=" << CHK(value) << " uri=" << CHK(nsUri) << bsl::endl; int numAttr = numAttributes(); for (int i = 0; i < numAttr; ++i) { ElementAttribute attr; lookupAttribute(&attr, i); os << strPad << " ATTRIBUTE " << CHK(attr.qualifiedName()) << "=" << CHK(attr.value()) << " uri=" << CHK(attr.namespaceUri()) << bsl::endl; } }