From: Michael Andreen Date: Wed, 27 Jun 2007 06:03:23 +0000 (+0000) Subject: toString for actions X-Git-Tag: v0.1~40 X-Git-Url: https://ruin.nu/git/?p=germs.git;a=commitdiff_plain;h=6ed5c4682ee599c7d03d8c67dcca3ac4033a63ec toString for actions --- diff --git a/src/genesorter.cpp b/src/genesorter.cpp index d73f176..7553688 100644 --- a/src/genesorter.cpp +++ b/src/genesorter.cpp @@ -41,6 +41,7 @@ GeneSorter::ActionList GeneSorter::sort(const GeneOrder& go){ ActionList safe = safeActions(temp); if (safe.size() > 0){ safe[0](temp); + cout << "Action: " << safe[0].toString() << " "; al.push_back(safe[0]); }else return ActionList(); //TODO: Need to handle hurdles. diff --git a/src/reverseaction.h b/src/reverseaction.h index 76ab666..006c9eb 100644 --- a/src/reverseaction.h +++ b/src/reverseaction.h @@ -25,6 +25,7 @@ #include "genealgorithms.h" #include +#include /** * Reverses an interval @@ -59,6 +60,15 @@ class ReverseAction : public SortAction{ } return false; } + + /** + * Gives a string representation of the action, for output + */ + virtual std::string toString() const{ + std::ostringstream os; + os << "[" << _i << "," << _j << "]"; + return os.str(); + } private: size_t _i; size_t _j; diff --git a/src/sortaction.h b/src/sortaction.h index 0e59cd3..66c337c 100644 --- a/src/sortaction.h +++ b/src/sortaction.h @@ -22,6 +22,7 @@ #define __SORTACTION_H__ #include +#include class GeneOrder; /** * Abstraction of a sort action, all child actions has to be immutable. @@ -63,6 +64,13 @@ class SortAction{ virtual bool operator==(const SortAction& sa) const{ return (*_action) == (sa._action.get() == 0 ? sa : *sa._action); } + + /** + * Gives a string representation of the action, for output + */ + virtual std::string toString() const{ + return _action->toString(); + } private: ActionPointer _action;