add the feature to update a single file instead of creating a new one

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@311 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2007-06-19 07:31:00 +00:00
commit 335b1f9fc1

View file

@ -33,9 +33,11 @@ public:
* Ctor * Ctor
* @param _arch local archive * @param _arch local archive
* @param _filename target filename * @param _filename target filename
* @param _count put this variable to true if you want a new file to be created each time () is called and to false if you only want the file to be updated
* @param _id own ID * @param _id own ID
*/ */
moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<MOEOT> & _arch, const std::string & _filename, int _id = -1) : arch(_arch), filename(_filename), id(_id), counter(0) moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<MOEOT> & _arch, const std::string & _filename, bool _count = false, int _id = -1) :
arch(_arch), filename(_filename), count(_count), counter(0), id(_id)
{} {}
/** /**
@ -43,10 +45,29 @@ public:
*/ */
void operator()() { void operator()() {
char buff[MAX_BUFFER_SIZE]; char buff[MAX_BUFFER_SIZE];
if (id == -1) if (count)
sprintf (buff, "%s.%u", filename.c_str(), counter ++); {
if (id == -1)
{
sprintf (buff, "%s.%u", filename.c_str(), counter ++);
}
else
{
sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++);
}
}
else else
sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++); {
if (id == -1)
{
sprintf (buff, "%s", filename.c_str());
}
else
{
sprintf (buff, "%s.%u", filename.c_str(), id);
}
counter ++;
}
std::ofstream f(buff); std::ofstream f(buff);
for (unsigned i = 0; i < arch.size (); i++) for (unsigned i = 0; i < arch.size (); i++)
f << arch[i].objectiveVector() << std::endl; f << arch[i].objectiveVector() << std::endl;
@ -60,10 +81,12 @@ private:
moeoArchive<MOEOT> & arch; moeoArchive<MOEOT> & arch;
/** target filename */ /** target filename */
std::string filename; std::string filename;
/** own ID */ /** this variable is set to true if a new file have to be created each time () is called and to false if the file only HAVE to be updated */
int id; bool count;
/** counter */ /** counter */
unsigned counter; unsigned counter;
/** own ID */
int id;
}; };