Advertisement
P-Gaideec

Untitled

Mar 16th, 2019
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #ifndef INITIALIZATION_H
  2. #define INITIALIZATION_H
  3. #include "CommandInterface.h"
  4.  
  5.  
  6. //Cutting Class
  7.  
  8. class CutCOmmandInterface : public CommandInterface
  9. {
  10. public:
  11.     class CutInterface : public TextTransform
  12.     {
  13.     public:
  14.         std::string cuttedText;
  15.  
  16.         virtual void invokeOn(std::string& text, int startIndex, int endIndex) override {
  17.  
  18.             if (startIndex == endIndex)
  19.             {
  20.                 cuttedText.clear();
  21.             }
  22.             else
  23.             {
  24.                 cuttedText = text.substr(startIndex, endIndex);
  25.             }
  26.  
  27.             text.erase(startIndex, endIndex);
  28.         }
  29.     };
  30.  
  31.     virtual std::vector<Command> initCommands() override {
  32.         std::vector<Command> commands;
  33.  
  34.         commands.push_back(Command("cut", std::make_shared<CutInterface>()));
  35.  
  36.         return commands;
  37.     }
  38. };
  39.  
  40. //Pasting Class
  41.  
  42. class PasteCommandInterface : public CommandInterface
  43. {
  44. public:
  45.     class PasteInterface : public TextTransform
  46.     {
  47.     public:
  48.         virtual void invokeOn(std::string& text, int startIndex, int endIndex) override {
  49.             CutCOmmandInterface::CutInterface cut;
  50.             text.replace(startIndex, endIndex, cut.cuttedText);
  51.         }
  52.     };
  53.  
  54.     virtual std::vector<Command> initCommands() override {
  55.         std::vector<Command> commands;
  56.  
  57.         commands.push_back(Command("paste", std::make_shared<PasteInterface>()));
  58.  
  59.         return commands;
  60.     }
  61. };
  62.  
  63.  
  64.  
  65.  
  66. #endif // !INITIALIZATION_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement