X-Git-Url: https://ruin.nu/git/index.pl?a=blobdiff_plain;f=src%2Fsortaction.h;h=c56d0ee42a304bdf26db992f36d4c61a5f374f7a;hb=efe42ca948704593c847996d0ae8da71d15bb75b;hp=b6c5df74278f85d08540678674ffb6c7d384a650;hpb=47b1f5c0294e079bc120dc8366977951aa0778bf;p=germs.git diff --git a/src/sortaction.h b/src/sortaction.h index b6c5df7..c56d0ee 100644 --- a/src/sortaction.h +++ b/src/sortaction.h @@ -21,20 +21,89 @@ #ifndef __SORTACTION_H__ #define __SORTACTION_H__ +#include +#include +class GeneOrder; + + +class SortActionImpl{ + public: + + virtual ~SortActionImpl(){}; + + /** + * Applies the action on the GeneOrder and returning it. + */ + virtual GeneOrder& operator()(GeneOrder& go) const = 0; + + /** + * Compares sort actions. + */ + virtual bool operator==(const SortActionImpl& sa) const = 0; + + /** + * Gives a string representation of the action, for output + */ + virtual std::string toString() const = 0; +}; + /** - * Abstraction of a sort action, keeping track of score + * Abstraction of a sort action, all child actions has to be immutable. * * \author Michael Andreen */ class SortAction{ public: + typedef std::tr1::shared_ptr ActionPointer; - virtual ~SortAction(){}; + /** + * Creates a new sort action, given a specified action. + * SortAction promises to remove the given action. + */ + SortAction(SortActionImpl* sa): _action(sa){ + } + + SortAction(const SortAction& sa): _action(sa._action){ + } + + const SortAction& operator=(const SortAction& sa){ + if (this != &sa) + _action = sa._action; + return *this; + } + + ~SortAction(){}; + + /** + * Applies the action on the GeneOrder and returning it. + */ + GeneOrder& operator()(GeneOrder& go) const{ + return (*_action)(go); + } /** - * Sort SortActions by score + * Compares sort actions. */ - virtual operator<(const SortAction& sa) const; + bool operator==(const SortAction& sa) const{ + return (*_action) == (*sa._action); + } + + /** + * Compares sort actions. + */ + bool operator==(const SortActionImpl& sa) const{ + return (*_action) == sa; + } + + /** + * Gives a string representation of the action, for output + */ + std::string toString() const{ + return _action->toString(); + } + private: + ActionPointer _action; + }; #endif