-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decoupeur.cpp
170 lines (144 loc) · 3.96 KB
/
Decoupeur.cpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*************************************************************************
Decoupeur
-------------------
début : 15/01/2019
copyright : (C) 2019 par Jacquot Pierre
Villenave Sophie
*************************************************************************/
//----- Réalisation de la classe <Decoupeur> (fichier Decoupeur.cpp) -----
//---------------------------------------------------------------- INCLUDE
//-------------------------------------------------------- Include système
#include <iostream>
using namespace std;
//------------------------------------------------------ Include personnel
#include "Decoupeur.h"
//------------------------------------------------------------- Constantes
//----------------------------------------------------------------- PUBLIC
//----------------------------------------------------- Méthodes publiques
bool Decoupeur::LigneSuivante ( )
{
if ( fichier )
{
do
{
getline ( fichier , ligneActuelle );
DecouperLigne ( );
} while ( fichier && !FiltresOK ( ) );
}
return EstOK ( );
} //----- Fin de Méthode
string * Decoupeur::DecouperDate ( ) const
{
return new string ( infos [ 0 ] );
}
string * Decoupeur::DecouperRequete ( ) const
{
return SansArguments ( infos [ 2 ] );
}
string * Decoupeur::DecouperReferer ( ) const
{
string * p;
if ( infos [ 4 ].find ( "http://intranet-if.insa-lyon.fr" ) != string::npos )
p = SansArguments ( infos [ 4 ].substr ( 31 , infos [ 4 ].size ( ) ) );
else
p = SansArguments ( infos [ 4 ] );
return p;
}
string * Decoupeur::DecouperNavigateur ( ) const
{
return new string ( infos [ 5 ] );
}
bool Decoupeur::EstOK ( ) const
{
return fichier.good ( );
}
bool Decoupeur::FiltresOK ( ) const
{
bool conforme = true;
if ( ListeFiltres != nullptr )
{
for ( list<Filtre *>::iterator it = ListeFiltres->begin ( ); it != ListeFiltres->end ( ); ++it )
{
if ( !( *it )->LigneEstConforme ( infos ) )
{
conforme = false;
break;
}
}
}
return conforme;
}
//------------------------------------------------- Surcharge d'opérateurs
//-------------------------------------------- Constructeurs - destructeur
Decoupeur::Decoupeur ( string nomFichier , list<Filtre *> * liste ) : fichier ( nomFichier ) , ligneActuelle ( "" ) , ListeFiltres ( liste )
{
#ifdef MAP
cout << "Appel au constructeur de <Decoupeur>" << endl;
#endif
}
Decoupeur::~Decoupeur ( )
// Algorithme :
//
{
#ifdef MAP
cout << "Appel au destructeur de <Decoupeur>" << endl;
#endif
fichier.close ( );
if ( ListeFiltres != nullptr )
{
for ( list<Filtre*>::iterator it = ListeFiltres->begin ( ); it != ListeFiltres->end ( ); ++it )
{
delete ( *it );
}
delete ListeFiltres;
}
} //----- Fin de ~Decoupeur
//------------------------------------------------------------------ PRIVE
//----------------------------------------------------- Méthodes protégées
void Decoupeur::DecouperLigne ( )
{
char separateurs [ ] = { ':', ':', ' ', '"', ' ', ' ', '"', ' ', '"', '"', '"', '"' };
int indexSep = 0;
char tampon;
string motTampon;
bool enregistrer = false;
int indexString = 0;
string stringTampon = "";
infos.clear ( );
while ( indexSep < 10 )
{
tampon = ligneActuelle [ indexString ];
if ( tampon == separateurs [ indexSep ] )
{
++indexSep;
if ( enregistrer )
{
infos.push_back ( motTampon );
motTampon = "";
}
enregistrer = !enregistrer;
}
else if ( enregistrer )
{
motTampon += tampon;
}
++indexString;
}
}
string * Decoupeur::SansArguments ( const string & url ) const
{
//Suppression des valeurs envoyées au serveur par methode GET
//et des jsession.
//on se focalise sur la ressource demandée.
string * p;
unsigned int posGET = url.find ( "?" );
unsigned int posJSession = url.find ( ";jsession" );
if ( posGET == string::npos && posJSession == string::npos )
p = new string ( url );
else
{
unsigned int posMin = min ( posGET , posJSession );
p = new string ( url.substr ( 0 , posMin ) );
}
return p;
}