X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=src%2Fsortaction.h;h=66c337ca625cac468b113debc86c1cd224029a76;hb=4b63e18f4e100d3506ed170d4798539b08d19bc0;hp=a71a533cf70ec981f10d32527053e58cdf0a609b;hpb=d0abe1592fcbb10f4ac303e7b66c384624d4d439;p=germs.git diff --git a/src/sortaction.h b/src/sortaction.h index a71a533..66c337c 100644 --- a/src/sortaction.h +++ b/src/sortaction.h @@ -21,30 +21,59 @@ #ifndef __SORTACTION_H__ #define __SORTACTION_H__ +#include +#include class GeneOrder; /** - * Abstraction of a sort action + * Abstraction of a sort action, all child actions has to be immutable. * * \author Michael Andreen */ class SortAction{ public: + typedef std::tr1::shared_ptr ActionPointer; + /** + * Creates a new sort action, given a specified action. + * SortAction promises to remove the given action. + */ + SortAction(SortAction* sa): _action(sa){ + } + + SortAction(const SortAction& sa): _action(sa._action){ + } + + virtual const SortAction& operator=(const SortAction& sa){ + if (this != &sa) + _action = sa._action; + return *this; + } + virtual ~SortAction(){}; /** * Applies the action on the GeneOrder and returning it. */ virtual GeneOrder& operator()(GeneOrder& go) const{ - return go; + return (*_action)(go); } /** * Compares sort actions. */ virtual bool operator==(const SortAction& sa) const{ - return false; + 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; + }; #endif