Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #ifndef COMMAND_INTERFACE_EXTENDED_H
- #define COMMAND_INTERFACE_EXTENDED_H
- #include <string>
- #include <vector>
- #include "TextTransform.h"
- #include "CommandInterface.h"
- const size_t MAX_TEXT_SIZE = 30;
- class CommandInterfaceExtended : public CommandInterface {
- public:
- class CutTransform : public TextTransform {
- public:
- void invokeOn(std::string& text, int startIndex, int endIndex) override {
- char* lastCut;
- text.copy(lastCut, startIndex, endIndex);
- _lastCut = lastCut;
- text.erase(text.begin() + startIndex, text.end() - endIndex);
- }
- };
- class PasteTransform : public TextTransform {
- public:
- void invokeOn(std::string& text, int startIndex, int endIndex) override {
- text.replace(startIndex, endIndex, _lastCut);
- }
- };
- std::vector<Command> initCommands() override {
- std::vector<Command> commands;
- commands.push_back(Command("cut", std::make_shared<CutTransform>()));
- return commands;
- }
- std::vector<Command> initCommands() override {
- std::vector<Command> commands;
- commands.push_back(Command("paste", std::make_shared<PasteTransform>()));
- return commands;
- }
- private:
- static std::string _lastCut;
- };
- #endif // COMMAND_INTERFACE_EXTENDED_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement