1//===-- CommandHistory.h ----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_INTERPRETER_COMMANDHISTORY_H
10#define LLDB_INTERPRETER_COMMANDHISTORY_H
11
12#include <mutex>
13#include <optional>
14#include <string>
15#include <vector>
16
17#include "lldb/Utility/Stream.h"
18#include "lldb/lldb-private.h"
19
20namespace lldb_private {
21
22class CommandHistory {
23public:
24  CommandHistory() = default;
25
26  ~CommandHistory() = default;
27
28  size_t GetSize() const;
29
30  bool IsEmpty() const;
31
32  std::optional<llvm::StringRef> FindString(llvm::StringRef input_str) const;
33
34  llvm::StringRef GetStringAtIndex(size_t idx) const;
35
36  llvm::StringRef operator[](size_t idx) const;
37
38  llvm::StringRef GetRecentmostString() const;
39
40  void AppendString(llvm::StringRef str, bool reject_if_dupe = true);
41
42  void Clear();
43
44  void Dump(Stream &stream, size_t start_idx = 0,
45            size_t stop_idx = SIZE_MAX) const;
46
47  static const char g_repeat_char = '!';
48
49private:
50  CommandHistory(const CommandHistory &) = delete;
51  const CommandHistory &operator=(const CommandHistory &) = delete;
52
53  typedef std::vector<std::string> History;
54  mutable std::recursive_mutex m_mutex;
55  History m_history;
56};
57
58} // namespace lldb_private
59
60#endif // LLDB_INTERPRETER_COMMANDHISTORY_H
61