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
|
#include <string>
#include <fstream>
#include <iostream>
#include <ext/hash_set>
#include "WeakWords.hh"
using namespace std;
using namespace __gnu_cxx;
//
// Public
//
WeakWords::WeakWords()
{
}
WeakWords::~WeakWords()
{
/* Clean m_weakWordsSet */
__gnu_cxx::hash_set<const char*, __gnu_cxx::hash<const char*>, eqstr>::iterator weakWordsSetIt = m_weakWordsSet.begin();
while(weakWordsSetIt != m_weakWordsSet.end())
{
cout << "Suppression de [" << (*weakWordsSetIt) << "]" << endl;
if((*weakWordsSetIt) != NULL)
{
// Le problème semble être ici
delete[] (*weakWordsSetIt);
}
weakWordsSetIt++;
}
m_weakWordsSet.clear();
}
unsigned int WeakWords::loadWeakWords(const string fileName)
{
m_weakWordsFileName.assign(fileName);
return _loadWeakWords(m_weakWordsFileName.c_str());
}
//
// Private
//
unsigned int WeakWords::_loadWeakWords(const char *fileName)
{
string fileLine;
ifstream weakWordsFile (m_weakWordsFileName.c_str(), ios::in);
if(weakWordsFile.is_open() == false)
{
return 1;
}
while(weakWordsFile.good())
{
weakWordsFile >> fileLine;
if(fileLine.length() > 0)
{
char *t=new char[fileLine.length()+1];
// Le memset est il necessaire ?
//memset(t, 0, fileLine.length());
strcpy(t, fileLine.c_str());
m_weakWordsSet.insert(t);
}
fileLine.clear();
}
weakWordsFile.close();
return 0;
} |
Partager