Skip to content
Snippets Groups Projects
Action.hpp 1.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • #ifndef ACTION__H
    #define ACTION__H
    
    #include <functional>
    #include <string>
    #include <vector>
    #include "Config.hpp"
    
    class Action
    {
      public :
    
      enum Type
      {
        Push,
        Pop,
        Write,
        MoveWord,
        MoveChar,
        AddLines,
        Check
      };
    
    
      enum Object
      {
        Buffer,
        Stack
      };
    
    
      private :
    
      Type type;
      std::vector<std::string> data;
    
      public :
    
    
      std::function<void(Config & config, Action & action)> apply;
      std::function<void(Config & config, Action & action)> undo;
      std::function<bool(const Config & config, const Action & action)> appliable;
    
      private :
    
      Action(Type type, std::function<void(Config & config, Action & action)> apply, std::function<void(Config & config, Action & action)> undo, std::function<bool(const Config & config, const Action & action)> appliable);
    
      static Object str2object(const std::string & s);
    
      static Action addLinesIfNeeded(int nbLines);
      static Action moveWordIndex(int movement);
      static Action moveCharacterIndex(int movement);
    
      static Action addHypothesis(const std::string & colName, std::size_t lineIndex, const std::string & hypothesis);
      static Action addHypothesisRelative(const std::string & colName, Object object, int relativeIndex, const std::string & hypothesis);
    
      static Action pushWordIndexOnStack();
      static Action popStack();
    
    Franck Dary's avatar
    Franck Dary committed
      static Action emptyStack();
      static Action setRoot();
    
      static Action updateIds();
    
      static Action attach(Object governorObject, int governorIndex, Object dependentObject, int dependentIndex);