X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=src%2Fsortaction.h;h=faec98a0c2e94681dcba096714d7f4c2e47759d6;hb=d7c119fefaf9cce07974afbefb4b6a017689a961;hp=0e59cd385e1701eff4b2a592fbd0dc9aae2c73bb;hpb=1c14858d7eb8283d147fbe11963d7b32b221a98b;p=germs.git diff --git a/src/sortaction.h b/src/sortaction.h index 0e59cd3..faec98a 100644 --- a/src/sortaction.h +++ b/src/sortaction.h @@ -22,7 +22,31 @@ #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, all child actions has to be immutable. * @@ -30,38 +54,59 @@ class GeneOrder; */ class SortAction{ public: - typedef std::tr1::shared_ptr ActionPointer; + 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(SortActionImpl* sa): _action(sa){ } SortAction(const SortAction& sa): _action(sa._action){ } - virtual const SortAction& operator=(const SortAction& sa){ + const SortAction& operator=(const SortAction& sa){ if (this != &sa) _action = sa._action; return *this; } - virtual ~SortAction(){}; + ~SortAction(){}; /** * Applies the action on the GeneOrder and returning it. */ - virtual GeneOrder& operator()(GeneOrder& go) const{ + GeneOrder& operator()(GeneOrder& go) const{ return (*_action)(go); } /** * Compares sort actions. */ - virtual bool operator==(const SortAction& sa) const{ - return (*_action) == (sa._action.get() == 0 ? sa : *sa._action); + 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(); + } + + /** + * Gives access to the implementation + */ + const SortActionImpl& impl(){ + return *_action; } private: ActionPointer _action;