fixed (?) some problems with stringstreams and std::ends
This commit is contained in:
parent
07a3e56db1
commit
eaabc7ae3b
10 changed files with 57 additions and 50 deletions
|
|
@ -21,7 +21,7 @@
|
|||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mak@dhi.dk
|
||||
CVS Info: $Date: 2003-02-27 19:25:48 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/eoVariableLengthCrossover.h,v 1.8 2003-02-27 19:25:48 okoenig Exp $ $Author: okoenig $
|
||||
CVS Info: $Date: 2003-03-21 02:38:57 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/eoVariableLengthCrossover.h,v 1.9 2003-03-21 02:38:57 maartenkeijzer Exp $ $Author: maartenkeijzer $
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -150,10 +150,17 @@ public :
|
|||
|
||||
virtual std::string className() const
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
os << "eoVlAtomExchangeQuadOp(" << atomExchange.className() << ")";
|
||||
return os.str()
|
||||
#else
|
||||
|
||||
char s[1024];
|
||||
std::ostrstream os(s, 1022);
|
||||
os << "eoVlAtomExchangeQuadOp(" << atomExchange.className() << ")" << std::ends;
|
||||
return std::string(s);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
Marc.Schoenauer@polytechnique.fr
|
||||
mak@dhi.dk
|
||||
CVS Info: $Date: 2003-02-27 19:25:48 $ $Version$ $Author: okoenig $
|
||||
CVS Info: $Date: 2003-03-21 02:38:57 $ $Version$ $Author: maartenkeijzer $
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -140,11 +140,17 @@ public :
|
|||
}
|
||||
|
||||
virtual std::string className() const
|
||||
{
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
os << "eoVlDelMutation("<<chooser.className() << ")";
|
||||
return os.str();
|
||||
#else
|
||||
char s[1024];
|
||||
std::ostrstream os(s, 1022);
|
||||
os << "eoVlDelMutation(" << chooser.className() << ")" << std::ends;
|
||||
return std::string(s);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ std::string rng_to_string(const eoRng& _rng)
|
|||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
void rng_from_string(eoRng& _rng, std::string s)
|
||||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
|
|
@ -63,6 +64,21 @@ void rng_from_string(eoRng& _rng, std::string s)
|
|||
_rng.readFrom(is);
|
||||
}
|
||||
|
||||
struct RNG_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static
|
||||
boost::python::tuple getstate(const eoRng& _rng)
|
||||
{
|
||||
return boost::python::make_tuple(str(rng_to_string(_rng)));
|
||||
}
|
||||
static
|
||||
void setstate(eoRng& _rng, boost::python::tuple pickled)
|
||||
{
|
||||
std::string state = extract<std::string>(pickled[0]);
|
||||
rng_from_string(_rng, state);
|
||||
}
|
||||
};
|
||||
|
||||
int spin(eoRng& _rng, numeric::array values, double total)
|
||||
{
|
||||
if (total == 0.0)
|
||||
|
|
@ -97,6 +113,7 @@ void random_numbers()
|
|||
.def("to_string", rng_to_string)
|
||||
.def("from_string", rng_from_string)
|
||||
.def("roulette_wheel", spin)
|
||||
.def_pickle(RNG_pickle_suite())
|
||||
;
|
||||
|
||||
def("rng", get_rng, return_value_policy<reference_existing_object>());
|
||||
|
|
|
|||
|
|
@ -69,28 +69,7 @@ class TestPickling(unittest.TestCase):
|
|||
for i in range(10):
|
||||
rng().rand()
|
||||
|
||||
filename = tempfile.mktemp()
|
||||
file = open(filename, 'wb')
|
||||
pickler = cPickle.Pickler(file)
|
||||
|
||||
s = rng().to_string()
|
||||
|
||||
pickler.dump(s);
|
||||
del pickler
|
||||
file.close()
|
||||
|
||||
file = open(filename)
|
||||
|
||||
unpickler = cPickle.Unpickler(file)
|
||||
|
||||
s = unpickler.load()
|
||||
|
||||
rng2 = eoRng(1)
|
||||
rng2.from_string(s)
|
||||
|
||||
del unpickler
|
||||
file.close()
|
||||
os.remove(filename)
|
||||
rng2 = self.do_pickle(rng())
|
||||
|
||||
for i in range(100):
|
||||
a = rng().rand()
|
||||
|
|
@ -99,19 +78,7 @@ class TestPickling(unittest.TestCase):
|
|||
|
||||
def vParam(self,v):
|
||||
|
||||
filename = tempfile.mktemp()
|
||||
file = open(filename,'wb')
|
||||
pickler = cPickle.Pickler(file)
|
||||
|
||||
pickler.dump(v)
|
||||
del pickler
|
||||
file.close()
|
||||
file = open(filename)
|
||||
|
||||
unpickler = cPickle.Unpickler(file)
|
||||
|
||||
v2 = unpickler.load();
|
||||
|
||||
v2 = self.do_pickle(v);
|
||||
self.failUnlessEqual(v.value, v2.value)
|
||||
|
||||
def testValueParam(self):
|
||||
|
|
|
|||
|
|
@ -97,12 +97,13 @@ public :
|
|||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream oscount;
|
||||
oscount << counter;
|
||||
#else
|
||||
char buff[255];
|
||||
std::ostrstream oscount(buff, 254);
|
||||
#endif
|
||||
oscount << counter;
|
||||
oscount << std::ends;
|
||||
#endif
|
||||
|
||||
currentFileName = dirname + "/" + filename + oscount.str();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,12 +106,13 @@ inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
|
|||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
os << "300x200-0+" << numWindow*220;
|
||||
#else
|
||||
char snum[255];
|
||||
std::ostrstream os(snum, 254);
|
||||
os << "300x200-0+" << numWindow*220 << std::ends;
|
||||
#endif
|
||||
|
||||
os << "300x200-0+" << numWindow*220 << std::ends;
|
||||
numWindow++;
|
||||
char *args[6];
|
||||
args[0] = strdup( "gnuplot" );
|
||||
|
|
@ -148,7 +149,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.7 2003-02-28 16:49:14 maartenkeijzer Exp $
|
||||
* Ident........: $Id: eoGnuplot.h,v 1.8 2003-03-21 02:39:09 maartenkeijzer Exp $
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -120,10 +120,10 @@ inline void eoGnuplot1DMonitor::FirstPlot()
|
|||
os << ", ";
|
||||
}
|
||||
os << '\n';
|
||||
os << std::ends;
|
||||
#ifdef HAVE_SSTREAM
|
||||
PipeComSend( gpCom, os.str().c_str());
|
||||
#else
|
||||
os << std::ends;
|
||||
PipeComSend( gpCom, buff );
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,9 +132,9 @@ public:
|
|||
virtual void printOn(std::ostream& _os) const
|
||||
{
|
||||
if (combien == 0)
|
||||
_os << 100*rate << "% " << std::ends;
|
||||
_os << 100*rate << "% ";
|
||||
else
|
||||
_os << combien << " " << std::ends;
|
||||
_os << combien << " ";
|
||||
return;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,12 +164,13 @@ public :
|
|||
{
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
os << repValue;
|
||||
#else
|
||||
char buf[1024];
|
||||
std::ostrstream os(buf, 1023);
|
||||
#endif
|
||||
os << repValue;
|
||||
os << std::ends;
|
||||
#endif
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
@ -221,11 +222,12 @@ std::string eoValueParam<std::pair<double, double> >::getValue(void) const
|
|||
// use own buffer as MSVC's buffer leaks!
|
||||
#ifdef HAVE_SSTREAM
|
||||
std::ostringstream os;
|
||||
os << repValue.first << ' ' << repValue.second;
|
||||
#else
|
||||
char buff[1024];
|
||||
std::ostrstream os(buff, 1024);
|
||||
#endif
|
||||
os << repValue.first << ' ' << repValue.second << std::ends;
|
||||
#endif
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +262,9 @@ std::string eoValueParam<std::vector<std::vector<double> > >::getValue(void) con
|
|||
std::copy(repValue[i].begin(), repValue[i].end(), std::ostream_iterator<double>(os, " "));
|
||||
}
|
||||
|
||||
#ifndef HAVE_SSTREAM
|
||||
os << std::ends;
|
||||
#endif
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
@ -302,7 +306,9 @@ std::string eoValueParam<std::vector<double> >::getValue(void) const
|
|||
#endif
|
||||
os << repValue.size() << ' ';
|
||||
std::copy(repValue.begin(), repValue.end(), std::ostream_iterator<double>(os, " "));
|
||||
#ifndef HAVE_SSTREAM
|
||||
os << std::ends;
|
||||
#endif
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +340,9 @@ std::string eoValueParam<std::vector<eoMinimizingFitness> >::getValue(void) cons
|
|||
#endif
|
||||
os << repValue.size() << ' ';
|
||||
std::copy(repValue.begin(), repValue.end(), std::ostream_iterator<eoMinimizingFitness>(os, " "));
|
||||
os << std::ends;
|
||||
#ifndef HAVE_SSTREAM
|
||||
os<< std::ends;
|
||||
#endif
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ void operator()(const eoPop<EOT>& _pop)
|
|||
for (unsigned i = 0; i < howmany; ++i)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << _pop[i] << std::endl << std::ends;
|
||||
os << _pop[i] << std::endl;
|
||||
|
||||
// paranoid:
|
||||
value() += os.str();
|
||||
|
|
@ -130,8 +130,8 @@ public :
|
|||
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;
|
||||
std::ostringstream os;
|
||||
os << *_pop[i] << std::endl;
|
||||
|
||||
// paranoid:
|
||||
value() += os.str();
|
||||
|
|
|
|||
Reference in a new issue