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 <cstring>
- #include <vector>
- #include "TextTransform.h"
- #include "CommandInterface.h"
- const size_t MAX_TEXT_SIZE = 30;
- class CommandInterfaceExtended : public CommandInterface {
- public:
- CommandInterfaceExtended(std::string& text) : CommandInterface(text) {}
- // CUT TRANSFORM
- class CutTransform : public TextTransform {
- void invokeOn(std::string& text, int startIndex, int endIndex) override {
- for (int i = startIndex; i < endIndex; ++i) {
- CommandInterfaceExtended::_lastCut += text[i];
- }
- text.erase(text.begin() + startIndex, text.begin() + endIndex);
- }
- };
- // PASTE TRANSFORM
- class PasteTransform : public CutTransform {
- void invokeOn(std::string& text, int startIndex, int endIndex) override {
- text.replace(text.begin() + startIndex, text.begin() + endIndex, CommandInterfaceExtended::_lastCut);
- }
- };
- // INIT COMMANDS FUNCTION
- std::vector<Command> initCommands() override {
- std::vector<Command> commands;
- commands.push_back(Command("cut", std::make_shared<CutTransform>()));
- commands.push_back(Command("paste", std::make_shared<PasteTransform>()));
- //addig uppercase case, works as paste :?
- //commands.push_back(Command("uppercase", std::make_shared<PasteTransform>()));
- return commands;
- }
- protected:
- static std::string _lastCut;
- };
- #endif // COMMAND_INTERFACE_EXTENDED_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement