void polyPrint2(double a[], int n) { int i; int first=1; //adjust n for actual integer value n--; //first checks to make sure array is not empty if (checkifempty(a, n)) { for (i = n; i >= 0; i--) { //if the value is 0 or 1, dont print it if (a[i] != 1 && fabs(a[i]) >= 0) { // if the value is greater than 0 than print it if (a[i] < 0 && i==n && first) { printf("-"); first=0; } if (fabs(a[i]) > 0&&a[i]!=-1) { printf("%g", fabs(a[i])); } } // if the number has a greater exponent than 1 and value isnt 0 if (i > 1 && a[i] != 0) { printf("x^%d", i); } else if (i == 1) { //the cases if the value is x with exponent of 1 if (a[i] == 0) continue; else { printf("x"); } } //handle placing signs if (i > 0 &&a[i]!=0) { //if it isnt empty than print accorind to the next sign if (a[nextElement(a, i)] < 0) printf(" - "); else if (a[nextElement(a, i)] > 0) printf(" + "); else break; i = nextElement(a, i)+1; } } } else printf("0"); //newline after creating polynomial printf("\n"); }
int nextElementValue(char *name, FILE *fp) { unsigned int value; nextElement(name, fp); fscanf(fp, "%u", &value); reachChar('>', fp); return value; }
void Carousel::handleZoomAnimationEvent(const ZoomAnimationImage& element) { if (currentAnimation == ANIMATE_LEFT) { // Reset the order of the visible elements remove(visibleElements[4]); insert(&visibleElements[2], visibleElements[4]); setSelectedElement(nextElement(selectedElement)); } else if (currentAnimation == ANIMATE_RIGHT) { // Reset the order of the visible elements remove(visibleElements[2]); insert(&visibleElements[5], visibleElements[2]); setSelectedElement(prevElement(selectedElement)); } else if (currentAnimation == ANIMATE_ELEMENT_SELECTED) { } currentAnimation = NO_ANIMATION; if (carouselAnimationEndedAction && carouselAnimationEndedAction->isValid()) { carouselAnimationEndedAction->execute(*this); } }
Vertex readVertex(FILE *fp, Edge *ep, int numberOfEdges, EdgePointer *EdgePointerStart) { static int EdgePointerCount = 0; Vertex v; memset(&v, 0, sizeof(v)); char buf[BIG_BUFFER]; memset(buf, 0, BIG_BUFFER); int value; nextElement(buf, fp); if (strcmp(buf, "vertex")) error(); v.vertexId = nextElementValue(buf, fp); memset(buf, 0 , BIG_BUFFER); nextElement(buf, fp); if (strcmp(buf, "coord")) error(); v.x = nextElementValue(buf, fp); v.y = nextElementValue(buf, fp); nextElement(buf, fp); memset(buf, 0, BIG_BUFFER); nextElement(buf, fp); if (strcmp(buf, "edges")) error(); while (1) { memset(buf, 0, BIG_BUFFER); value = nextElementValue(buf, fp); if (strcmp(buf, "edgeId") == 0) { Edge *edgeP = getEp(ep, value, numberOfEdges); assignEdge(&(v.ep), &EdgePointerStart[EdgePointerCount++], edgeP); } else break; } getFloorAndtype(v.vertexId , (int *) & (v.floorId) , (int *) & (v.type)); return v; }
//vygeneruje XML subor bool generateXML(Car *car, int n) { FILE *xmlOut = fopen("cars.xml", "w"); int i; if (xmlOut != NULL) { fprintf(xmlOut, "<?xml version=\"1.0\" encoding=\"UTF - 8\"?>\n"); fprintf(xmlOut, "<cars>\n"); for (i = 0; i < n; i++) { fprintf(xmlOut, "\n\t<car id=%d>\n", i + 1); //item start nextElement(xmlOut, "type", car[i].type, "brand", car[i].brand, 2); //brand & type nextElement(xmlOut, "color", getColor(car[i].color), NULL, NULL, 2); //color nextElement(xmlOut, "year", getYear(car[i].year),NULL,NULL,2); //year char temp[2]; //fuel temp[0] = car[i].fuel; temp[1] = '\0'; nextElement(xmlOut, "fuel", temp, NULL, NULL, 2); //date char **tags = (char**)malloc(sizeof(char*) * 3); //tags tags[0] = (char*)malloc(sizeof(char) * 4); strcpy(tags[0], "day\0"); tags[1] = (char*)malloc(sizeof(char) * 6); strcpy(tags[1], "month\0"); tags[2] = (char*)malloc(sizeof(char) * 5); strcpy(tags[2], "year\0"); char **values = (char**)malloc(sizeof(char*) * 3); //values values[0] = (char*)malloc(sizeof(char) * (strlen(getDay(car[i].evidDate.day)) + 1)); strcpy(values[0], getDay(car[i].evidDate.day)); values[1] = (char*)malloc(sizeof(char) * (strlen(getMonth(car[i].evidDate.month)) + 1)); strcpy(values[1], getMonth(car[i].evidDate.month)); values[2] = (char*)malloc(sizeof(char) * (strlen(getYear(car[i].evidDate.year)) + 1)); strcpy(values[2], getYear(car[i].evidDate.year)); nextStructElement(xmlOut, "date", tags, values, 3, NULL, NULL, 2); nextElement(xmlOut, "plate", car[i].licansePlate, NULL, NULL, 2); //licanse plate fprintf(xmlOut, "\t<performance>%d KW</performance>\n", car[i].performance); //performance fprintf(xmlOut, "\t<driven>%d km</driven>\n", car[i].driven); //driven fprintf(xmlOut, "\t</car>\n"); //item end } fprintf(xmlOut, "\n</cars>\n"); return true; } return false; }
/*! @brief Free Objects related to VariableArray */ void VariableArrayCursor::finalize() { reset(); if (getBaseOId() != UNDEF_OID) { while (nextElement(true)) { ; } } }
void readEdges(FILE *fp, Edge *edges, int numberOfEdges) { char buf[MEDIUM_BUFFER]; memset(buf, 0, MEDIUM_BUFFER); nextElement(buf, fp); int i; if (strcmp(buf, "edges")) error(); for (i = 0; i < numberOfEdges; i++) { edges[i] = readEdge(fp); } nextElement(buf, fp); }
void ClassGenerator::generate() { BaseCodegenerator::generate(); // ++index; nextElement(); }
void m_read() { m_ok = (m_enumeration && m_enumeration->hasMoreElements()) ? true : false; if (m_ok) { m_enumeration->nextElement(m_value); } }
void readvertices(FILE *fp, Vertex *vertices, int numberOfvertices, Edge *ep, int numberOfEdges) { char buf[MEDIUM_BUFFER]; memset(buf, 0, MEDIUM_BUFFER); nextElement(buf, fp); int i; EdgePointer *EdgePointerStart = (EdgePointer *)(vertices + numberOfvertices); if (strcmp(buf, "vertices")) error(); for (i = 0; i < numberOfvertices; i++) { vertices[i] = readVertex(fp, ep, numberOfEdges, EdgePointerStart); } nextElement(buf, fp); }
Graph *readXml(FILE *fp) { Floor *floors; char c = 0; char buf[SMALL_BUFFER]; int edgesCount, verticesCount, floorsCount; while ((c = getc(fp)) != EOF) { if (c == '<') break; } fscanf(fp, "%6s", buf); if (strcmp(buf, "graph")) { error(); return NULL; } readDefaultAtributes(&edgesCount, &verticesCount, &floorsCount, fp); unsigned long amountToAlloc = sizeof(Graph) + floorsCount * sizeof(Floor) + verticesCount * sizeof(Vertex) + edgesCount * sizeof(Edge) + edgesCount * 2 * sizeof(EdgePointer); Graph *graph = malloc(amountToAlloc); memset(graph, 0, amountToAlloc); floors = (void *)(graph + 1); Edge *edges = (Edge *)(floors + floorsCount); Vertex *vertices = (Vertex *)(edges + edgesCount); reachChar('>', fp); readEdges(fp, edges, edgesCount); readvertices(fp, vertices, verticesCount, edges, edgesCount); nextElement(buf, fp); if (strcmp(buf, "graph")) error(); crawlEdges(&edges, vertices, edgesCount, verticesCount); crawVertices(&vertices, verticesCount, &floors); crawlFloors(&floors, vertices, floorsCount, verticesCount); graph->numOfVertices = verticesCount; graph->numOfFloors = floorsCount; graph->floors = floors; return graph; }
void nextStructElement(FILE *file, char *root_tag, char **child, char **values, int n, char *att, char *attValue, int step) { level(file,step); fprintf(file, "<%s ", root_tag); if (att != NULL && attValue != NULL) { fprintf(file, "%s=%s", att, attValue); } fprintf(file, ">\n"); int i = 0; for (i; i < n; i++) { nextElement(file, child[i], values[i], NULL, NULL, step + 1); } level(file, step); fprintf(file, "</%s>\n", root_tag); }
virtual void endElementEvent(const XMLCh *prefix, const XMLCh *uri, const XMLCh *localname, const XMLCh *typeURI, const XMLCh *typeName) { assert(node_ && node_->getNodeType() == DOMNode::ELEMENT_NODE); // Copy the element's type const XMLCh *oldTypeURI, *oldTypeName; XercesNodeImpl::typeUriAndName(node_, oldTypeURI, oldTypeName); if(!XPath2Utils::equals(oldTypeName, typeName) || !XPath2Utils::equals(oldTypeURI, typeURI)) { XercesSequenceBuilder::setElementTypeInfo((DOMElement *)node_, typeURI, typeName); } child_ = node_; node_ = node_->getParentNode(); child_ = nextElement(child_->getNextSibling()); }
void Carousel::updateVisibleElements() { // Update the visibleElements to match the new selected element uint8_t currentElement = prevElement(prevElement(prevElement(selectedElement))); for (uint8_t i = 0; i < NUMBER_OF_VISIBLE_ELEMENTS; i++) { visibleElements[i].setBitmaps(elements[currentElement].smallBmp, elements[currentElement].mediumBmp, elements[currentElement].largeBmp); visibleElements[i].setPosition(visibleElementPositions[i].x, visibleElementPositions[i].y, visibleElementPositions[i].width, visibleElementPositions[i].height); visibleElements[i].setAlpha(255); visibleElements[i].invalidate(); currentElement = nextElement(currentElement); } // The two elements in the end should be ready to be faded in when // animation starts visibleElements[0].setAlpha(0); visibleElements[NUMBER_OF_VISIBLE_ELEMENTS-1].setAlpha(0); }
void Menu::input() { InputHandler* input = InputHandler::getInstance(); if (!once){ //AudioManager::instance()->PlayGameSound("menuSong", false, 1, Vector2D(0, 0), 1); once = true; } if (m_state == MENUSTATE::READY) { if (input->isPressed(InputHandler::DPAD_DOWN)) { AudioManager::instance()->PlayGameSound("select", false, 0.3f, m_curr->getPosition(), 1); nextElement(); } else if (input->isPressed(InputHandler::DPAD_UP)) { AudioManager::instance()->PlayGameSound("select", false, 0.3f, m_curr->getPosition(), 1); previousElement(); } else if (input->isPressed(InputHandler::DPAD_RIGHT)) { AudioManager::instance()->PlayGameSound("select", false, 0.3f, m_curr->getPosition(), 1); previousElement(); } else if (input->isPressed(InputHandler::DPAD_LEFT)) { AudioManager::instance()->PlayGameSound("select", false, 0.3f, m_curr->getPosition(), 1); previousElement(); } else if (input->isPressed(InputHandler::A)) { AudioManager::instance()->PlayGameSound("click", false, 0.3f, m_curr->getPosition(), 1); m_curr->invoke(); } } }
/*! @brief Get field value Object */ void VariableArrayCursor::getField( const ColumnInfo &columnInfo, BaseObject &baseObject) { uint32_t variableColumnNum = columnInfo.getColumnOffset(); uint32_t varColumnNth = 0; while (nextElement()) { ; if (varColumnNth == variableColumnNum) { break; } ++varColumnNth; } if (varColumnNth != variableColumnNum) { assert(false); GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_DS_PARAMETER_INVALID, "varColumnNth(" << varColumnNth << ") != variableColumnNum" << variableColumnNum); } baseObject.copyReference(curObject_.getBaseOId(), curObject_.getBaseAddr()); baseObject.moveCursor( curObject_.getCursor<uint8_t>() - curObject_.getBaseAddr()); }
void nextPartialSolution(enumeration * e, bags *bag, int method){ if ( terminated(e) != 0) { int obj = nextElement(e); switch(method){ case 1: addFirstFit(obj, bag); break; case 2: addNextFit(obj, bag); break; case 3: addBestFit(obj, bag); break; } }else{ printf("Plus d'objet. \n"); } }
int main(){ Lol a,b,*z; GenericField *k; Queue *fila; strcpy(a.c,"CASA1"); strcpy(b.c,"CASA2"); a.v=10; b.v=20; fila=createQueue(); insertElement(fila,&a,STRUCT1); insertElement(fila,&b,STRUCT1); do{ z=(Lol *)getFieldValue(getElement(fila)); if(z!=NULL){ printf("%d %s\n",z->v,z->c); } }while(nextElement(fila)==0); clearQueue(fila); getchar(); return 0; }
Edge readEdge(FILE *fp) { Edge ed; unsigned int value, i; char buf[BIG_BUFFER]; nextElement(buf, fp); for (i = 0; i < 4; i++) { memset(buf, 0, BIG_BUFFER); value = nextElementValue(buf, fp); if (strcmp(buf, "edgeId") == 0) ed.edgeId = value; if (strcmp(buf, "weight") == 0) ed.weight = value; if (strcmp(buf, "vertexId1") == 0) ed.vertex1 = (Vertex *)(long)value; if (strcmp(buf, "vertexId2") == 0) ed.vertex2 = (Vertex *)(long)value; } reachChar('>', fp); return ed; }
Element* Marker::prevElement() { //it's the same barline return nextElement(); }
/*! @brief Clone */ OId VariableArrayCursor::clone(TransactionContext &txn, const AllocateStrategy &allocateStrategy, OId neighborOId) { if (UNDEF_OID == getBaseOId()) { return UNDEF_OID; } OId currentNeighborOId = neighborOId; OId linkOId = UNDEF_OID; uint32_t srcDataLength = getArrayLength(); if (srcDataLength == 0) { uint8_t *srcObj = getBaseAddr(); Size_t srcObjSize = getObjectManager()->getSize(srcObj); BaseObject destObject(txn.getPartitionId(), *getObjectManager()); OId destOId = UNDEF_OID; if (currentNeighborOId != UNDEF_OID) { destObject.allocateNeighbor<uint8_t>(srcObjSize, allocateStrategy, destOId, currentNeighborOId, OBJECT_TYPE_VARIANT); } else { destObject.allocate<uint8_t>( srcObjSize, allocateStrategy, destOId, OBJECT_TYPE_VARIANT); } memcpy(destObject.getBaseAddr(), srcObj, srcObjSize); linkOId = destOId; } else { OId srcOId = UNDEF_OID; OId destOId = UNDEF_OID; OId prevOId = UNDEF_OID; uint8_t *srcObj = NULL; BaseObject destObject(txn.getPartitionId(), *getObjectManager()); uint8_t *srcElem; uint32_t srcElemSize; uint32_t srcCount; uint8_t *lastElem = NULL; uint32_t lastElemSize = 0; while (nextElement()) { srcObj = data(); srcOId = getElementOId(); srcElem = getElement(srcElemSize, srcCount); if (srcOId != prevOId) { Size_t srcObjSize = getObjectManager()->getSize(srcObj); if (currentNeighborOId != UNDEF_OID) { destObject.allocateNeighbor<uint8_t>(srcObjSize, allocateStrategy, destOId, currentNeighborOId, OBJECT_TYPE_VARIANT); } else { destObject.allocate<uint8_t>(srcObjSize, allocateStrategy, destOId, OBJECT_TYPE_VARIANT); } currentNeighborOId = destOId; memcpy(destObject.getBaseAddr(), srcObj, srcObjSize); if (UNDEF_OID == linkOId) { linkOId = destOId; } else { assert(lastElem > 0); uint8_t *linkOIdAddr = lastElem + lastElemSize + ValueProcessor::getEncodedVarSize(lastElemSize); uint64_t encodedOId = ValueProcessor::encodeVarSizeOId(destOId); memcpy(linkOIdAddr, &encodedOId, sizeof(uint64_t)); } prevOId = srcOId; } lastElem = destObject.getBaseAddr() + (srcElem - srcObj); lastElemSize = srcElemSize; } } return linkOId; }
Element* Jump::prevElement() { return nextElement(); }
Step *Step::nextStep() { const AbstractRangeElement *re = dynamic_cast<const AbstractRangeElement *>(this); return dynamic_cast<Step *>(nextElement(re)); }
daeElementRef daeLIBXMLPlugin::startParse(daeMetaElement* thisMetaElement, xmlTextReaderPtr reader) { // The original parsing system would drop everything up to the first element open, usually <COLLADA> // This behavior will have to be replicated here till we have someplace to put the headers/comments int ret = xmlTextReaderRead(reader); if(ret != 1) { // empty or hit end of file return NULL; } //printf("xmlTextReaderConstBaseUri is %s\n",xmlTextReaderConstBaseUri(reader)); //printf("xmlTextReaderConstNamespaceUri is %s\n",xmlTextReaderConstNamespaceUri(reader)); //printf("xmlTextReaderConstPrefix is %s\n",xmlTextReaderConstPrefix(reader)); //printf("xmlTextReaderName is %s\n",xmlTextReaderName(reader)); // Process the current element // Skip over things we don't understand while(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT) { ret = xmlTextReaderRead(reader); if(ret != 1) return(NULL); } // Create the element that we found daeElementRef element = thisMetaElement->create((const daeString)xmlTextReaderConstName(reader)); if(!element) { char err[256]; memset( err, 0, 256 ); const xmlChar * mine =xmlTextReaderConstName(reader); #if LIBXML_VERSION >= 20620 sprintf(err,"The DOM was unable to create an element type %s at line %d\nProbably a schema violation.\n", mine,xmlTextReaderGetParserLineNumber(reader)); #else sprintf(err,"The DOM was unable to create an element type %s\nProbably a schema violation.\n", mine); #endif daeErrorHandler::get()->handleWarning( err ); xmlTextReaderNext(reader); return NULL; } int currentDepth = xmlTextReaderDepth(reader); //try and read attributes readAttributes( element, reader ); //Check COLLADA Version if ( strcmp( element->getTypeName(), "COLLADA" ) != 0 ) { //invalid root daeErrorHandler::get()->handleError("Loading document with invalid root element!"); return NULL; } daeURI *xmlns = (daeURI*)(element->getMeta()->getMetaAttribute( "xmlns" )->getWritableMemory( element )); if ( strcmp( xmlns->getURI(), COLLADA_NAMESPACE ) != 0 ) { //invalid COLLADA version daeErrorHandler::get()->handleError("Trying to load an invalid COLLADA version for this DOM build!"); return NULL; } ret = xmlTextReaderRead(reader); // If we're out of data, return the element if(ret != 1) return(element); // Read all the tags that are part of this tag bool trew = true; while(trew) { int thisType = xmlTextReaderNodeType(reader); if(thisType == XML_READER_TYPE_ELEMENT) { // Is the new element at the same depth as this one? if(currentDepth == xmlTextReaderDepth(reader)) { // Same depth means the current element ended in a /> so this is a sibling // so we return and let our parent process it. return(element); } else { // The element is a child of this one, so we recurse if(!element->placeElement(nextElement(element->getMeta(), reader))) { char err[256]; memset( err, 0, 256 ); #if LIBXML_VERSION >= 20620 sprintf(err,"placeElement failed at line %d\n", xmlTextReaderGetParserLineNumber(reader)); #else sprintf(err,"placeElement failed\n"); #endif daeErrorHandler::get()->handleWarning(err); ret = xmlTextReaderRead(reader); if ( ret != 1 ) { return element; } } } } else if(thisType == XML_READER_TYPE_TEXT) { readValue( element, reader ); } else if(thisType == XML_READER_TYPE_END_ELEMENT) { // Done with this element so read again and return ret = xmlTextReaderRead(reader); return(element); } else { // Skip element types we don't care about ret = xmlTextReaderRead(reader); // If we're out of data, return the element if(ret != 1) return(element); } } // Return NULL on an error return NULL; }
virtual void startElementEvent(const XMLCh *prefix, const XMLCh *uri, const XMLCh *localname) { assert(child_ && child_->getNodeType() == DOMNode::ELEMENT_NODE); node_ = child_; child_ = nextElement(node_->getFirstChild()); }
void PrefabPlant::nextElement( const wstring & name, const wstring & prefix ) { nextElement(name); }
daeElementRef daeLIBXMLPlugin::nextElement(daeMetaElement* thisMetaElement, xmlTextReaderPtr reader) { int ret; // Process the current element // Skip over things we don't understand while(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT) { ret = xmlTextReaderRead(reader); if(ret != 1) return(NULL); } // Create the element that we found daeElementRef element = thisMetaElement->create((const daeString)xmlTextReaderConstName(reader)); if(!element) { const xmlChar * mine =xmlTextReaderConstName(reader); char err[256]; memset( err, 0, 256 ); #if LIBXML_VERSION >= 20620 sprintf(err,"The DOM was unable to create an element type %s at line %d\nProbably a schema violation.\n", mine,xmlTextReaderGetParserLineNumber(reader)); #else sprintf(err,"The DOM was unable to create an element type %s\nProbably a schema violation.\n", mine); #endif daeErrorHandler::get()->handleWarning( err ); if ( xmlTextReaderNext(reader) == -1 ) { int x = 12312412; } return NULL; } int currentDepth = xmlTextReaderDepth(reader); //try and read attributes readAttributes( element, reader ); ret = xmlTextReaderRead(reader); // If we're out of data, return the element if(ret != 1) return(element); // Read all the tags that are part of this tag bool trew = true; while(trew) { int thisType = xmlTextReaderNodeType(reader); if(thisType == XML_READER_TYPE_ELEMENT) { // Is the new element at the same depth as this one? if(currentDepth == xmlTextReaderDepth(reader)) { // Same depth means the current element ended in a /> so this is a sibling // so we return and let our parent process it. return(element); } else { // The element is a child of this one, so we recurse if(!element->placeElement(nextElement(element->getMeta(), reader))) { char err[256]; memset( err, 0, 256 ); #if LIBXML_VERSION >= 20620 sprintf(err,"placeElement failed at line %d\n", xmlTextReaderGetParserLineNumber(reader)); #else sprintf(err,"placeElement failed\n"); #endif daeErrorHandler::get()->handleWarning( err ); ret = xmlTextReaderRead(reader); if ( ret != 1 ) { return element; } } } } else if(thisType == XML_READER_TYPE_TEXT) { readValue( element, reader ); } else if(thisType == XML_READER_TYPE_END_ELEMENT) { // Done with this element so read again and return ret = xmlTextReaderRead(reader); return(element); } else { // Skip element types we don't care about ret = xmlTextReaderRead(reader); // If we're out of data, return the element if(ret != 1) return(element); } } //program will never get here but this line is needed to supress a warning return NULL; }
virtual void startDocumentEvent(const XMLCh *documentURI, const XMLCh *encoding) { assert(child_ && child_->getNodeType() == DOMNode::DOCUMENT_NODE); node_ = child_; child_ = nextElement(node_->getFirstChild()); }