Example #1
0
vector<ASTNode*> ASTNode::getChildren(const string &key) {
    vector<ASTNode*> subset;

    if (m_children.size() > 0) {
        string keyLC = key;

        // Transform key name to lower case for case insensitive lookups.
        transform(keyLC.begin(), keyLC.end(), keyLC.begin(), ptr_fun(::tolower));

        vector<ASTNode*>::iterator it = m_children.begin();
        while (it != m_children.end()) {
            ASTNode *n = (*it++);
            string nodeKey = n->getKey();

            // Transform key name to lower case for case insensitive lookups.
            transform(nodeKey.begin(), nodeKey.end(), nodeKey.begin(), ptr_fun(::tolower));

            // Try to match the key.
            if (keyLC == nodeKey) {
                subset.push_back(n);
            }
        }
    }

    return subset;
}
Example #2
0
void ASTNode::printKeys() const {
    vector<ASTNode*>::const_iterator it = m_children.begin();
    while (it != m_children.end()) {
        ASTNode *n = (*it++);
        clog << "Key: " << n->getKey() << endl;
    }
}
        Object SITSituationVisitor::visitObject(ASTNode *node) {
            Object o;

            if (node != NULL) {
                ASTNode *n = NULL;

                n = node->getNodeFromFirstMatchingChildFor("OBJECT");
                if (n == NULL) {
                    OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get value from OBJECT expected.");
                }
                o.setName(n->getValue<string>());

                n = node->getNodeFromFirstMatchingChildFor("OBJECTID");
                if (n == NULL) {
                    OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get value from OBJECTID expected.");
                }
                o.setID(n->getValue<uint32_t>());

                // Parse shape from child.
                vector<ASTNode*> listOfChildren = node->getChildren("OBJECTID");
                vector<ASTNode*>::iterator it = listOfChildren.begin() + 1; // Skip first OBJECTID.
                while (it != listOfChildren.end()) {
                    ASTNode *child = (*it++)->getFirstChild();
                    if (child != NULL) {
                        if (child->getKey() == "SHAPENAME") {
                            Shape *shape = visitShape(child->getParent());
                            o.setShape(shape);
                        }
                    }
                }

                n = node->getNodeFromFirstMatchingChildFor("ROTZ");
                if (n == NULL) {
                    OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get value from ROTZ expected.");
                }
                o.setRotationZ(n->getValue<double>());

                n = *(node->getChildren("ROTZ").begin() + 1); // BEHAVIOR starts directly after ROTZ.
                if (n == NULL) {
                    OPENDAVINCI_CORE_THROW_EXCEPTION(SITSituationVisitorException, "Node to get value from BEHAVIOR expected.");
                }
                o.setBehavior(visitBehavior(n));
            }

            return o;
        }