void StageDlg::onIndexNew( wxCommandEvent& event ) { int i = findID("NEW"); if( i == wxNOT_FOUND ) { iONode model = wxGetApp().getModel(); if( model != NULL ) { iONode sblist = wPlan.getsblist( model ); if( sblist == NULL ) { sblist = NodeOp.inst( wStageList.name(), model, ELEMENT_NODE ); NodeOp.addChild( model, sblist ); } if( sblist != NULL ) { iONode stage = NodeOp.inst( wStage.name(), sblist, ELEMENT_NODE ); NodeOp.addChild( sblist, stage ); wStage.setid( stage, "NEW" ); wStage.setx( stage, 0 ); wStage.sety( stage, 0 ); wStage.setz( stage, 0 ); m_Props = stage; initValues(); initIndex(); setSelection(wStage.getid( stage )); } } } }
void Top100::calculate(MiniUser *u) { if (!u) return; Cmd::MiniGameScore s = u->getGameScore(); /* for (top_iter i=top100.begin(); i!=top100.end(); i++) if (i->id==u->id) { top100.erase(i); return; } */ top_iter ti = std::find_if(top100.begin(),top100.end(),findID(u->id)); if (ti!=top100.end()) top100.erase(ti); if (top100.size()>=120 && s<top100.rbegin()->score) return; //top_iter i=top100.begin(); //for (; i!=top100.end() && i->score>s; i++); top_iter i = std::find_if(top100.begin(),top100.end(),findScore(s)); Cmd::MiniUserData d; u->full_MiniUserData(0,d); top100.insert(i,d); if (top100.size()>120) top100.erase(--top100.end()); //for (top_iter i=top100.begin(); i!=top100.end(); i++) // Xlogger->debug("Top100\t%s(%u)\tscore=%d",i->name,i->id,i->score.score); }
void buttonList::editLabel(int id, char* newLabel){ int tempInt; if(findID(id)){ delete current->label; tempInt = strlen(newLabel); current->label = new char [tempInt+1]; strcpy(current->label, newLabel); } }
void PowerManDlg::OnAddBooster( wxCommandEvent& event ) { int i = findID("NEW"); if( i == wxNOT_FOUND ) { iONode model = wxGetApp().getModel(); iONode boosterlist = wPlan.getboosterlist( model ); iONode booster = NodeOp.inst( wBooster.name(), boosterlist, ELEMENT_NODE ); wBooster.setid(booster, "NEW"); NodeOp.addChild( boosterlist, booster ); m_Props = booster; initValues(); initIndex(); setSelection(wBooster.getid( booster )); } }
void buttonList::removeButton( int id){ if(findID(id)){ if(current == start){ start = current->next; } if(current == end){ end = current->prev; } if(current->next != NULL){ current->next->prev=current->prev; } if(current->prev != NULL){ current->prev->next=current->next; } } delete current; current = start; }
void buttonList::addButtonBelow( int w, int h, int buffx, int buffy, char* label, int buttonID, int id){ button* temp; if(id==-1){ id = size; } if(buttonID == -2){ buttonID = size; } if(start == NULL){ return; } else if(findID(buttonID)){ temp = current->next; current->next = new button(current->x+buffx, current->y+current->h+buffy, w, h, label, buttonID, current, temp); size++; } else{ return; } }
void OperatorDlg::onNewOperator( wxCommandEvent& event ) { int i = findID("NEW"); if( i == wxNOT_FOUND ) { iONode model = wxGetApp().getModel(); if( model != NULL ) { iONode operatorlist = wPlan.getoperatorlist( model ); if( operatorlist == NULL ) { operatorlist = NodeOp.inst( wOperatorList.name(), model, ELEMENT_NODE ); NodeOp.addChild( model, operatorlist ); } if( operatorlist != NULL ) { iONode op = NodeOp.inst( wOperator.name(), operatorlist, ELEMENT_NODE ); NodeOp.addChild( operatorlist, op ); wOperator.setid( op, "NEW" ); m_Props = op; initIndex(); initValues(); setSelection(wOperator.getid( op )); } } } }
void VariableDlg::onNew( wxCommandEvent& event ) { int i = findID("NEW"); if( i == wxNOT_FOUND ) { iONode model = wxGetApp().getModel(); if( model != NULL ) { iONode varlist = wPlan.getvrlist( model ); if( varlist == NULL ) { varlist = NodeOp.inst( wVariableList.name(), model, ELEMENT_NODE ); NodeOp.addChild( model, varlist ); } if( varlist != NULL ) { iONode var = NodeOp.inst( wVariable.name(), varlist, ELEMENT_NODE ); NodeOp.addChild( varlist, var ); wVariable.setid( var, "NEW" ); m_Props = var; initValues(); initIndex(); setSelection(wVariable.getid( var )); } } } }
void TextDialog::OnNewtextClick( wxCommandEvent& event ) { int i = findID("NEW"); if( i == wxNOT_FOUND ) { iONode model = wxGetApp().getModel(); if( model != NULL ) { iONode txlist = wPlan.gettxlist( model ); if( txlist == NULL ) { txlist = NodeOp.inst( wTextList.name(), model, ELEMENT_NODE ); NodeOp.addChild( model, txlist ); } if( txlist != NULL ) { iONode tx = NodeOp.inst( wText.name(), txlist, ELEMENT_NODE ); NodeOp.addChild( txlist, tx ); wText.setid( tx, "NEW" ); appendItem(tx); setIDSelection(wItem.getid(tx)); m_Props = tx; initValues(); } } } }
int MAPSJoin::findID(int id_object, int id_target, MATCH_OBJECTS * vector) { int pos = findID(id_object, vector); if (pos == -1 || id_target == -1) { return -1;//Only for control but actually should be implossible } for (int j = 0; j < vector->number_matched[pos]; j++) { if (j > AUTO_MAX_NUM_OBJECTS) { continue;//Only for control but actually should be implossible } if (vector->Matrix_matched[pos][j][0] == id_target) { return j; } } return -1; }
void AccDecDlg::onAdd( wxCommandEvent& event ) { TraceOp.trc( "accdecdlg", TRCLEVEL_INFO, __LINE__, 9999, "Add" ); int i = findID("NEW"); if( i == wxNOT_FOUND ) { iONode model = wxGetApp().getModel(); if( model != NULL ) { iONode declist = wPlan.getdeclist( model ); if( declist == NULL ) { declist = NodeOp.inst( wDecList.name(), model, ELEMENT_NODE ); NodeOp.addChild( model, declist ); } if( declist != NULL ) { iONode dec = NodeOp.inst( wDec.name(), declist, ELEMENT_NODE ); NodeOp.addChild( declist, dec ); wDec.setid( dec, "NEW" ); m_Props = dec; appendItem(dec); setIDSelection(wItem.getid(dec)); initValues(); } } } }
int addcurve(char *id) /* **------------------------------------------------------------- ** Input: id = curve ID label ** Output: returns error code ** Purpose: adds a new curve to the database **-------------------------------------------------------------- */ { STmplist *c; /* Check if ID is same as last one processed */ if (Curvelist != NULL && strcmp(id,Curvelist->ID) == 0) return(0); /* Check that curve was not already created */ if (findID(id,Curvelist) == NULL) { /* Update curve count & create new list element */ (MaxCurves)++; c = (STmplist *) malloc(sizeof(STmplist)); if (c == NULL) return(101); /* Initialize list element properties */ else { c->i = MaxCurves; strncpy(c->ID,id,MAXID); c->x = NULL; c->y = NULL; c->next = Curvelist; Curvelist = c; } } return(0); }
int addpattern(char *id) /* **------------------------------------------------------------- ** Input: id = pattern ID label ** Output: returns error code ** Purpose: adds a new pattern to the database **-------------------------------------------------------------- */ { STmplist *p; /* Check if ID is same as last one processed */ if (Patlist != NULL && strcmp(id,Patlist->ID) == 0) return(0); /* Check that pattern was not already created */ if (findID(id,Patlist) == NULL) { /* Update pattern count & create new list element */ (MaxPats)++; p = (STmplist *) malloc(sizeof(STmplist)); if (p == NULL) return(101); /* Initialize list element properties */ else { p->i = MaxPats; strncpy(p->ID,id,MAXID); p->x = NULL; p->y = NULL; p->next = Patlist; Patlist = p; } } return(0); }
static AGArray * getUserInfo() { AGArray * result = NULL; HANDLE hFile; HANDLE hMapping; char usersFile[MAX_PATH]; char *userData; char *current; char *maxData; int fileSize; char *name, *dir; usersFile[0] = '\0'; getUsersFile(usersFile, MAX_PATH); hFile = CreateFile(usersFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return NULL; fileSize = GetFileSize(hFile, NULL); hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); if (NULL != hMapping) { userData = (char *)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); maxData = userData + fileSize; result = AGArrayNew(AGUnownedPointerElements, 0); if (NULL != result) { for (current = userData; current < maxData; current++) { if ((name = findString(current, maxData)) && (dir = findString(current + strlen(name) + 1, maxData))) { AGUserInfo * user; int id; id = findID(current - 4); user = (AGUserInfo *)malloc(sizeof(AGUserInfo)); if (NULL != user) { user->name = name; user->dir = dir; user->id = id; current += strlen(name) + strlen(dir) + 1; AGArrayAppend(result, user); } } } } UnmapViewOfFile(userData); CloseHandle(hMapping); } CloseHandle(hFile); return result; }
Token * tokenMatch(char & ch, ifstream & file) { while ((ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t') && !file.eof()) { file.get(ch); } switch (ch) { case ':': return new Token(COLON) ; case ';': return new Token(SEMICOLON); case '.': return new Token(DOT); case ',': return new Token(COMMA); case '!': return new Token(BANG); case '(': return new Token(LPAREN); case ')': return new Token(RPAREN); case '[': return new Token(LBRACKET); case ']': return new Token(RBRACKET); case '{': return new Token(LBRACE); case '}': return new Token(RBRACE); case '<': return new Token(LESSTHAN); case '+': return new Token(PLUS); case '-': return new Token(MINUS); case '*': return new Token(TIMES); case '/': file.get(ch); if (ch == '/') { while (file.peek() != '\n') { file.get(ch); } file.get(ch); //One extra time to skip the newline return tokenMatch(ch, file); } else if (ch == '*') { while (file.get(ch)) { if (ch == '*') { file.get(ch); if (ch == '/') { file.get(ch); return tokenMatch(ch, file); } } } } return new Token(DIV); case '=': file.get(ch); if (ch == '=') return new Token(EQUALS); file.seekg (-1, file.cur); //Move file pointer back one step so the loop won't miss a char return new Token(EQSIGN); case '&': file.get(ch); if (ch == '&') return new Token(AND); file.seekg (-1, file.cur); //Move file pointer back one step so the loop won't miss a char return new Token(BAD); case '|': file.get(ch); if (ch == '|') return new Token(OR); file.seekg (-1, file.cur); //Move file pointer back one step so the loop won't miss a char return new Token(BAD); default: return findID(ch, file); } }
int handle_command(int socket) { char message[MESSAGE]; int result; int code; //receive message if((result = recvall(socket, message, sizeof(message))) == -1){ printf("handle_command recvall failed\n"); return -1; } //if result 0, close connection if(result == CLOSED){ struct peer *closedSocket = findConnection(socket); printf("%s closed the connection\n", closedSocket->hostname); updateSelect(DELETE, socket, &master_set, &fdmax); removeFromConnections(socket); if(localInfo.isServer){ //broadcast new IP list sendIPLIST(); } return 0; } //printf("NEW MESSAGE: %s\n", message); //EXTRACTING MESSAGE char* newptr = message; int nbytes; char hostName[200]; char port[50]; char ipaddr[INET6_ADDRSTRLEN]; //extract header sscanf(newptr, "%d %n", &code, &nbytes); newptr += nbytes; //SERVER IP UPDATE switch(code) { case ADD_IP_LIST : { DESTROY_IPLIST(); printf("\n%s UPDATED SERVER IP LIST:\n", getTime()); while(true){ //parse out the IP LIST sscanf(newptr, "%s %s %s %n", hostName, ipaddr, port, &nbytes); if(strcmp(hostName, "EOF") == 0) {break;} //printf("%s %s %s\n",hostName, ipaddr, port); SAVE_IPLIST(hostName, port, ipaddr); newptr += nbytes; } PRINT_IPLIST(); printf("\n"); break; } case SEND_FILE : { char filename[50]; char file_len[50]; char chunks_num[50]; sscanf(newptr, "%s %s %s", filename, file_len, chunks_num); struct peer *sender = findConnection(socket); printf("DOWNLOADING FILE: %s FROM: %s\n", filename, sender->hostname); if ((result = receiveFile(socket, filename, file_len, chunks_num)) != 0){ return result; } break; } case REQUEST_FILE : { char filename[50]; int connectionID; sscanf(newptr, "%s", filename); if((connectionID = findID(socket)) == -1){ printf("REQUEST_FILE: connection does not exist\n"); return EHOSTUNREACH; } char ID[20]; sprintf(ID, "%d", connectionID); int argCount = 3; char *arguments[] = {"UPLOAD", ID, filename}; if((result = cmd_upload(argCount, arguments)) != 0){ printf("ERROR: Could not upload file.\n"); char message[MESSAGE]; sprintf(message, "%d %s\n",NOTIFICATION, "REQUEST FAILED: COULD NOT UPLOAD FILE!"); sendall(socket, message, sizeof(message)); return EHOSTUNREACH; } break; } case NOTIFICATION : { struct peer *sender = findConnection(socket); printf("\n**** NOTIFICATION FROM: %s ****\n", sender->hostname); printf(">> %s\n", newptr); break; } default : printf("Invalid Message Code, cannot understand\n"); return -1; } return 0; }
void buttonList::editDisplay(int id, bool toDisplay){ if(findID(id)){ current->display = toDisplay; } }
float MAPSJoin::getOverlapScore(AUTO_Object * Object_Laser, AUTO_Object * Object_Camera) { return (float)Laser_Matched.Matrix_matched[findID(Object_Laser->id, &Laser_Matched)][findID(Object_Laser->id, Object_Camera->id, &Laser_Matched)][1]; }
void Meshing::splitDiag() { for(int id=0;id<mesh_.size();id++){ QPolygonF poly = mesh_.at(id); if(poly.isEmpty()) continue; if(!poly.isClosed()) poly << poly.at(0); if(poly.size()<=4) continue; QStringList polyID; for(int k=0;k<poly.size();k++) polyID << findID(poly.at(k)); /*for(int i=0;i<poly.size()-2;i++){ QPointF p = (poly.at(i) + poly.at(i+2))/2.0; if(poly.containsPoint(p,Qt::WindingFill)){ QPolygonF p1,p2; for(int k=i;k<i+3;k++){ p1 << poly.at(k); } p1 << poly.at(i); for(int k=i+3;k<=poly.size()-1;k++){ p2 << poly.at(k); } for(int k=0;k<i;k++){ p2 << poly.at(k); } p2 << poly.at(i); mesh_.push_back(p1); mesh_.push_back(p2); mesh_.removeAt(id); splitDiag(); return; } }*/ //qDebug() << "Split poly" << polyID; for(int i=0;i<poly.size()-1;i++){ for(int j=i+2;j<poly.size()-(i==0?2:1);j++){ //qDebug() << "Try to split along" << findID(poly.at(i)) << findID(poly.at(j)); QLineF line(poly.at(i),poly.at(j)); QPointF middle = (poly.at(i)+poly.at(j))/2.0; if(!poly.containsPoint(middle,Qt::WindingFill)) continue; if(!intersects(poly,line)){ QPolygonF p1,p2; //QStringList poly1id,poly2id; for(int k=i;k<=j;k++){ p1 << poly.at(k); //poly1id << findID(poly.at(k)); } p1 << poly.at(i); //poly1id << findID(poly.at(i)); for(int k=j;k<poly.size()-1;k++){ p2 << poly.at(k); //poly2id << findID(poly.at(k)); } for(int k=0;k<=i;k++){ p2 << poly.at(k); //poly2id << findID(poly.at(k)); } p2 << poly.at(j); //poly2id << findID(poly.at(j)); //qDebug() << poly.size() << QPair<int,QString>(i,findID(poly.at(i))) << QPair<int,QString>(j,findID(poly.at(j))) << p1.size() << p2.size(); //qDebug() << "Poly1" << poly1id; //qDebug() << "Poly2" << poly2id; mesh_.push_back(p1); mesh_.push_back(p2); mesh_.removeAt(id); splitDiag(); return; } } } //qDebug() << "Can't split poly " << polyID; } }
void Top100::remove(DWORD id) { top_iter ti = std::find_if(top100.begin(),top100.end(),findID(id)); if (ti!=top100.end()) top100.erase(ti); }
void buttonList::editCallback(int id, buttonCallback newFunc){ if(findID(id)){ current->callbackFunction = newFunc; } }
/** Peforms the processing associated with these transformations. */ void MDGeometryXMLParser::execute() { Poco::XML::DOMParser pParser; Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(m_xmlToProcess); Poco::XML::Element *pRootElem = pDoc->documentElement(); // Apply root node checking if supplied. Poco::XML::Element *geometryXMLElement = nullptr; if (!m_rootNodeName.empty()) { Poco::XML::Element *temp = pRootElem->getChildElement(m_rootNodeName); geometryXMLElement = temp; if (geometryXMLElement == nullptr) { std::string message = "Root node was not found to be the expected value of " + m_rootNodeName; throw std::runtime_error(message); } } else { // The default is to take the root node to be the geometry xml element. geometryXMLElement = pRootElem; } Poco::AutoPtr<Poco::XML::NodeList> dimensionsXML = geometryXMLElement->getElementsByTagName( MDGeometryXMLDefinitions::workspaceDimensionElementName()); size_t nDimensions = dimensionsXML->length(); VecIMDDimension_sptr vecAllDims(nDimensions); ////Extract dimensions for (size_t i = 0; i < nDimensions; i++) { Poco::XML::Element *dimensionXML = static_cast<Poco::XML::Element *>( dimensionsXML->item(static_cast<unsigned long>(i))); vecAllDims[i] = createDimension(*dimensionXML); } VecIMDDimension_sptr vecNonMappedDims = vecAllDims; Poco::XML::Element *xDimensionElement = geometryXMLElement->getChildElement( MDGeometryXMLDefinitions::workspaceXDimensionElementName()); std::string xDimId = xDimensionElement ->getChildElement( MDGeometryXMLDefinitions::workspaceRefDimensionElementName()) ->innerText(); if (!xDimId.empty()) { auto xDimensionIt = find_if(vecAllDims.begin(), vecAllDims.end(), findID(xDimId)); if (xDimensionIt == vecAllDims.end()) { throw std::invalid_argument("Cannot determine x-dimension mapping."); } m_xDimension = *xDimensionIt; vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(), vecNonMappedDims.end(), findID(xDimId)), vecNonMappedDims.end()); } Poco::XML::Element *yDimensionElement = geometryXMLElement->getChildElement( MDGeometryXMLDefinitions::workspaceYDimensionElementName()); std::string yDimId = yDimensionElement ->getChildElement( MDGeometryXMLDefinitions::workspaceRefDimensionElementName()) ->innerText(); if (!yDimId.empty()) { auto yDimensionIt = find_if(vecAllDims.begin(), vecAllDims.end(), findID(yDimId)); if (yDimensionIt == vecAllDims.end()) { throw std::invalid_argument("Cannot determine y-dimension mapping."); } m_yDimension = *yDimensionIt; vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(), vecNonMappedDims.end(), findID(yDimId)), vecNonMappedDims.end()); } Poco::XML::Element *zDimensionElement = geometryXMLElement->getChildElement( MDGeometryXMLDefinitions::workspaceZDimensionElementName()); std::string zDimId = zDimensionElement ->getChildElement( MDGeometryXMLDefinitions::workspaceRefDimensionElementName()) ->innerText(); if (!zDimId.empty()) { auto zDimensionIt = find_if(vecAllDims.begin(), vecAllDims.end(), findID(zDimId)); if (zDimensionIt == vecAllDims.end()) { throw std::invalid_argument("Cannot determine z-dimension mapping."); } m_zDimension = *zDimensionIt; vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(), vecNonMappedDims.end(), findID(zDimId)), vecNonMappedDims.end()); } Poco::XML::Element *tDimensionElement = geometryXMLElement->getChildElement( MDGeometryXMLDefinitions::workspaceTDimensionElementName()); std::string tDimId = tDimensionElement ->getChildElement( MDGeometryXMLDefinitions::workspaceRefDimensionElementName()) ->innerText(); if (!tDimId.empty()) { auto tDimensionIt = find_if(vecAllDims.begin(), vecAllDims.end(), findID(tDimId)); if (tDimensionIt == vecAllDims.end()) { throw std::invalid_argument("Cannot determine t-dimension mapping."); } m_tDimension = *tDimensionIt; if (!vecNonMappedDims.empty()) { vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(), vecNonMappedDims.end(), findID(tDimId)), vecNonMappedDims.end()); } } m_vecNonMappedDims = vecNonMappedDims; // Copy with strong guarantee. m_vecAllDims = vecAllDims; m_executed = true; }