void CElement::listChildren(string& strChildList) const { strChildList = "\n"; // Get list of children names uint32_t uiNbChildren = getNbChildren(); uint32_t uiChild; for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { const CElement* pChild = _childArray[uiChild]; strChildList += pChild->getName() + "\n"; } }
// Memory uint32_t CConfigurableElement::getFootPrint() const { uint32_t uiSize = 0; uint32_t uiIndex; uint32_t uiNbChildren = getNbChildren(); for (uiIndex = 0; uiIndex < uiNbChildren; uiIndex++) { const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(getChild(uiIndex)); uiSize += pConfigurableElement->getFootPrint(); } return uiSize; }
// List available criteria void CSelectionCriteriaDefinition::listSelectionCriteria(std::list<std::string> &lstrResult, bool bWithTypeInfo, bool bHumanReadable) const { // Propagate size_t uiNbChildren = getNbChildren(); size_t uiChild; for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { const CSelectionCriterion *pSelectionCriterion = static_cast<const CSelectionCriterion *>(getChild(uiChild)); lstrResult.push_back( pSelectionCriterion->getFormattedDescription(bWithTypeInfo, bHumanReadable)); } }
// Offset void CConfigurableElement::setOffset(uint32_t uiOffset) { // Assign offset locally _uiOffset = uiOffset; // Propagate to children uint32_t uiIndex; uint32_t uiNbChildren = getNbChildren(); for (uiIndex = 0; uiIndex < uiNbChildren; uiIndex++) { CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(getChild(uiIndex)); pConfigurableElement->setOffset(uiOffset); uiOffset += pConfigurableElement->getFootPrint(); } }
void CTypeElement::populate(CElement *pElement) const { // Populate children size_t uiChild; size_t uiNbChildren = getNbChildren(); for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { const CTypeElement *pChildTypeElement = static_cast<const CTypeElement *>(getChild(uiChild)); CInstanceConfigurableElement *pInstanceConfigurableChildElement = pChildTypeElement->instantiate(); // Affiliate pElement->addChild(pInstanceConfigurableChildElement); } }
bool CSubsystem::mapSubsystemElements(string& strError) { // Default mapping context _contextStack.push(CMappingContext(_contextMappingKeyArray.size())); // Map all instantiated subelements in subsystem uint32_t uiNbChildren = getNbChildren(); uint32_t uiChild; for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild)); if (!pInstanceConfigurableChildElement->map(*this, strError)) { return false; } } return true; }
// From IXmlSource void CElement::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Browse children and propagate uint32_t uiNbChildren = getNbChildren(); uint32_t uiChild; for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { const CElement* pChild = _childArray[uiChild]; // Create corresponding child element CXmlElement xmlChildElement; xmlElement.createChild(xmlChildElement, pChild->getKind()); // Set attributes pChild->setXmlNameAttribute(xmlChildElement); // Propagate pChild->toXml(xmlChildElement, serializingContext); } }
bool CInstanceConfigurableElement::map(IMapper& mapper, std::string& strError) { bool bHasMappingData = getTypeElement()->hasMappingData(); bool bKeepDiving = true; // Begin if (bHasMappingData && !mapper.mapBegin(this, bKeepDiving, strError)) { return false; } // Go on through children? if (bKeepDiving) { // Map children size_t uiNbChildren = getNbChildren(); size_t uiChild; for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild)); if (!pInstanceConfigurableChildElement->map(mapper, strError)) { return false; } } } // End if (bHasMappingData) { mapper.mapEnd(); } return true; }
string CElement::listQualifiedPaths(bool bDive, uint32_t uiLevel) const { uint32_t uiNbChildren = getNbChildren(); string strResult; // Dive Will cause only leaf nodes to be printed if (!bDive || !uiNbChildren) { strResult = getQualifiedPath() + "\n"; } if (bDive || !uiLevel) { // Get list of children paths uint32_t uiChild; for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { const CElement* pChild = _childArray[uiChild]; strResult += pChild->listQualifiedPaths(bDive, uiLevel + 1); } } return strResult; }
// XML configuration settings parsing bool CConfigurableElement::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const { uint32_t uiIndex; uint32_t uiNbChildren = getNbChildren(); if (!configurationAccessContext.serializeOut()) { // Just do basic checks and propagate to children CXmlElement::CChildIterator it(xmlConfigurationSettingsElementContent); CXmlElement xmlChildConfigurableElementSettingsElement; // Propagate to children for (uiIndex = 0; uiIndex < uiNbChildren; uiIndex++) { // Get child const CConfigurableElement* pChildConfigurableElement = static_cast<const CConfigurableElement*>(getChild(uiIndex)); if (!it.next(xmlChildConfigurableElementSettingsElement)) { // Structure error configurationAccessContext.setError("Configuration settings parsing: Settings don't conform to structure of configurable element " + getName()); return false; } // Check element type matches in type if (xmlChildConfigurableElementSettingsElement.getType() != pChildConfigurableElement->getKind()) { // Type error configurationAccessContext.setError("Configuration settings parsing: Settings for configurable element " + pChildConfigurableElement->getName() + " does not match expected type: " + xmlChildConfigurableElementSettingsElement.getType() + " instead of " + pChildConfigurableElement->getKind()); return false; } // Check element type matches in name if (xmlChildConfigurableElementSettingsElement.getNameAttribute() != pChildConfigurableElement->getName()) { // Name error configurationAccessContext.setError("Configuration settings parsing: Under configurable elememnt " + getName() + ", expected element name " + pChildConfigurableElement->getName() + " but found " + xmlChildConfigurableElementSettingsElement.getNameAttribute() + " instead"); return false; } // Parse child configurable element's settings if (!pChildConfigurableElement->serializeXmlSettings(xmlChildConfigurableElementSettingsElement, configurationAccessContext)) { return false; } } // There should remain no configurable element to parse if (it.next(xmlChildConfigurableElementSettingsElement)) { // Structure error configurationAccessContext.setError("Configuration settings parsing: Settings don't conform to structure of configurable element " + getName()); return false; } } else { // Propagate to children for (uiIndex = 0; uiIndex < uiNbChildren; uiIndex++) { const CConfigurableElement* pChildConfigurableElement = static_cast<const CConfigurableElement*>(getChild(uiIndex)); // Create corresponding child element CXmlElement xmlChildConfigurableElementSettingsElement; xmlConfigurationSettingsElementContent.createChild(xmlChildConfigurableElementSettingsElement, pChildConfigurableElement->getKind()); // Handle element name attribute xmlChildConfigurableElementSettingsElement.setNameAttribute(pChildConfigurableElement->getName()); // Propagate pChildConfigurableElement->serializeXmlSettings(xmlChildConfigurableElementSettingsElement, configurationAccessContext); } } // Done return true; }