Пример #1
0
tablero::tablero(const string& archivo){
    
    string palabra, str_local;
    ifstream fich(archivo.c_str());
    list<string> aux;
    while (fich >> palabra) {
        aux.push_back(palabra);
    }
    
    fich.close();
    
    list<string>::const_iterator itr,itr2,itr3;
    itr = aux.begin();
    itr2 = ++itr;  
    pair<unsigned int,unsigned int> par(atoi((*itr).c_str()),atoi((*itr2).c_str()));
    _tam = par;
    
    string::iterator it;
    list<char> lc;
    for(itr3 = ++itr; itr3 != aux.end(); ++itr3){
        str_local = *itr3;
        for (it = str_local.begin(); it != str_local.end(); it++ )
            lc.push_back(*it);
        _matriz.push_back(lc);
        lc.clear();
    }

}
Пример #2
0
int GeoEngine::downloadImage(Couche couche, int x, int y, int zoomLevel,bool forceDl)
{
    TuileParams params;
    params.couche=couche;
    params.x = x;
    params.y = y;
    params.zoomlevel = zoomLevel;
    QFileInfo info = convertTileToFileInfo(params);
    if(!info.exists() || ((mode==CONNECTED) && forceDl))
    {
        if(mode==OFFLINE)
            info = QFileInfo(QString("noImg.jpg"));
        else if (mode==CONNECTED)
        {
            QNetworkRequest request(genereUrl(couche, x, y, zoomLevel));
            request.setRawHeader("Referer", "http://www.geoportail.gouv.fr/swf/geoportal-visu-1.1.3.swf");
            request.setRawHeader("Host", "gpp3-wxs.ign.fr");
            request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
                                 QNetworkRequest::PreferCache);
            imageRequests.append(manager->get(request));
            return int(imageRequests.back());
        }
    }
    QFile fich(info.filePath());
    fich.open(QIODevice::ReadOnly);
    toSendId.enqueue(compteur++);
    toSend.enqueue(fich.readAll());
    fich.close();
    QTimer::singleShot(10,this,SLOT(sendFirstData()));
    return toSendId.back();
}
Пример #3
0
Board::Board(const string &filename) // loads board from file 'filename'
{
	string leitura;
	char temp;

	ifstream fich(filename);
	
	fich >> numLines >> temp >> numColumns;

	while (!fich.eof())
	{
		char symbol, orientation;
		Position<char> position;  
		unsigned int size, color; 
		
		fich >> symbol >> size >> position.lin >> position.col >> orientation >> color;

		ships.push_back(Ship(symbol, position, orientation, size, color));
	}
	fich.close();
	
	for (int i = 0; i < numLines; i++)
	{
		vector<int> temp (numColumns, -1);
		board.push_back(temp);
	}
	
}
Пример #4
0
sudoku::sudoku(const string &file) : _tablero(vector<vector<celda> >(9, vector<celda>(9))) {
	string basura;
	unsigned int dato;
	
	ifstream fich(file.c_str());
	if (fich.is_open()) {
		fich >> basura;

	    unsigned int fila = 1;
	    unsigned int columna = 1;

	    while ((fila < 10) and (columna < 10)) {
	    	fich >> basura;
	    	// string to int
	    	istringstream buffer(basura);
	    	buffer >> dato;
	    	if ((dato >= 1) and (dato <= 9)) {
	    		bool res = _tablero[fila-1][columna-1].fijar_valor(dato, true);
	    		if (!res) {
	    			cout << "Problemas con el tablero..." << endl;
	    		}
	    	}
	    	++columna;
	    	if (columna == 10) {
	    		columna = 1;
	    		++fila;
	    	}
	    }

	    fich.close();
	  }
Пример #5
0
void UnitTestCase::test(void)
{
  
  ifstream fich ("../prueba1.cg");
  CCortes cortes (10, 10, fich);
  fich.close ();
  cortes.cortes (10, 10);
 
  CPPUNIT_ASSERT( cortes.getPos (10, 10)== 80);
}
/** Almacenamiento del vocabulario en una variable MiVocabulario */
bool capturaVocabulario(char * nomFich)
{
	std::ifstream fich(nomFich);
	if(fich.is_open()) _vocabulario.readVocabulary(fich);
	else return false;
	fich.close();	

	_vocabulario.imprimeVocabulario();
	std::cout << _vocabulario.getTipo() << std::endl;

	return true;
}
Пример #7
0
void ScriptingArea::load(const QString &name) {

    Log::i("ScriptingArea") << "chargement du script dans : " << SCRIPTS_DIR << name;

    QFile fich(QString(SCRIPTS_DIR) + name);
    fich.open(QIODevice::ReadOnly);
    QByteArray ba;
    ba = fich.readAll();
    m_textZone.setText(QString::fromLatin1(ba));
    fich.close();

    Log::d("ScriptingArea") << "chargement terminé";
}
Пример #8
0
void ScriptingArea::save(const QString &name) const {

    Log::i("ScriptingArea") << "sauvegarde du script dans : " << SCRIPTS_DIR << name;

    QFile fich(QString(SCRIPTS_DIR) + name);
    fich.open(QIODevice::WriteOnly);
    QByteArray ba;
    ba.append(m_textZone.text().toLatin1());
    fich.write(ba);
    fich.close();

    Log::d("ScriptingArea") << "sauvegarde terminée";
}
Пример #9
0
int numStringMatching(string filename,string toSearch)
{
	ifstream fich(filename.c_str());
	if (!fich)
	{ cout << "Erro a abrir ficheiro de leitura\n"; return 0; }

	string line1;
	int num=0;

	while (!fich.eof()) {
		getline(fich,line1);
		num+=kmp(line1,toSearch);
	}
	fich.close();
	return num;
}
Пример #10
0
float numApproximateStringMatching(string filename,string toSearch)
{
	ifstream fich(filename.c_str());
	if (!fich)
	{ cout << "Erro a abrir ficheiro de leitura\n"; return 0; }

	string line1, word1;
	int num=0, nwords=0;

	while (!fich.eof()) {
		getline(fich,line1);
		stringstream s1(line1);
		while (!s1.eof()) {
			s1 >> word1;
			num += editDistance(toSearch,word1);
			nwords++;
		}
	}
	fich.close();
	float res=(float)num/nwords;
	return res;
}
RF_Asset_List::RF_Asset_List(string path)
{
    ///Por el momento, path es un directorio

    //Obtenemos el id del paquete de recursos
        const size_t it = path.find_last_of('/');
        id = path; id.erase(0,it+1);

    //Extraemos el nombre del directorio para insertarlo en el nombre;
        DIR *dir;

    //En *ent habrá información sobre el archivo que se está "sacando" a cada momento;
        struct dirent *ent;

    //Empezaremos a leer en el directorio actual;
        dir = opendir (path.c_str());

    //Miramos que no haya error
        if (dir == NULL)
        {
            RF_Engine::instance->Debug(("LoadAsset [Error]: No se puede abrir directorio " + path));
            return;
        }

    //Creamos un puntero con el seleccionaremos el fichero de configuración (si existe);
        ifstream fich(path + "/package.cfg");

        if(fich.is_open())
        {
            RF_Engine::instance->Debug((path + "/package.cfg"));

            string buffer;
            while(!fich.eof())
            {
                fich >> buffer;
                cfg.push_back(buffer);
            }
        }
Пример #12
0
tablero::tablero(const string& archivo) {

    string palabra;
    ifstream fich(archivo.c_str());
    vector<string> aux;
    while (fich >> palabra) {
        aux.push_back(palabra);
    }

    fich.close();

    pair<unsigned int,unsigned int> par(atoi(aux[0].c_str()),atoi(aux[1].c_str()));
    _tam = par;

    string::iterator it;
    vector<char> vc;
    for(unsigned int i=2; i < aux.size(); i++) {
        for ( it=aux[i].begin() ; it < aux[i].end(); it++ )
            vc.push_back(*it);
        _matriz.push_back(vc);
        vc.clear();
    }
}
Пример #13
0
void OpcionesJuego::leeFich(string fichero){
    string cad;
    ifstream fich(fichero.c_str());//Creación y apertura
    if(!fich){
        cerr << "\nNo es posible abrir " << fichero <<"\n";
        exit(1);
    }
    leeLinea(fich,cad,'\n');
    //fich.ignore(1000,'\n');//Ignoramos número mágico
    leeLinea (fich,cad,'\n');
    incendios_permitidos=s2bool(cad);

    leeLinea (fich,cad,'\n');
    viento_permitido=s2bool(cad);

    leeLinea (fich,cad,'\n');


    direccion_viento = atoi(cad.c_str());//INT 1 y 6 o -1

    if(direccion_viento!=-1 && (direccion_viento<0 || direccion_viento>6)){
        cerr << "\nValor de dirección del viento incorrecto, debe de estar entre 1 y 6 o ser -1:"<<endl;
        cin.get();
        exit(1);
    }
    leeLinea (fich,cad,'\n');
    ataques_fisicos_permitidos=s2bool(cad);

    leeLinea (fich,cad,'\n');
    fase_calor=s2bool(cad);

    leeLinea (fich,cad,'\n');
    devastar_bosques=s2bool(cad);

    leeLinea (fich,cad,'\n');
    derrumbar_edificios=s2bool(cad);

    leeLinea (fich,cad,'\n');
    chequeos_pilotaje=s2bool(cad);

    leeLinea (fich,cad,'\n');
    chequeo_danho=s2bool(cad);

    leeLinea (fich,cad,'\n');
    chequeo_desconexion=s2bool(cad);

    leeLinea (fich,cad,'\n');
    impactos_criticos=s2bool(cad);

    leeLinea (fich,cad,'\n');
    explosion_municion=s2bool(cad);

    leeLinea (fich,cad,'\n');
    apagar_radiadores=s2bool(cad);

    leeLinea (fich,cad,'\n');
    limitar_tiempo_respuesta=s2bool(cad);

    leeLinea (fich,cad,'\n');
    valor_limite_tiempo = atoi(cad.c_str());//entero positivo o -1
    if(valor_limite_tiempo!=-1 && valor_limite_tiempo<0){
        cerr << "\nValor de tiempo incorrecto, debe ser entero positivo o -1"<<endl;
        exit(1);
    }
}