Bonjour a tous, voila quelques heures que je parcours le forum pour éviter de créer un sujet déjà existant avec ma réponse à l'intérieur. Si jamais j'ai mal ou pas assez cherché je m'en excuse d'avance.
Voici le contenu de mon problème:
je parcours un fichier excel afin d'identifier des familles d'éléments dont les identifiants peuvent figurer sur 2 colonnes.
mes cas étant tous différents les uns des autres j'ai créé une structure d'éléments (CONNECTORTYPE) a 2 attributs: Famille et Désignation dans une classe dédiée a mon fichier excel d'entrée et son contenu (.h):
#ifndef KITLISTGIDTFILE_H
#define KITLISTGIDTFILE_H
#include "ExcelManager/excelfile.h"
#include <set>
#include <vector>
#include "gidtmass.h"
class KitListParameter : public ExcelFileParameter
{
public :
KitListParameter(std::wstring file);
~KitListParameter();
int labelRow(){ return LABEL_ROW;} // Ligne contenant les titres
int headerRowsNb(){ return NUMBER_OF_HEADER_LINES;} // Nombre de lignes d'entêtes
int getNumberOfColumns(){return NUMBER_OF_COLUMNS;}
int getSheetIndex(){return SHEET_INDEX;}
enum m_columns{
ID_OUTIL,
ETAT,
REV,
BUNDLE,
FROM_BOX_CODE,
FROM_CONNECTOR,
FAMILY,
PROVIDER_REFERENCE,
PROVIDER,
DESIGNATION,
INTERNAL_REFERENCE,
QUANTITY,
MASS,
NUMBER_OF_COLUMNS
};
const int LABEL_ROW = 0;
const int NUMBER_OF_HEADER_LINES = 1;
const int SHEET_INDEX = 0;
struct CONNECTORTYPE
{
// Constructeur
CONNECTORTYPE(const std::wstring & sFAMILY, const std::wstring & sDESIGNATION){
FAMILY=sFAMILY;
DESIGNATION=sDESIGNATION;
};
CONNECTORTYPE();
bool egal (const CONNECTORTYPE &b) const;
std::wstring FAMILY;
std::wstring DESIGNATION;
};
static const std::vector <KitListParameter::CONNECTORTYPE> vConnectorType;
};
bool operator==(KitListParameter::CONNECTORTYPE const & a, KitListParameter::CONNECTORTYPE const & b);
le contenu de mon vector de structure ainsi que le code de mon foncteur booléen "egal" dans le cpp correspondant :
const std::vector <KitListParameter::CONNECTORTYPE> vConnectorType = {{L"CONTENU TAF",L"CONTENU TAF"}, {L"CONTENU TAF",L"*"}, {L"CONTENU TAF",L"*"}, {L"CONTENU TAF",L"*"}, {L"CONTENU TAF",L"CONTENU TAF*"}, {L"CONTENU TAF",L"CONTENU TAF*"}, {L"CONTENU TAF",L"*"}, {L"CONTENU TAF",L"*"}, {L"CONTENU TAF",L"*"}, {L"CONTENU TAF",L"*"}, {L"CONTENU TAF",L"CONTENU TAF"}, {L"CONTENU TAF",L"CONTENU TAF"}};
bool KitListParameter::CONNECTORTYPE::egal(const CONNECTORTYPE &b) const
{
std::vector<std::wstring> vSplit;
int pos1,pos2;
unsigned int j;
std::wstring wsDesignation, wsContient, wsTermine, wsCommence, wsCommine;
pos1=-1;
if((b.FAMILY==this->FAMILY && this->DESIGNATION==L"*")
|| (b.FAMILY==this->FAMILY && b.DESIGNATION==this->DESIGNATION))
//soit le FAMILY suffit, soit le FAMILY et la DESIGNATION sont parfaitement identique donc true
return true;
else if(b.FAMILY==this->FAMILY && this->DESIGNATION.find(L"*"))
{
pos1=this->DESIGNATION.find(L"*");
CShared::Split(this->DESIGNATION,vSplit,*L"*");
if(vSplit.size()==1)
{
if(pos1==0)
{
wsDesignation=this->DESIGNATION.substr(1,this->DESIGNATION.size());
if(wsDesignation.find(L"*"))
{
//FAMILY identique & Désignation contient
wsContient=wsDesignation.substr(0,wsDesignation.size()-1);
if (b.DESIGNATION.find(wsContient))
return true;
}
else
{
//FAMILY identique & Désignation se termine par
wsTermine=b.DESIGNATION.substr(b.DESIGNATION.size()-wsDesignation.size(),wsDesignation.size());
if(wsTermine==wsDesignation)
return true;
}
}
else
{
//FAMILY identique & Désignation commence par
wsDesignation=this->DESIGNATION.substr(0,this->DESIGNATION.size()-1);
wsCommence=b.DESIGNATION.substr(0,this->DESIGNATION.size()-1);
if(wsDesignation==wsCommence)
return true;
}
}
else if(vSplit.size()>1)
{
//FAMILY identique & Désignation Commence par contient et se termine par
pos2=0;
for(j=0; j<vSplit.size(); j++)
{
wsCommine=b.DESIGNATION.substr(b.DESIGNATION.find(vSplit[j]),vSplit[j].size());
if(wsCommine==vSplit[j])
pos2++;
}
if (pos2==j)
return true;
}
}
else
return false;
}
A ce stade tout se compile.
Je sais bien que c'est codé comme un enfant avec beaucoup trop de if et autre mais a ce stade c'est tout ce dont je suis capable.
Mon probleme cependant se trouve ailleurs
dans mon code main ou je fais appel à ces éléments, je souhaite tester ma ligne de fichier excel afin de determiner si l'element de cette ligne rentre dans les conditions du foncteur et donc trouve son bonheur dans la liste en dur de mon vector structure à l'aide d'un find:
je n'ai pas surchargé d'opérateur inférieur car je n'en vois pas l'utilité vu que ma fonction doit juste retourner égal ou diffèrent (non égal)
je crois comprendre qu'il y a une incompatibilité de type et que ce doit être lié à l'itérateur mais j'avoue que je ne comprends pas trop le sens de cette erreur.
merci d'avance si quelqu'un sait m'aiguiller sur la résolution de mon problème,
Cdlt,
- Edité par Buntaflex 27 septembre 2021 à 16:37:28
Je n'ai pas regardé tous les détails, mais le premier truc qui devrait te débloquer est que find renvoie un itérateur vers l'élément trouvé, et end() si aucun élément ne correspond.
Ensuite le test d'égalité se fait sur operator==().
j'ai maintenant un probleme de definition de mon tableau vConnectorType, je vais voir d'ou cela peut venir
merci beaucoup
"Kaizoku oni ore wa naru !"
std::find sur un vetor de struct dans une class
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
"Kaizoku oni ore wa naru !"
"Kaizoku oni ore wa naru !"