Exemple #1
0
xmlNode* retrieveElement(xmlDoc* doc, xmlNode* node, char* tag) {
    xmlNode* cur_node = NULL;
    xmlNode* found_it = NULL;
    //int debug = 1;
    for(cur_node = node; cur_node; cur_node = cur_node->next) {
        if(found_it!=NULL) {
            if(DEBUG>3) printf("[ retrieveElement ]: stop at cur_node %s prev %s  \n",cur_node->name,cur_node->prev->name);
            break;
        }
        if(DEBUG>3) printf("[ retrieveElement ]: Looking for %s and comparing to %s\n",tag,cur_node->name);
        if( (!xmlStrcmp(cur_node->name,(const xmlChar*)tag)) ) {
            if(DEBUG>3) printf("[ retrieveElement ]: found an element of type %d\n",cur_node->type);
            if (cur_node->type == XML_ELEMENT_NODE) {
                if(DEBUG>3) printf("[ retrieveElement ]: found it\n");
                found_it = cur_node;
                break;
            }
        }

        if(found_it!=NULL) {
            if(DEBUG>3) printf("[ retrieveElement ]: found it at name %s \n",cur_node->name);
            return found_it;
        }

        found_it = retrieveElement(doc,cur_node->children,tag);

    }

    return found_it;
}
    /*!
     * Returns the element for the pair (p1, p2), either by retrieving an
     * existing element (see \ref retrieveElement) or by creating a new one, if
     * no element for that pair exists yet.
     *
     * \return Either the value of \ref retrieveElement or a new element for
     * (p1,p2), if \ref retrieveElement returns NULL.
     */
    CollisionCacheElement* CollisionCache::retrieveOrAddElement(Proxy* p1, Proxy* p2) {
        if (!p1) {
            throw NullPointerException("p1");
        }
        if (!p2) {
            throw NullPointerException("p2");
        }

        CollisionCacheElement* element = retrieveElement(p1, p2);
        if (element) {
            return element;
        }

        element = new CollisionCacheElement(p1, p2);

        element->mCachePosition1 = mMap.insert(std::make_pair(p1, element));

        //insert the second element only for non-selfcollisions
        if (p1 != p2) {
            element->mCachePosition2 = mMap.insert(std::make_pair(p2, element));
        } else {
            element->mCachePosition2 = element->mCachePosition1;
        }

        return element;
    }
    /*!
     * Apply the cache to the \ref Pipeline, i.e. make sure that the \ref
     * WorldCollisions object of the current collision run will contain the
     * information stored in the cache for the (toplevel-)proxy pair (p1,p2).
     *
     * Note that \p p1 and \p p2 must be toplevel proxies, see \ref
     * Proxy::getToplevelProxy
     *
     * This method uses \ref Pipeline::processCollisionCacheElement to perform
     * its actual task.
     */
    bool CollisionCache::applyCacheIfAvailable(Proxy* p1, Proxy* p2) {
        CollisionCacheElement* element = retrieveElement(p1, p2);
        if (!element) {
            return false;
        }

        mPipeline->processCollisionCacheElement(element);

        return true;
    }
Exemple #4
0
static Element *
newElement (Queue *queue, void *item) {
  Element *element;

  if (!(element = retrieveElement())) {
    if (!(element = malloc(sizeof(*element)))) {
      logMallocError();
      return NULL;
    }

    element->previous = element->next = NULL;
  }

  addElement(queue, element);
  element->item = item;
  return element;
}
Exemple #5
0
static Element *
newElement (Queue *queue, void *item) {
    Element *element;

    if (!(element = retrieveElement())) {
        if (!(element = malloc(sizeof(*element)))) {
            logMallocError();
            return NULL;
        }

        element->previous = element->next = NULL;
    }

    {
        static int identifier = 0;
        element->identifier = ++identifier;
    }

    element->queue = queue;
    queue->size++;

    element->item = item;
    return element;
}
Exemple #6
0
void retrieveValue(xmlDoc* doc, xmlNode* node, char* tags, char value[], const unsigned int MAX) {
    xmlChar* value_str = NULL;
    char* pch;
    char* pch_prev=NULL;
    xmlNode* cur_node = NULL;
    xmlNode* prev_node = node;
    //use a copy since it modifies the original string
    //char* tags = (char*)malloc(strlen(tags)*sizeof(char));
    //strcpy(tags,tags);
    if(DEBUG>0) printf("[ retrieveValue ]: for tag \"%s\"\n",tags);
    if(strlen(tags)>0) {
        pch = strtok(tags," :,.-");
        while(pch!=NULL) {
            if(DEBUG>2) printf("[ retrieveValue ]: Find element %s \n",pch);
            if(pch_prev!=NULL) {
                if(DEBUG>2) printf("[ retrieveValue ]: Find element %s from children of prev element at %p\n",pch,prev_node->name);
                cur_node = retrieveElement(doc,prev_node->children,pch);
            }
            else {
                if(DEBUG>2) printf("[ retrieveValue ]: Find element %s from element %s\n",pch,prev_node->name);
                cur_node = retrieveElement(doc,prev_node,pch);
            }

            // check that we found it
            if(cur_node != NULL) {
                if(DEBUG>2) printf("[ retrieveValue ]: found cur_node name %s\n",cur_node->name);
            } else {
                if(DEBUG>2) printf("[ retrieveValue ]: couldn't find cur_node\n");
                break;
            }

            pch_prev = pch;
            prev_node = cur_node;
            pch = strtok(NULL," :,.");
        }

        //if there is a node at the end it means we should get it's list of strings
        // if it's not the lowest level it might returns some garbage -> FIX THIS!
        if(cur_node !=NULL) {
            value_str  = xmlNodeListGetString(doc,cur_node->children,0);
            if(value_str!=NULL) {
                if(DEBUG>2) printf("[ retrieveValue ]: Found value %s\n",value_str);
                if(strlen((char*) value_str)>=MAX) {
                    if(DEBUG>2) printf("[ retrieveValue ]: the value for tags=%s is %d i.e. larger than MAX=%d, return no value!\n",tags,strlen((char*)value_str),MAX);
                    value_str = NULL;
                } else {
                    if(DEBUG>2) printf("[ retrieveValue ]: copy the value_str=\"%s\" (%d) to %p\n",value_str,strlen((char*)value_str),value);
                    strcpy((char*)value,(char*)value_str);
                }
            } else {
                value_str = NULL;
                if(DEBUG>2) printf("[ retrieveValue ]: Found no value for tags %s\n",tags);
            }
        } else {
            value_str = NULL;
            if(DEBUG>2) printf("[ retrieveValue ]: cur_node is null so no value found for tags=%s\n",tags);
        }
    }
    if(value_str!=NULL) {
        if(DEBUG>1) printf("[ retrieveValue ]: free value_str\n");
        xmlFree(value_str);
    }
}