From f357a908bfd8de6308317eac4a814ac1af9fb10b Mon Sep 17 00:00:00 2001 From: mac Date: Sun, 9 Apr 2000 09:46:20 +0000 Subject: [PATCH] Updated documentation to give proper include file in doxygen and define a module selectors Also added a load(stream) and save(stream) to eoState --- eo/src/utils/eoFileMonitor.cpp | 4 ++-- eo/src/utils/eoMonitor.h | 3 ++- eo/src/utils/eoRNG.h | 5 +++-- eo/src/utils/eoStat.h | 5 +++-- eo/src/utils/eoState.cpp | 20 ++++++++++++++++++-- eo/src/utils/eoState.h | 14 ++++++++++++++ eo/src/utils/selectors.h | 4 ++++ 7 files changed, 46 insertions(+), 9 deletions(-) diff --git a/eo/src/utils/eoFileMonitor.cpp b/eo/src/utils/eoFileMonitor.cpp index f0c0047c..43dbeb60 100644 --- a/eo/src/utils/eoFileMonitor.cpp +++ b/eo/src/utils/eoFileMonitor.cpp @@ -8,7 +8,7 @@ using namespace std; -void eoFileMonitor::operator()(void) +eoMonitor& eoFileMonitor::operator()(void) { if (firsttime) { @@ -53,6 +53,6 @@ void eoFileMonitor::operator()(void) os << ',' << (*it)->getValue(); } - // and we're there + return *this; } diff --git a/eo/src/utils/eoMonitor.h b/eo/src/utils/eoMonitor.h index 3348403c..d79d8245 100644 --- a/eo/src/utils/eoMonitor.h +++ b/eo/src/utils/eoMonitor.h @@ -45,7 +45,8 @@ public : virtual ~eoMonitor() {} - virtual void operator()(void) = 0; + /** Just do it! */ + virtual eoMonitor& operator()(void) = 0; void add(const eoParam& _param) { push_back(&_param); } }; diff --git a/eo/src/utils/eoRNG.h b/eo/src/utils/eoRNG.h index 063e4dbc..1dcd0a61 100644 --- a/eo/src/utils/eoRNG.h +++ b/eo/src/utils/eoRNG.h @@ -86,7 +86,7 @@ #include "../eoObject.h" // TODO: check for various compilers if this is exactly 32 bits -// Unfortunately MSVC's preprocessor does not comprehends sizeof() +// Unfortunately MSVC's preprocessor does not comprehend sizeof() // so neat preprocessing tricks will not work typedef unsigned long uint32; // Compiler and platform dependent! @@ -95,7 +95,8 @@ typedef unsigned long uint32; // Compiler and platform dependent! // eoRng //----------------------------------------------------------------------------- /** -eoRng is a persitent class that uses the ``Mersenne Twister'' random number generator MT19937 +\class eoRng eoRNG.h utils/eoRNG.h +eoRng is a persistent class that uses the ``Mersenne Twister'' random number generator MT19937 for generating random numbers. The various member functions implement useful functions for evolutionary algorithms. Included are: rand(), random(), flip() and normal(). diff --git a/eo/src/utils/eoStat.h b/eo/src/utils/eoStat.h index 0ae64113..92a8c794 100644 --- a/eo/src/utils/eoStat.h +++ b/eo/src/utils/eoStat.h @@ -36,6 +36,9 @@ class eoStatBase public : virtual ~eoStatBase(){} + /** + calculate some statistic on the population + */ virtual void operator()(const eoPop& _pop) = 0; }; @@ -44,8 +47,6 @@ class eoStat : public eoValueParam, public eoStatBase { public : eoStat(T _value, std::string _description) : eoValueParam(_value, _description) {} - - virtual void operator()(const eoPop& _pop) = 0; }; #include diff --git a/eo/src/utils/eoState.cpp b/eo/src/utils/eoState.cpp index 5a14e743..d69c23d3 100644 --- a/eo/src/utils/eoState.cpp +++ b/eo/src/utils/eoState.cpp @@ -61,7 +61,18 @@ void eoState::registerObject(eoPersistent& registrant) void eoState::load(const string& _filename) { ifstream is (_filename.c_str()); + + if (!is) + { + string str = "Could not open file " + _filename; + throw runtime_error(str); + } + load(is); +} + +void eoState::load(std::istream& is) +{ string str; string name; @@ -69,7 +80,7 @@ void eoState::load(const string& _filename) if (is.fail()) { - string str = "Could not open file " + _filename; + string str = "Error while reading stream"; throw runtime_error(str); } @@ -119,12 +130,17 @@ void eoState::save(const string& filename) const { // saves in order of insertion ofstream os(filename.c_str()); - if (os.fail()) + if (!os) { string msg = "Could not open file: " + filename + " for writing!"; throw runtime_error(msg); } + save(os); +} + +void eoState::save(std::ostream& os) const +{ // saves in order of insertion for (vector::const_iterator it = creationOrder.begin(); it != creationOrder.end(); ++it) { os << "\\section{" << (*it)->first << "}\n"; diff --git a/eo/src/utils/eoState.h b/eo/src/utils/eoState.h index fd50cc9b..05316784 100644 --- a/eo/src/utils/eoState.h +++ b/eo/src/utils/eoState.h @@ -66,12 +66,26 @@ public : */ void load(const std::string& _filename); + /** + * Reads the file specified + * + * @param is the stream to load from + */ + void load(std::istream& is); + /** * Saves the state in file specified * * @param _filename the name of the file to save into */ void save(const std::string& _filename) const; + + /** + * Saves the state in file specified + * + * @param os the stream to save into + */ + void save(std::ostream& os) const; private : std::string createObjectName(eoObject* obj); diff --git a/eo/src/utils/selectors.h b/eo/src/utils/selectors.h index bb99bb2d..2d9a3db7 100644 --- a/eo/src/utils/selectors.h +++ b/eo/src/utils/selectors.h @@ -42,6 +42,10 @@ #include "eoRNG.h" +/** +\defgroup selectors +*/ + template bool minimizing_fitness() {