pelican/utility/src/Config.cpp
/**
 * @details
 * Returns a QDomElement at the specified address in the given document.
 * The element returned is null if the address doesn't exist.
 *
 * @param[in] address The address of the configuration node to get.
 *
 * @return A QDomElement at the address specified in the argument.
 */
@details
Returns a QDomElement at the specified address in the given document.
The element returned is null if the address doesn't exist.

@param[in] address The address of the configuration node to get.

@return A QDomElement at the address specified in the argument.
@details Returns a QDomElement at the specified address in the given document . The element returned is null if the address doesn ' t exist . @param [ in ] address The address of the configuration node to get . @return A QDomElement at the address specified in the argument .
QDomElement Config::_get(const TreeAddress &address, const QDomDocument& document) const
{
    QDomElement parent = document.documentElement();
    if (parent.isNull())
        return QDomElement();
    int index = 0;
    if( address.at(0).first == parent.tagName() ) ++index;
    for (int a = index; a < address.size(); a++)
    {
        QString tag  = address.at(a).first;
        QString name = address.at(a).second;
        QDomNodeList children = parent.childNodes();
        QList<QDomNode> nodes;
        for (int i = 0; i < children.size(); i++) {
            if (children.at(i).toElement().tagName() == tag) {
                nodes << children.at(i);
            }
        }
        if (nodes.isEmpty())
        {
            return QDomElement();
        }
        else
        {
            int iNode = -1;
            for (int n = 0; n < nodes.size(); n++) {
                QString nodeName = nodes.at(n).toElement().attribute(QString("name"));
                if (nodeName == name)
                    iNode = n;
            }
            if (iNode == -1)
                return QDomElement();
            else
                parent = nodes.at(iNode).toElement();
        }
    }
    return parent;
}
QDomElement Config :: _get ( const TreeAddress & address , const QDomDocument & document ) const { QDomElement parent = document . documentElement ( ) ; if ( parent . isNull ( ) ) return QDomElement ( ) ; int index = 0 ; if ( address . at ( 0 ) . first == parent . tagName ( ) ) ++ index ; for ( int a = index ; a < address . size ( ) ; a ++ ) { QString tag = address . at ( a ) . first ; QString name = address . at ( a ) . second ; QDomNodeList children = parent . childNodes ( ) ; QList < QDomNode > nodes ; for ( int i = 0 ; i < children . size ( ) ; i ++ ) { if ( children . at ( i ) . toElement ( ) . tagName ( ) == tag ) { nodes << children . at ( i ) ; } } if ( nodes . isEmpty ( ) ) { return QDomElement ( ) ; } else { int iNode = -1 ; for ( int n = 0 ; n < nodes . size ( ) ; n ++ ) { QString nodeName = nodes . at ( n ) . toElement ( ) . attribute ( QString ( " " ) ) ; if ( nodeName == name ) iNode = n ; } if ( iNode == -1 ) return QDomElement ( ) ; else parent = nodes . at ( iNode ) . toElement ( ) ; } } return parent ; }
@details
 Returns a QDomElement at the specified address in the given document.
@details Returns a QDomElement at the specified address in the given document .
// Empty configuration, so return null element. // addresses can refer from the top node, or one level below the // top node. Need to check which one. // Find child nodes of the specified tag type. // No node exists of the specified tag. //            cerr << "Config::_get(): No node exists." << endl; //            cerr << "tag = '" << tag.toStdString() << "'" << endl; //            cerr << "name = '" << name.toStdString() << "'" << endl; //            cerr << "parent = '" << parent.tagName().toStdString() << "'"<< endl; //            cerr << endl; // Nodes exist of the specified tag; find the right one to return. // Find if the tag already exists with the name. // Check if no tag exists with the name. // Tag exists - move the parent pointer.