tape.h 840 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // tape.hpp
  3. // cli
  4. //
  5. // Created by Sam Jaffe on 7/23/24.
  6. // Copyright © 2024 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <cstdint>
  10. #include <string>
  11. #include <vector>
  12. namespace cli {
  13. struct Tape {
  14. public:
  15. using callback_type = std::function<void(std::string)>;
  16. using value_type = std::string;
  17. using char_type = char;
  18. private:
  19. size_t negative_offset_{0};
  20. size_t cursor_offset_{0};
  21. std::vector<value_type> elements_{""};
  22. callback_type callback_;
  23. public:
  24. explicit Tape(callback_type const &callback) : Tape(1, callback) {}
  25. Tape(size_t n, callback_type const &callback);
  26. value_type const &get() const;
  27. void readch();
  28. private:
  29. value_type &get();
  30. void down();
  31. void up();
  32. void left();
  33. void right();
  34. void insert(char_type value);
  35. void erase();
  36. void clear();
  37. };
  38. }