History.h 578 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <AK/Vector.h>
  9. class History final {
  10. public:
  11. void push(StringView history_item);
  12. String current();
  13. void go_back();
  14. void go_forward();
  15. bool can_go_back() { return m_current_history_item > 0; }
  16. bool can_go_forward() { return m_current_history_item + 1 < static_cast<int>(m_items.size()); }
  17. void clear();
  18. private:
  19. Vector<String> m_items;
  20. int m_current_history_item { -1 };
  21. };