Advertisement
Guest User

CommandInterfaceExtended

a guest
Aug 29th, 2021
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #pragma once
  2.  
  3. #ifndef COMMAND_INTERFACE_EXTENDED_H
  4. #define COMMAND_INTERFACE_EXTENDED_H
  5.  
  6. #include <string>
  7. #include <vector>
  8.  
  9. #include "TextTransform.h"
  10. #include "CommandInterface.h"
  11.  
  12. const size_t MAX_TEXT_SIZE = 30;
  13.  
  14. class CommandInterfaceExtended : public CommandInterface {
  15. public:
  16.  
  17.     class CutTransform : public TextTransform {
  18.     public:
  19.         void invokeOn(std::string& text, int startIndex, int endIndex) override {
  20.             char* lastCut;
  21.             text.copy(lastCut, startIndex, endIndex);
  22.             _lastCut = lastCut;
  23.             text.erase(text.begin() + startIndex, text.end() - endIndex);
  24.         }
  25.     };
  26.  
  27.     class PasteTransform : public TextTransform {
  28.     public:
  29.         void invokeOn(std::string& text, int startIndex, int endIndex) override {
  30.             text.replace(startIndex, endIndex, _lastCut);
  31.         }
  32.     };
  33.  
  34.     std::vector<Command> initCommands() override {
  35.         std::vector<Command> commands;
  36.  
  37.         commands.push_back(Command("cut", std::make_shared<CutTransform>()));
  38.  
  39.         return commands;
  40.     }
  41.  
  42.     std::vector<Command> initCommands() override {
  43.         std::vector<Command> commands;
  44.  
  45.         commands.push_back(Command("paste", std::make_shared<PasteTransform>()));
  46.  
  47.         return commands;
  48.     }
  49.  
  50. private:
  51.     static std::string _lastCut;
  52. };
  53.  
  54. #endif // COMMAND_INTERFACE_EXTENDED_H
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement