예제 #1
0
  /** Guardar contactos en la lista al final del fichero por defecto
   */
   bool FicheroPacientes::guardar(){

    Paciente* p;
    Atributo* am;
    //if(_pacientes->empty())
    //return true;

    std::ofstream fichero;
    fichero.open(_filename.c_str());

    if(!fichero.is_open())
      return false;

    for(std::list<Contacto*>::iterator it=_pacientes->begin();it!=_pacientes->end();it++){
      p = static_cast<Paciente*>(*(it)); //cast de Contacto* a Paciente*

      fichero<<"***"<<std::endl;
      fichero<<p->get_apellido1().get_titulo()<<":"<<p->get_apellido1().get_contenido()<<std::endl;
      fichero<<p->get_apellido2().get_titulo()<<":"<<p->get_apellido2().get_contenido()<<std::endl;

      fichero<<"FRECUENCIA:"<<p->get_frecuencia()<<std::endl;
      fichero<<"FAVORITO:"<<p->get_favorito()<<std::endl;

      fichero<<p->get_dni().get_titulo()<<":"<<p->get_dni().get_contenido()<<std::endl;
      fichero<<p->get_sexo().get_titulo()<<":"<<p->get_sexo().get_contenido()<<std::endl;
      fichero<<p->get_nombre().get_titulo()<<":"<<p->get_nombre().get_contenido()<<std::endl;
      fichero<<"FECHA NACIMIENTO:"<<p->get_fecha_nacimiento()<<std::endl;


      p->reset_cursor();
      while(!p->es_ultimo()){
        am = p->get_atributo_multiple();
        fichero<<am->get_titulo()<<":"<<am->get_contenido()<<std::endl;
      };


      fichero<<"---"<<std::endl;
    }


    fichero.close();

    return true;
  }
예제 #2
0
  bool FicheroPacientes::buscar(const std::string& a1, const std::string& a2){
    Paciente* act; //paciente actual
    Paciente b; //paciente buscado
    b.set_apellido1(a1);
    b.set_apellido2(a2);

    std::list<Contacto*>::iterator it = _pacientes->begin();

    while(it!=_pacientes->end()){
      if(b == *it){
	// si lo encuentra, sale del bucle y _activo
	// apunta primer paciente encontrado
	_activo = it;

	guardar();
	return true;
      }
      ++it;
    }

    //si no encuentra el exacto,
    //buscamos coincidencias por primer apellido
    it = _pacientes->begin();
    while(it!=_pacientes->end()){
      act = dynamic_cast<Paciente*>(*it);
      if(b.get_apellido1().get_contenido() == act->get_apellido1().get_contenido()){
	// si lo encuentra, sale del bucle y _activo
	// apunta primer paciente encontrado
	_activo = it;

	guardar();
	return true;
      }
      ++it;
    }

    return false;

  }