From 153b80440c12cd996753be6a48902cc700fff043 Mon Sep 17 00:00:00 2001 From: maartenkeijzer Date: Fri, 28 Feb 2003 16:49:19 +0000 Subject: [PATCH] changed to using sstream --- eo/Makefile.am | 2 +- eo/acinclude.m4 | 37 ++++++++++++++++++++++ eo/app/Makefile.am | 2 +- eo/configure.in | 4 ++- eo/doc/Makefile.am | 2 -- eo/src/Makefile.am | 2 +- eo/src/eoCtrlCContinue.cpp | 4 +-- eo/src/eoPop.h | 2 -- eo/src/utils/eoFileSnapshot.h | 5 +++ eo/src/utils/eoGnuplot.h | 13 ++++++-- eo/src/utils/eoGnuplot1DMonitor.h | 9 ++++++ eo/src/utils/eoGnuplot1DSnapshot.h | 21 ++++++++++-- eo/src/utils/eoHowMany.h | 5 +++ eo/src/utils/eoParam.h | 51 +++++++++++++++++++++++++++++- eo/src/utils/eoParser.cpp | 6 +++- eo/src/utils/eoPopStat.h | 41 +++++++++++++++++++++--- eo/src/utils/eoRealBounds.cpp | 14 ++++++++ eo/src/utils/eoState.cpp | 19 +++++++++-- eo/src/utils/eoUpdater.cpp | 19 ++++++++--- eo/test/t-eoGenOp.cpp | 9 ++++-- eo/test/t-eoVirus.cpp | 1 - eo/test/t-eobin.cpp | 16 +++++++++- 22 files changed, 253 insertions(+), 31 deletions(-) create mode 100644 eo/acinclude.m4 diff --git a/eo/Makefile.am b/eo/Makefile.am index e72f4029..3296c41b 100644 --- a/eo/Makefile.am +++ b/eo/Makefile.am @@ -10,7 +10,7 @@ DOCDIR = ~/public_html/eodocs #Directory for indices -- not useful for the user IDXDIR = ~/index -EXTRA_DIST=LICENSE +EXTRA_DIST=LICENSE ############################################################################### diff --git a/eo/acinclude.m4 b/eo/acinclude.m4 new file mode 100644 index 00000000..3454628c --- /dev/null +++ b/eo/acinclude.m4 @@ -0,0 +1,37 @@ +dnl Available from the GNU Autoconf Macro Archive at: +dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_have_sstream.html +dnl +AC_DEFUN([AC_CXX_HAVE_SSTREAM], +[AC_CACHE_CHECK(whether the compiler has stringstream, +ac_cv_cxx_have_sstream, +[AC_REQUIRE([AC_CXX_NAMESPACES]) + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_TRY_COMPILE([#include +#ifdef HAVE_NAMESPACES +using namespace std; +#endif],[stringstream message; message << "Hello"; return 0;], + ac_cv_cxx_have_sstream=yes, ac_cv_cxx_have_sstream=no) + AC_LANG_RESTORE +]) +if test "$ac_cv_cxx_have_sstream" = yes; then + AC_DEFINE(HAVE_SSTREAM,,[define if the compiler has stringstream]) +fi +]) +dnl Available from the GNU Autoconf Macro Archive at: +dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_namespaces.html +dnl +AC_DEFUN([AC_CXX_NAMESPACES], +[AC_CACHE_CHECK(whether the compiler implements namespaces, +ac_cv_cxx_namespaces, +[AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_TRY_COMPILE([namespace Outer { namespace Inner { int i = 0; }}], + [using namespace Outer::Inner; return i;], + ac_cv_cxx_namespaces=yes, ac_cv_cxx_namespaces=no) + AC_LANG_RESTORE +]) +if test "$ac_cv_cxx_namespaces" = yes; then + AC_DEFINE(HAVE_NAMESPACES,,[define if the compiler implements namespaces]) +fi +]) diff --git a/eo/app/Makefile.am b/eo/app/Makefile.am index 54699465..39553c1c 100644 --- a/eo/app/Makefile.am +++ b/eo/app/Makefile.am @@ -4,7 +4,7 @@ ## ############################################################################### -SUBDIRS = gprop mastermind gpsymreg +SUBDIRS = mastermind gpsymreg gprop ############################################################################### diff --git a/eo/configure.in b/eo/configure.in index 90de6124..a728dd4f 100644 --- a/eo/configure.in +++ b/eo/configure.in @@ -22,9 +22,11 @@ AC_CHECK_LIB(eoutils, main) dnl Replace `main' with a function in -lm: AC_CHECK_LIB(m, main) + dnl Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS(limits.h) +#AC_CXX_HAVE_SSTREAM dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -34,5 +36,5 @@ AC_TYPE_SIZE_T dnl Checks for library functions. AC_CHECK_FUNCS(select) -AC_OUTPUT(src/obsolete/Makefile doc/Makefile src/Makefile src/utils/Makefile src/other/Makefile win/Makefile src/gp/Makefile src/es/Makefile src/ga/Makefile test/Makefile contrib/Makefile Makefile app/Makefile app/gprop/Makefile app/mastermind/Makefile app/gpsymreg/Makefile) +AC_OUTPUT(doc/Makefile src/Makefile src/utils/Makefile src/other/Makefile win/Makefile src/gp/Makefile src/es/Makefile src/ga/Makefile test/Makefile contrib/Makefile Makefile app/Makefile app/gprop/Makefile app/mastermind/Makefile app/gpsymreg/Makefile src/do/Makefile) diff --git a/eo/doc/Makefile.am b/eo/doc/Makefile.am index f7779469..64f03e40 100644 --- a/eo/doc/Makefile.am +++ b/eo/doc/Makefile.am @@ -8,8 +8,6 @@ EXTRA_DIST = eo.cfg foot.html html/* latex/* -all: doc - doc: eo.cfg doxygen eo.cfg diff --git a/eo/src/Makefile.am b/eo/src/Makefile.am index 85a048d0..0bf74599 100644 --- a/eo/src/Makefile.am +++ b/eo/src/Makefile.am @@ -4,7 +4,7 @@ ## ############################################################################### -SUBDIRS = es ga gp utils other +SUBDIRS = es ga gp utils other do CPPFLAGS = -O2 lib_LIBRARIES = libeo.a diff --git a/eo/src/eoCtrlCContinue.cpp b/eo/src/eoCtrlCContinue.cpp index 36b0abe7..deec4176 100644 --- a/eo/src/eoCtrlCContinue.cpp +++ b/eo/src/eoCtrlCContinue.cpp @@ -29,7 +29,7 @@ #endif #include -#include +#include // --- Global variables - but don't know what else to do - MS --- bool arret_demande = false; @@ -44,7 +44,7 @@ void signal_handler( int sig ) // --- On veut la paix, jusqu'a la fin --- signal( SIGINT, SIG_IGN ); signal( SIGQUIT, SIG_IGN ); - cerr << "Ctrl C entered ... closing down" << endl ; + std::cerr << "Ctrl C entered ... closing down" << std::endl ; arret_demande = true; } diff --git a/eo/src/eoPop.h b/eo/src/eoPop.h index 46cc2ab9..06babcca 100644 --- a/eo/src/eoPop.h +++ b/eo/src/eoPop.h @@ -26,7 +26,6 @@ #define _EOPOP_H #include -#include #include #include // needed for GCC 3.2 @@ -262,7 +261,6 @@ class eoPop: public std::vector, public eoObject, public eoPersistent //@{ /** * Read object. The EOT class must have a ctor from a stream; - in this case, a strstream is used. * @param _is A std::istream. */ virtual void readFrom(std::istream& _is) diff --git a/eo/src/utils/eoFileSnapshot.h b/eo/src/utils/eoFileSnapshot.h index 354d2c2a..0c89ef7e 100644 --- a/eo/src/utils/eoFileSnapshot.h +++ b/eo/src/utils/eoFileSnapshot.h @@ -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(); } diff --git a/eo/src/utils/eoGnuplot.h b/eo/src/utils/eoGnuplot.h index 0d61e40c..38aea2b4 100644 --- a/eo/src/utils/eoGnuplot.h +++ b/eo/src/utils/eoGnuplot.h @@ -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 $ * ---------------------------------------------------------------------- */ diff --git a/eo/src/utils/eoGnuplot1DMonitor.h b/eo/src/utils/eoGnuplot1DMonitor.h index 00799f6e..05af81d5 100644 --- a/eo/src/utils/eoGnuplot1DMonitor.h +++ b/eo/src/utils/eoGnuplot1DMonitor.h @@ -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> rate; // now store if (interpret_as_rate) diff --git a/eo/src/utils/eoParam.h b/eo/src/utils/eoParam.h index 1a0354a4..c1f75092 100644 --- a/eo/src/utils/eoParam.h +++ b/eo/src/utils/eoParam.h @@ -30,7 +30,13 @@ //----------------------------------------------------------------------------- #include // for floor #include + +#ifdef HAVE_SSTREAM +#include +#else #include +#endif + #include #include // for GCC 3.2 #include @@ -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::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 >::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 >::getValue(void) const template <> void eoValueParam >::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 >::setValue(std::string _value) template <> std::string eoValueParam > >::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 > >::getValue(void) con template <> void eoValueParam > >::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 > >::setValue(std::string _val template <> std::string eoValueParam >::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(os, " ")); os << std::ends; @@ -273,7 +310,11 @@ std::string eoValueParam >::getValue(void) const template <> void eoValueParam >::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 >::setValue(std::string _value) template <> std::string eoValueParam >::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(os, " ")); os << std::ends; @@ -298,7 +343,11 @@ std::string eoValueParam >::getValue(void) cons template <> void eoValueParam >::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); diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index c002cfd6..68f59323 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -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'; diff --git a/eo/src/utils/eoPopStat.h b/eo/src/utils/eoPopStat.h index 80ecb6fd..4c06f2d5 100644 --- a/eo/src/utils/eoPopStat.h +++ b/eo/src/utils/eoPopStat.h @@ -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& _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& _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& _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& _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& _pop) { char buffer[1023]; // about one K of space per member @@ -121,6 +153,7 @@ public : value() += buffer; } } +#endif private: unsigned combien; }; diff --git a/eo/src/utils/eoRealBounds.cpp b/eo/src/utils/eoRealBounds.cpp index 647f3db0..e052a341 100644 --- a/eo/src/utils/eoRealBounds.cpp +++ b/eo/src/utils/eoRealBounds.cpp @@ -4,7 +4,13 @@ #endif #include + +#ifdef HAVE_SSTREAM +#include +#else #include +#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; diff --git a/eo/src/utils/eoState.cpp b/eo/src/utils/eoState.cpp index baf57c7d..e8eec0dd 100644 --- a/eo/src/utils/eoState.cpp +++ b/eo/src/utils/eoState.cpp @@ -5,7 +5,12 @@ #include #include + +#ifdef HAVE_SSTREAM +#include +#else #include +#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(); diff --git a/eo/src/utils/eoUpdater.cpp b/eo/src/utils/eoUpdater.cpp index 87759cb4..dd30b4b4 100644 --- a/eo/src/utils/eoUpdater.cpp +++ b/eo/src/utils/eoUpdater.cpp @@ -2,8 +2,11 @@ #pragma warning(disable:4786) #endif - +#ifdef HAVE_SSTREAM +#include +#else #include +#endif #include #include @@ -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()); } diff --git a/eo/test/t-eoGenOp.cpp b/eo/test/t-eoGenOp.cpp index e85fe19a..23d1c8f8 100644 --- a/eo/test/t-eoGenOp.cpp +++ b/eo/test/t-eoGenOp.cpp @@ -176,10 +176,15 @@ void init(eoPop & _pop, unsigned _pSize) } for (unsigned i=0; i<_pSize; i++) { - char s[255]; +#ifdef HAVE_SSTREAM + std::ostringstream os; +#else + char s[255]; std::ostrstream os(s, 254); +#endif + os << i << std::ends; - _pop[i] = Dummy(s); + _pop[i] = Dummy(os.str()); _pop[i].fitness(i); } } diff --git a/eo/test/t-eoVirus.cpp b/eo/test/t-eoVirus.cpp index 612906a9..7c127c3b 100644 --- a/eo/test/t-eoVirus.cpp +++ b/eo/test/t-eoVirus.cpp @@ -24,7 +24,6 @@ //----------------------------------------------------------------------------- #include // std::cout -#include // ostrstream, istrstream #include // general EO #include "../contrib/MGE/VirusOp.h" #include "../contrib/MGE/eoVirus.h" diff --git a/eo/test/t-eobin.cpp b/eo/test/t-eobin.cpp index 220df5fa..7c14c6de 100644 --- a/eo/test/t-eobin.cpp +++ b/eo/test/t-eobin.cpp @@ -24,7 +24,13 @@ //----------------------------------------------------------------------------- #include // std::cout + +#ifdef HAVE_SSTREAM +#include +#else #include // ostrstream, istrstream +#endif + #include // general EO #include // bitstring representation & operators #include @@ -56,11 +62,19 @@ void main_function() std::cout << "chrom: " << chrom << std::endl << "chrom2: " << chrom2 << std::endl; - + +#ifdef HAVE_SSTREAM + std::ostringstream os; +#else char buff[1024]; std::ostrstream os(buff, 1024); +#endif os << chrom; +#ifdef HAVE_SSTREAM + std::istringstream is(os.str()); +#else std::istrstream is(os.str()); +#endif is >> chrom2; chrom.fitness(binary_value(chrom2)); std::cout << "\nTesting reading, writing\n";