1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include "Appel.h"
#include "function.h"
#include <map> //tableau associatif
#include <algorithm>
using namespace std;
Appel::Appel : m_numAppelant(0) ,m_numDestination(0) ,m_date(0) ,m_duree(0) ,m_type("local") ,m_numTransfer(0) ,m_cos(0) ,m_terminal(0) ,m_cosExist("false") ,m_transferExist("false")
{
//ctor par defaut
}
Appel::Appel (unsigned int numAppelant,unsigned int numDestination,time_t dateAppel,unsigned int duree,unsigned int transfert,unsigned int cos,unsigned int terminal): m_numAppelant(0) ,m_numDestination(0) ,m_date(0) ,m_duree(0) ,m_numTransfer(0) ,m_cos(0) ,m_terminal(0)
//ctor utilise par le programme normalement
{
//Determination du type de l'appel
string arrStr[3] = {"local", "regional", "international"};
do
{
for (string* p = &arrStr[0]; p != &arrStr[3]; ++p)
{
string listInd;
//Recuperation des indicatifs dans le fichier de configuration
listInd=getConfig ("INDICATIFS",*p,fichierConfiguration);
//separation des differents indicatifs
vector<string> listCodechar;
listCodechar=extractSbstr(listInd,separateur);
//Insertion du resultat dans un tableau associatif
map <string, vector> tableauIndicatif;
tableauIndicatif[*p]=listCodechar;
};
}while (!tableauIndicatif);
//on convertit le numero de destination en chaine de caracteres pour pouvoir faire une comparaison avec l'indicatif
string destination=convertIntString(m_numDestination);
for (string* p = &arrStr[0]; p != &arrStr[3]; ++p)
{
listCodechar=tableauIndicatif[*p];//on recupere les indicatifs de chaque type d'appel
for (int i = 0 ; i < tableauIndicatif.size() ; ++i)
{
int taille=listCodechar[i].length;//on determine la taille de l'indicatif
if (tableauIndicatif==destination.sbstr(0,taille)) m_type=*p;//si les premiers chiffres de la destination alors le type de l'appel est connu.
};
};
//Valeur de cosExist est "true" si l'appel a ete fait avec un cos
if (cos==0) m_cosExist("false") else m_cosExist("true");
//valeur de transferExist est "true" si l'appel a ete transfere
if (transfert==0) m_transferExist("false") else m_transferExist("true");
}
Appel::~Appel()
{
//dtor
}
void Appel::enregistrerDB () const
{
MYSQL *mysql=NULL;
if(mysqlconnect(DB)==0)
{
mysqlsetcall(mysql);
mysql_close(&mysql);
return 0;
}
else return 1;
}
//enregistre un appel dans la base de données
int mysqlsetcall()
{
mysql_query(&mysql,"INSERT INTO callid VALUES(' ',m_dateAppel.day,m_dateAppel.moment,m_duree,m_numTransfer,m_numDestination,m_cos,m_transferExist,m_cosExist,m_terminal,m_numAppelant)");
mysql_query(&mysql,"INSERT INTO destination VALUES(m_numDestination,m_type)");
return 0;
}
//Extraire des sous-chaines delimites par des sperateurs d'une chaine et les mets dans un tableau dynamique
vector <string> extractSbstr(string chaine,char charSeparateur)
{
string mot;
vector <string> tableauMots;
while ( std::getline( iss, mot, charSeparateur ) )
{
tableauMots.pushback(mot);
i++;
};
return (tableauMots);
} |
Partager