X-Git-Url: https://ruin.nu/git/?p=germs.git;a=blobdiff_plain;f=src%2Fsortaction.h;h=c56d0ee42a304bdf26db992f36d4c61a5f374f7a;hp=66c337ca625cac468b113debc86c1cd224029a76;hb=efe42ca948704593c847996d0ae8da71d15bb75b;hpb=f8575ea6c0982bba5ccf42771b2994d19500c0a3 diff --git a/src/sortaction.h b/src/sortaction.h index 66c337c..c56d0ee 100644 --- a/src/sortaction.h +++ b/src/sortaction.h @@ -24,6 +24,29 @@ #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. * @@ -31,44 +54,51 @@ 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 */ - virtual std::string toString() const{ + std::string toString() const{ return _action->toString(); } private: