Ver Mensaje Individual
  #47 (permalink)  
Antiguo 21/03/2016, 20:19
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años, 1 mes
Puntos: 6
Respuesta: headers, carpetas y menúes c++

Hola eferion, aunque parezca mentira solucioné mis problemas con el crud que tenía, la clave estaba en el struct Persona.

Código C++:
Ver original
  1. #ifndef PERSONA_H
  2. #define PERSONA_H
  3. using namespace std;
  4. struct Persona{
  5.     int id;
  6.     string nom;
  7.     string ape;
  8.     bool operator == (const Persona& p){
  9.         return p.id == id;
  10.     }
  11.     // este operator < lo tuve que usar para ordenar mis datos
  12.     bool operator < (const Persona & p) const
  13.     {
  14.         return id < p.id;
  15.     }
  16. };
  17. #endif  /* PERSONA_H */

Y en el ManPersonas, luego de borrar, reinsertar, ordeno los datos para que al editar mis datos no tenga problemas con el orden

Código C++:
Ver original
  1. #include <list>
  2. #include "../Model/Persona.h"
  3. #include "../Lib/Util.h"
  4. #ifndef MANPERSONAS_H
  5. #define MANPERSONAS_H
  6. using namespace std;    
  7.     std::list<Persona> lista;
  8.     int maxIdP = 0;
  9.     int getMaxIdP(){
  10.         return ++maxIdP;
  11.     }
  12.     Persona getPhantom(){
  13.         Persona p;
  14.         p.id = 0;
  15.         p.nom ="";
  16.         p.ape ="";
  17.         return p;
  18.     }    
  19.     Persona getRow(std::string xnom){
  20.         for(Persona p : lista){
  21.             if(p.nom == xnom){
  22.                 return p;
  23.             }
  24.         }
  25.         return getPhantom();
  26.     }    
  27.     Persona getRow(int xid){
  28.         for(Persona p : lista){
  29.             if(p.id == xid){
  30.                 return p;
  31.             }
  32.         }
  33.         return getPhantom();
  34.     }
  35.     bool create(const Persona& p){
  36.         if(getRow(p.nom).nom != ""){
  37.             maxIdP--;
  38.             return false;
  39.         }
  40.         else{
  41.             lista.push_back(p);            
  42.             return true;
  43.         }
  44.     }
  45.     bool update(const Persona& p){
  46.         Persona per = getRow(p.id);
  47.         if(per.nom != p.nom){
  48.             if(getRow(p.nom).nom != ""){
  49.                 return false;
  50.             }
  51.         }
  52.         lista.remove(per);
  53.         lista.push_back(p);
  54.         lista.sort();
  55.         return true;        
  56.     }
  57.     void deleted(const Persona& p){
  58.         lista.remove(p);
  59.     }
  60.     std::list<Persona> read(){
  61.         return lista;        
  62.     }  
  63. #endif  /* MANPERSONAS_H */

Ahora me quedan hacer andar bien las validaciones tanto en los string como en los enteros, en conclusión este código hecho comparado con lo que tu y Instru me dijeron es malo, pero para safar un poco da aunque debo mejorarlo...

Espero sus respuestas y saludos.