]> ruin.nu Git - germs.git/blobdiff - src/sortaction.h
Added more doxygen documentation
[germs.git] / src / sortaction.h
index a71a533cf70ec981f10d32527053e58cdf0a609b..ec9a023710961ee0978651fe46f1520d6d18039d 100644 (file)
 #ifndef __SORTACTION_H__
 #define __SORTACTION_H__
 
+#include <tr1/memory>
+#include <string>
 class GeneOrder;
+
+
 /**
- * Abstraction of a sort action
+ * Abstraction for a sort action implementation, this is the base that other
+ * actions inherits from.
+ */
+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 SortActionImpls has to be immutable.
  *
  * \author Michael Andreen
  */
 class SortAction{
        public:
+               typedef std::tr1::shared_ptr<SortActionImpl> ActionPointer;
+
+               /**
+                * 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){
+               }
 
-               virtual ~SortAction(){};
+               const SortAction& operator=(const SortAction& sa){
+                       if (this != &sa)
+                               _action = sa._action;
+                       return *this;
+               }
+               
+               ~SortAction(){};
 
                /**
                 * Applies the action on the GeneOrder and returning it.
                 */
-               virtual GeneOrder& operator()(GeneOrder& go) const{
-                       return go;
+               GeneOrder& operator()(GeneOrder& go) const{
+                       return (*_action)(go);
                }
 
                /**
                 * Compares sort actions.
                 */
-               virtual bool operator==(const SortAction& sa) const{
-                       return false;
+               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() const{
+                       return *_action;
+               }
+       private:
+               ActionPointer _action;
+
 };
 
 #endif