const Attr* NeedAttr (const Collection* C, const char* Name, const char* Op) /* Search for an attribute with the given name and return it. If the attribute * is not found, the function terminates with an error using Op as additional * context in the error message. */ { /* Search for the attribute and return it */ unsigned Index; if (!FindAttr (C, Name, &Index)) { Error ("Found no attribute named `%s' for operation %s", Name, Op); } return CollConstAt (C, Index); }
const Attr* GetAttr (const Collection* C, const char* Name) /* Search for an attribute with the given name and return it. The function * returns NULL if the attribute wasn't found. */ { /* Search for the attribute and return it */ unsigned Index; if (FindAttr (C, Name, &Index)) { return CollConstAt (C, Index); } else { /* Not found */ return 0; } }
void AddAttr (Collection* C, const char* Name, const char* Value) /* Add an attribute to an alphabetically sorted attribute collection */ { /* Create a new attribute entry */ Attr* A = NewAttr (Name, Value); /* Search for the attribute. If it is there, we have a duplicate, otherwise * we have the insert position. */ unsigned Index; if (FindAttr (C, Name, &Index)) { Error ("Duplicate command line attribute `%s'", Name); } /* Insert the attribute */ CollInsert (C, A, Index); }
void CSenPropertiesElement::CopyFromL(CSenElement& aSource) { TPtrC8 sourceContent = aSource.Content(); if (sourceContent.Length() > 0) { SetContentL(sourceContent); } RPointerArray<CSenElement> sourceElements = aSource.ElementsL(); if (sourceElements.Count() > 0) { for (TInt i=0;i<sourceElements.Count(); i++) { CSenElement* pElement = sourceElements[i]; CSenElement* pNewElement = CSenPropertiesElement::NewL(pElement->LocalName(), ipStringPool); pNewElement->CopyFromL(*pElement); CSenXmlElement::AddElementL(*pNewElement); } } RPointerArray<CSenBaseAttribute> sourceAttributes = aSource.AttributesL(); if (sourceAttributes.Count() > 0) { for (TInt i=0;i<sourceAttributes.Count(); i++) { CSenBaseAttribute* pBaseAttribute = sourceAttributes[i]; // 2005-04-28: check for duplicate and override existing value if // attribute already exists. CSenBaseAttribute* pOriginal = FindAttr(pBaseAttribute->Name()); if (pOriginal) { pOriginal->SetValueL(pBaseAttribute->Value()); continue; } CSenBaseAttribute* pNewBaseAttribute = CSenBaseAttribute::NewL(pBaseAttribute->Name(), pBaseAttribute->Value()); CSenXmlElement::AddAttributeL(pNewBaseAttribute); } } RPointerArray<CSenNamespace> sourceNamespaces = aSource.NamespacesL(); if (sourceNamespaces.Count() > 0) { for (TInt i=0;i<sourceNamespaces.Count(); i++) { CSenNamespace* pNamespace = sourceNamespaces[i]; CSenNamespace* pNewNamespace = CSenNamespace::NewL(pNamespace->Prefix(),pNamespace->URI()); CleanupStack::PushL(pNewNamespace); CSenXmlElement::AddNamespaceL(*pNewNamespace, EFalse); CleanupStack::Pop(); } } SetNamespaceL(aSource.NamespaceURI()); }