changed to using sstream
This commit is contained in:
parent
86fa476c67
commit
153b80440c
22 changed files with 253 additions and 31 deletions
|
|
@ -95,10 +95,15 @@ public :
|
|||
*/
|
||||
void setCurrentFileName()
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream oscount;
|
||||
#else
|
||||
char buff[255];
|
||||
std::ostrstream oscount(buff, 254);
|
||||
#endif
|
||||
oscount << counter;
|
||||
oscount << std::ends;
|
||||
|
||||
currentFileName = dirname + "/" + filename + oscount.str();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,14 +104,23 @@ private:
|
|||
inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
||||
/////////////////////////////////////////////////////////
|
||||
{
|
||||
char snum[255];
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
#else
|
||||
char snum[255];
|
||||
std::ostrstream os(snum, 254);
|
||||
#endif
|
||||
|
||||
os << "300x200-0+" << numWindow*220 << std::ends;
|
||||
numWindow++;
|
||||
char *args[6];
|
||||
args[0] = strdup( "gnuplot" );
|
||||
args[1] = strdup( "-geometry" );
|
||||
#ifdef HAVE_SSTREAM
|
||||
args[2] = strdup( os.str().c_str());
|
||||
#else
|
||||
args[2] = strdup( os.str() );
|
||||
#endif
|
||||
args[3] = strdup( "-title" );
|
||||
args[4] = strdup( _title.c_str() );
|
||||
args[5] = 0;
|
||||
|
|
@ -139,7 +148,7 @@ inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
|||
* Created......: Mon Mar 13 13:50:11 1995
|
||||
* Description..: Communication par pipe bidirectionnel avec un autre process
|
||||
*
|
||||
* Ident........: $Id: eoGnuplot.h,v 1.6 2003-02-27 19:21:18 okoenig Exp $
|
||||
* Ident........: $Id: eoGnuplot.h,v 1.7 2003-02-28 16:49:14 maartenkeijzer Exp $
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -105,8 +105,13 @@ inline void eoGnuplot1DMonitor::FirstPlot()
|
|||
{
|
||||
throw std::runtime_error("Must have some stats to plot!\n");
|
||||
}
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
#else
|
||||
char buff[1024];
|
||||
std::ostrstream os(buff, 1024);
|
||||
#endif
|
||||
|
||||
os << "plot";
|
||||
for (unsigned i=1; i<vec.size(); i++) {
|
||||
os << " '" << getFileName().c_str() <<
|
||||
|
|
@ -116,7 +121,11 @@ inline void eoGnuplot1DMonitor::FirstPlot()
|
|||
}
|
||||
os << "\n";
|
||||
os << '\0';
|
||||
#ifdef HAVE_SSTREAM
|
||||
PipeComSend( gpCom, os.str().c_str());
|
||||
#else
|
||||
PipeComSend( gpCom, buff );
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -100,9 +100,13 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
|
|||
|
||||
virtual void handleBounds(eoRealVectorBounds & _bounds)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
#else
|
||||
// use strstream and not std::stringstream until strstream is in all distributions
|
||||
char buf[1024];
|
||||
std::ostrstream os(buf, 1023);
|
||||
#endif
|
||||
// std::ostrstream os;
|
||||
os << "set autoscale\nset yrange [" ;
|
||||
if (_bounds.isMinBounded(0))
|
||||
|
|
@ -129,13 +133,24 @@ inline eoMonitor& eoGnuplot1DSnapshot::operator() (void)
|
|||
eoFileSnapshot::operator()();
|
||||
|
||||
// sends plot order to gnuplot
|
||||
#ifdef HAVE_SSTREAM
|
||||
//std::string buff; // need local memory
|
||||
std::ostringstream os;
|
||||
#else
|
||||
char buff[1024];
|
||||
std::ostrstream os(buff, 1024);
|
||||
#endif
|
||||
|
||||
os << "set title 'Gen. " << getCounter() << "'; plot '"
|
||||
<< getFileName() << "' notitle with points ps " << pointSize << "\n";
|
||||
os << '\0';
|
||||
// mk: had to use getFilename().c_str(), because it seems the string(stream) lib is screwed in gcc3.2
|
||||
<< getFileName().c_str() << "' notitle with points ps " << pointSize;
|
||||
os << std::endl;
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
PipeComSend( gpCom, os.str().c_str());
|
||||
#else
|
||||
PipeComSend( gpCom, buff );
|
||||
|
||||
#endif
|
||||
return (*this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,7 +152,12 @@ public:
|
|||
interpret_as_rate = true;
|
||||
_value.resize(pos); // get rid of %
|
||||
}
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::istringstream is(_value);
|
||||
#else
|
||||
std::istrstream is(_value.c_str());
|
||||
#endif
|
||||
is >> rate;
|
||||
// now store
|
||||
if (interpret_as_rate)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,13 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
#include <math.h> // for floor
|
||||
#include <string>
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <iterator> // for GCC 3.2
|
||||
#include <stdexcept>
|
||||
|
|
@ -156,8 +162,12 @@ public :
|
|||
|
||||
std::string getValue(void) const
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
#else
|
||||
char buf[1024];
|
||||
std::ostrstream os(buf, 1023);
|
||||
#endif
|
||||
os << repValue;
|
||||
os << std::ends;
|
||||
return os.str();
|
||||
|
|
@ -165,7 +175,11 @@ public :
|
|||
|
||||
void setValue(std::string _value)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::istringstream is(_value);
|
||||
#else
|
||||
std::istrstream is(_value.c_str());
|
||||
#endif
|
||||
is >> repValue;
|
||||
}
|
||||
|
||||
|
|
@ -191,8 +205,11 @@ void eoValueParam<bool>::setValue(std::string _value)
|
|||
repValue = true;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::istringstream is(_value);
|
||||
#else
|
||||
std::istrstream is(_value.c_str());
|
||||
#endif
|
||||
is >> repValue;
|
||||
}
|
||||
|
||||
|
|
@ -202,8 +219,12 @@ template <>
|
|||
std::string eoValueParam<std::pair<double, double> >::getValue(void) const
|
||||
{
|
||||
// use own buffer as MSVC's buffer leaks!
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
#else
|
||||
char buff[1024];
|
||||
std::ostrstream os(buff, 1024);
|
||||
#endif
|
||||
os << repValue.first << ' ' << repValue.second << std::ends;
|
||||
return os.str();
|
||||
}
|
||||
|
|
@ -212,7 +233,11 @@ std::string eoValueParam<std::pair<double, double> >::getValue(void) const
|
|||
template <>
|
||||
void eoValueParam<std::pair<double, double> >::setValue(std::string _value)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::istringstream is(_value);
|
||||
#else
|
||||
std::istrstream is(_value.c_str());
|
||||
#endif
|
||||
is >> repValue.first;
|
||||
is >> repValue.second;
|
||||
}
|
||||
|
|
@ -223,7 +248,11 @@ void eoValueParam<std::pair<double, double> >::setValue(std::string _value)
|
|||
template <>
|
||||
std::string eoValueParam<std::vector<std::vector<double> > >::getValue(void) const
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
#else
|
||||
std::ostrstream os;
|
||||
#endif
|
||||
os << repValue.size() << ' ';
|
||||
for (unsigned i = 0; i < repValue.size(); ++i)
|
||||
{
|
||||
|
|
@ -239,7 +268,11 @@ std::string eoValueParam<std::vector<std::vector<double> > >::getValue(void) con
|
|||
template <>
|
||||
void eoValueParam<std::vector<std::vector<double> > >::setValue(std::string _value)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::istringstream is(_value);
|
||||
#else
|
||||
std::istrstream is(_value.c_str());
|
||||
#endif
|
||||
unsigned i,j,sz;
|
||||
is >> sz;
|
||||
repValue.resize(sz);
|
||||
|
|
@ -262,7 +295,11 @@ void eoValueParam<std::vector<std::vector<double> > >::setValue(std::string _val
|
|||
template <>
|
||||
std::string eoValueParam<std::vector<double> >::getValue(void) const
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
#else
|
||||
std::ostrstream os;
|
||||
#endif
|
||||
os << repValue.size() << ' ';
|
||||
std::copy(repValue.begin(), repValue.end(), std::ostream_iterator<double>(os, " "));
|
||||
os << std::ends;
|
||||
|
|
@ -273,7 +310,11 @@ std::string eoValueParam<std::vector<double> >::getValue(void) const
|
|||
template <>
|
||||
void eoValueParam<std::vector<double> >::setValue(std::string _value)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::istringstream is(_value);
|
||||
#else
|
||||
std::istrstream is(_value.c_str());
|
||||
#endif
|
||||
unsigned sz;
|
||||
is >> sz;
|
||||
repValue.resize(sz);
|
||||
|
|
@ -286,7 +327,11 @@ void eoValueParam<std::vector<double> >::setValue(std::string _value)
|
|||
template <>
|
||||
std::string eoValueParam<std::vector<eoMinimizingFitness> >::getValue(void) const
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
#else
|
||||
std::ostrstream os;
|
||||
#endif
|
||||
os << repValue.size() << ' ';
|
||||
std::copy(repValue.begin(), repValue.end(), std::ostream_iterator<eoMinimizingFitness>(os, " "));
|
||||
os << std::ends;
|
||||
|
|
@ -298,7 +343,11 @@ std::string eoValueParam<std::vector<eoMinimizingFitness> >::getValue(void) cons
|
|||
template <>
|
||||
void eoValueParam<std::vector<eoMinimizingFitness> >::setValue(std::string _value)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::istringstream is(_value);
|
||||
#else
|
||||
std::istrstream is(_value.c_str());
|
||||
#endif
|
||||
unsigned sz;
|
||||
is >> sz;
|
||||
repValue.resize(sz);
|
||||
|
|
|
|||
|
|
@ -94,8 +94,12 @@ eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription,
|
|||
}
|
||||
|
||||
// now read arguments on command-line
|
||||
#ifdef HAVE_SSTREAM
|
||||
stringstream stream;
|
||||
#else
|
||||
strstream stream;
|
||||
|
||||
#endif
|
||||
|
||||
for (i = 1; i < _argc; ++i)
|
||||
{
|
||||
stream << _argv[i] << '\n';
|
||||
|
|
|
|||
|
|
@ -62,12 +62,27 @@ public :
|
|||
Adds a \n before so it does not get mixed up with the rest of the stats
|
||||
that are written by the monitor it is probably used from.
|
||||
*/
|
||||
#ifdef HAVE_SSTREAM
|
||||
void operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
char buffer[1023]; // about one K of space per member
|
||||
value() = "\n# ====== Pop dump =====\n";
|
||||
unsigned howMany=combien?combien:_pop.size();
|
||||
for (unsigned i = 0; i < howMany; ++i)
|
||||
value() = "\n# ====== pop dump =====\n";
|
||||
unsigned howmany=combien?combien:_pop.size();
|
||||
for (unsigned i = 0; i < howmany; ++i)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << _pop[i] << std::endl << std::ends;
|
||||
|
||||
// paranoid:
|
||||
value() += os.str();
|
||||
}
|
||||
}
|
||||
#else
|
||||
void operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
char buffer[1023]; // about one k of space per member
|
||||
value() = "\n# ====== pop dump =====\n";
|
||||
unsigned howmany=combien?combien:_pop.size();
|
||||
for (unsigned i = 0; i < howmany; ++i)
|
||||
{
|
||||
std::ostrstream os(buffer, 1022); // leave space for emergency terminate
|
||||
os << _pop[i] << std::endl << std::ends;
|
||||
|
|
@ -77,6 +92,8 @@ void operator()(const eoPop<EOT>& _pop)
|
|||
value() += buffer;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
unsigned combien;
|
||||
};
|
||||
|
|
@ -106,6 +123,21 @@ public :
|
|||
Adds a \n before so it does not get mixed up with the rest of the stats
|
||||
that are written by the monitor it is probably used from.
|
||||
*/
|
||||
#ifdef HAVE_SSTREAM
|
||||
void operator()(const std::vector<const EOT*>& _pop)
|
||||
{
|
||||
value() = ""; // empty
|
||||
unsigned howMany=combien?combien:_pop.size();
|
||||
for (unsigned i = 0; i < howMany; ++i)
|
||||
{
|
||||
std::ostringstream os; // leave space for emergency terminate
|
||||
os << *_pop[i] << std::endl << std::ends;
|
||||
|
||||
// paranoid:
|
||||
value() += os.str();
|
||||
}
|
||||
}
|
||||
#else
|
||||
void operator()(const std::vector<const EOT*>& _pop)
|
||||
{
|
||||
char buffer[1023]; // about one K of space per member
|
||||
|
|
@ -121,6 +153,7 @@ public :
|
|||
value() += buffer;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
unsigned combien;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,13 @@
|
|||
#endif
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream>
|
||||
#endif
|
||||
|
||||
#include "eoRealBounds.h"
|
||||
#include "eoRealVectorBounds.h"
|
||||
|
||||
|
|
@ -27,7 +33,11 @@ bool remove_leading(std::string & _s, const std::string _delim)
|
|||
|
||||
double read_double(std::string _s)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::istringstream is(_s);
|
||||
#else
|
||||
std::istrstream is(_s.c_str());
|
||||
#endif
|
||||
double r;
|
||||
is >> r;
|
||||
return r;
|
||||
|
|
@ -35,7 +45,11 @@ double read_double(std::string _s)
|
|||
|
||||
int read_int(std::string _s)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::istringstream is(_s);
|
||||
#else
|
||||
std::istrstream is(_s.c_str());
|
||||
#endif
|
||||
int i;
|
||||
is >> i;
|
||||
return i;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,12 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream>
|
||||
#endif
|
||||
|
||||
#include "eoState.h"
|
||||
#include "eoObject.h"
|
||||
|
|
@ -126,9 +131,11 @@ void eoState::load(std::istream& is)
|
|||
removeComment(str, getCommentString());
|
||||
fullstring += str + "\n";
|
||||
}
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
istringstream the_stream(fullstring);
|
||||
#else
|
||||
istrstream the_stream(fullstring.c_str(), fullstring.size());
|
||||
|
||||
#endif
|
||||
object->readFrom(the_stream);
|
||||
}
|
||||
}
|
||||
|
|
@ -163,7 +170,11 @@ string eoState::createObjectName(eoObject* obj)
|
|||
{
|
||||
if (obj == 0)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream os;
|
||||
#else
|
||||
ostrstream os;
|
||||
#endif
|
||||
os << objectMap.size();
|
||||
return os.str();
|
||||
}
|
||||
|
|
@ -175,7 +186,11 @@ string eoState::createObjectName(eoObject* obj)
|
|||
unsigned count = 1;
|
||||
while (it != objectMap.end())
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream os;
|
||||
#else
|
||||
ostrstream os;
|
||||
#endif
|
||||
os << obj->className().c_str() << count++ << ends;
|
||||
|
||||
name = os.str();
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@
|
|||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream>
|
||||
#endif
|
||||
|
||||
#include <utils/eoState.h>
|
||||
#include <utils/eoUpdater.h>
|
||||
|
|
@ -17,8 +20,12 @@ void eoTimedStateSaver::operator()(void)
|
|||
if (now >= last_time + interval)
|
||||
{
|
||||
last_time = now;
|
||||
|
||||
ostrstream os;
|
||||
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream os;
|
||||
#else
|
||||
ostrstream os;
|
||||
#endif
|
||||
os << prefix << (now - first_time) << '.' << extension << ends;
|
||||
state.save(os.str());
|
||||
}
|
||||
|
|
@ -26,7 +33,11 @@ void eoTimedStateSaver::operator()(void)
|
|||
|
||||
void eoCountedStateSaver::doItNow(void)
|
||||
{
|
||||
ostrstream os;
|
||||
#ifdef HAVE_SSTREAM
|
||||
ostringstream os;
|
||||
#else
|
||||
ostrstream os;
|
||||
#endif
|
||||
os << prefix << counter << '.' << extension << ends;
|
||||
state.save(os.str());
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue