map<int, string> Merger::getNodesToSendQuery(string qry){ int i = 0; map<int, string> nodePerTerm = map<int, string>(); vector<string> R = vector<string>(); vector<Vocabulary>::iterator it=vocab.begin(); StringExplode(qry, " ", &R); while (it != vocab.end() && i < R.size()){ for (int j = 0; j < R.size(); j++){ if (R[j] == it->term){ // if(it->row != rank){ if (nodePerTerm.find(it->row) == nodePerTerm.end()){ nodePerTerm[it->row] = R[j]; } else { nodePerTerm[it->row] += " " + R[j]; } // } i++; } } ++it; } return nodePerTerm; }
/////////////////////////////////////////////////////////////////////////////// // initializer methods /////////////////////////////////////////////////////////////////////////////// void PlotContig::setMassIntervals(string &strValues, vector<double> &values) { vector<string> items; StringExplode(strValues, items, true, "|"); for(int i = 0 ; i < items.size() ; i++) { double aux = getFloat(items[i].c_str()); values.push_back(aux); } }
int Broker::getRowToSendQuery(string qry){ unsigned int frecuencia = 0; unsigned int row = 0, i = 0; vector<string> R = vector<string>(); vector<Vocabulary>::iterator it=vocab.begin(); StringExplode(qry, " ", &R); while (it != vocab.end() && i < R.size()){ for (int j = 0; j < R.size(); j++){ if (R[j] == it->term){ if (frecuencia < it->frecuency){ frecuencia = it->frecuency; row = it->row; } i++; } } ++it; } return row; }
Game::Game() { // Load images string filename; fstream fin("data/img.init", fstream::in); while (!fin.eof()) { getline(fin, filename); vector<string> split; //split the string into parts: name width height StringExplode(filename.c_str(), " ", &split); filename = split[0]; SDL_Surface *surface; // Gives us the information to make the texture GLenum texture_format; GLint nOfColors; if ( (surface = SDL_LoadBMP(filename.c_str())) ) { textureDB.push_back(*(new Texture)); // Check that the image's width is a power of 2 if ( (surface->w & (surface->w - 1)) != 0 ) { printf("warning: image's width(%i) is not a power of 2\n", surface->w); } // Also check if the height is a power of 2 if ( (surface->h & (surface->h - 1)) != 0 ) { printf("warning: image's height(%i) is not a power of 2\n", surface->h); } // get the number of channels in the SDL surface nOfColors = surface->format->BytesPerPixel; if (nOfColors == 4) // contains an alpha channel { if (surface->format->Rmask == 0x000000ff) texture_format = GL_RGBA; else texture_format = GL_BGRA; } else if (nOfColors == 3) // no alpha channel { if (surface->format->Rmask == 0x000000ff) texture_format = GL_RGB; else texture_format = GL_BGR; } else { printf("warning: the image is not truecolor.. this will probably break\n"); // this error should not go unhandled } // Have OpenGL generate a texture object handle for us glGenTextures( 1, &textureDB[textureDB.size()-1].texture ); // Bind the texture object glBindTexture( GL_TEXTURE_2D, textureDB[textureDB.size()-1].texture ); // Set the texture's stretching properties glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); // Edit the texture object's image data using the information SDL_Surface gives us glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels ); //set dimensions for the loaded images textureDB[textureDB.size()-1].origwidth = surface->w; textureDB[textureDB.size()-1].origheight = surface->h; textureDB[textureDB.size()-1].width = atoi(split[1].c_str()); textureDB[textureDB.size()-1].height = atoi(split[2].c_str()); } else { printf("SDL could not load image: %s\n", SDL_GetError()); SDL_Quit(); throw IMG_LOAD_EXCEPTION; } // Free the SDL_Surface only if it was successfully created if ( surface ) { SDL_FreeSurface( surface ); } } // Create the State objects, and make the Menu active game_state = new State_Login(); cur_state = STATE_LOGIN; next_state = STATE_NULL; }
bool Game::LoopEvents() { // Wait a packet. UDP_Recv returns != 0 if a packet is coming char* data; if ((data = GetUDP())!=NULL) { if (strcmp(data, "login") == 0) { printf("logging in...\n"); if(inActiveList.size()>0) { SendUDP(itoa(inActiveList[inActiveList.size()-1]).c_str());// gives the loggie an id inActiveList.pop_back(); } else { SendUDP(itoa(beingDB.size()).c_str());// gives the loggie an id beingDB.push_back(*(new Being));// creates a new being for the loggie } // init beingDB[atoi((char*)p->data)].x = 0; beingDB[atoi((char*)p->data)].y = 0; beingDB[atoi((char*)p->data)].active = true; printf("data:%s\n", (char*)p->data); printf("logged in!\n"); } else { vector<string> action; action.clear(); StringExplode(data, ":", &action); //movments are based around the dwarfs dementions if(strcmp(action[1].c_str(), "DOWN") == 0 && beingDB[atoi(action[0].c_str())].y+22 <= 480) beingDB[atoi(action[0].c_str())].y+=11; if(strcmp(action[1].c_str(), "UP") == 0 && beingDB[atoi(action[0].c_str())].y-11 >= 0) beingDB[atoi(action[0].c_str())].y-=11; if(strcmp(action[1].c_str(), "LEFT") == 0 && beingDB[atoi(action[0].c_str())].x-8 >= 0) beingDB[atoi(action[0].c_str())].x-=8; if(strcmp(action[1].c_str(), "RIGHT") == 0 && beingDB[atoi(action[0].c_str())].x+16 <= 640) beingDB[atoi(action[0].c_str())].x+=8; if(strcmp(action[1].c_str(), "logout") == 0) { printf("logging out...\n"); // save the ID for recycling beingDB[atoi(action[0].c_str())].active = false; inActiveList.push_back(atoi(action[0].c_str())); printf("logged out!\n"); } } string beings; beings[0] = '\0'; for(int i = 0; i < beingDB.size(); i++)// send being list to clients { if(beingDB[i].active)// only bother with ID's that are in use { strcat((char*)beings.c_str(), itoa(i).c_str());// ID strcat((char*)beings.c_str(), ":"); strcat((char*)beings.c_str(), itoa(beingDB[i].x).c_str()); // ID:x strcat((char*)beings.c_str(), ":"); strcat((char*)beings.c_str(), itoa(beingDB[i].y).c_str());// ID:x:y if(i != beingDB.size()-1) strcat((char*)beings.c_str(), ";");// ID:x:y;... } } SendUDP(beings.c_str()); } return false; }
void EndoDebugFromXmlFile::Update() { endodebug( __FUNCTION__ ) std::string _FileName = *d->m_FileName; if( !itksys::SystemTools::FileExists( _FileName.c_str() ) ) { endodebug(_FileName << " does not exist"); return; } long int _FileModifiedTime = itksys::SystemTools::ModifiedTime( _FileName.c_str() ); // file has changed: we know an older version... if( d->m_FileModifiedTime >= _FileModifiedTime ) { endodebug("File not changed. No Update necessary."); return; } // reread endodebugvar( _FileName ) TiXmlDocument doc( _FileName ); doc.LoadFile(); TiXmlHandle docHandle( &doc ); TiXmlElement* elem = docHandle.FirstChildElement().FirstChildElement( "EndoDebug" ).ToElement(); if(elem == 0) { endodebug("EndoDebug element not found"); return; } int _DebugEnabled = d->m_EndoDebug->GetDebugEnabled(); if( elem->QueryIntAttribute("DebugEnabled",&_DebugEnabled) != TIXML_SUCCESS ) endodebug("DebugEnabled attribute not found"); int _ShowImagesInDebug = d->m_EndoDebug->GetShowImagesInDebug(); if( elem->QueryIntAttribute("ShowImagesInDebug",&_ShowImagesInDebug) != TIXML_SUCCESS ) endodebug("ShowImagesInDebug attribute not found"); int _ShowImagesTimeOut = d->m_EndoDebug->GetShowImagesTimeOut(); if( elem->QueryIntAttribute("ShowImagesTimeOut",&_ShowImagesTimeOut) != TIXML_SUCCESS ) endodebug("ShowImagesTimeOut attribute not found"); std::string _DebugImagesOutputDirectory = d->m_EndoDebug->GetDebugImagesOutputDirectory(); if( elem->QueryStringAttribute("DebugImagesOutputDirectory",&_DebugImagesOutputDirectory) != TIXML_SUCCESS ) endodebug("DebugImagesOutputDirectory attribute not found"); std::set<std::string> _FilesToDebug; std::string _FilesToDebugString; if( elem->QueryStringAttribute("FilesToDebug",&_FilesToDebugString) != TIXML_SUCCESS ) { endodebug("FilesToDebug attribute not found"); } else { StringExplode( _FilesToDebugString, ";", &_FilesToDebug ); } std::set<std::string> _SymbolsToDebug; std::string _SymbolsToDebugString; if( elem->QueryStringAttribute("SymbolsToDebug",&_SymbolsToDebugString) != TIXML_SUCCESS ) { endodebug("SymbolsToDebug attribute not found"); } else { StringExplode( _SymbolsToDebugString, ";", &_SymbolsToDebug ); } // save mitk::EndoDebug::GetInstance().SetDebugEnabled( _DebugEnabled == 1? true: false ); mitk::EndoDebug::GetInstance().SetShowImagesInDebug( _ShowImagesInDebug == 1? true: false ); mitk::EndoDebug::GetInstance().SetShowImagesTimeOut( _ShowImagesTimeOut ); mitk::EndoDebug::GetInstance().SetDebugImagesOutputDirectory( _DebugImagesOutputDirectory ); mitk::EndoDebug::GetInstance().SetFilesToDebug(_FilesToDebug); mitk::EndoDebug::GetInstance().SetSymbolsToDebug(_SymbolsToDebug); // save that modified time d->m_FileModifiedTime = _FileModifiedTime; }