blob: c1386f84fe2e19815db62da477de6c95038242c6 [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===-- 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 liblldb_CommandHistory_h_
10#define liblldb_CommandHistory_h_
11
12#include <mutex>
13#include <string>
14#include <vector>
15
16#include "lldb/Utility/Stream.h"
17#include "lldb/lldb-private.h"
18
19namespace lldb_private {
20
21class CommandHistory {
22public:
23 CommandHistory();
24
25 ~CommandHistory();
26
27 size_t GetSize() const;
28
29 bool IsEmpty() const;
30
31 llvm::Optional<llvm::StringRef> FindString(llvm::StringRef input_str) const;
32
33 llvm::StringRef GetStringAtIndex(size_t idx) const;
34
35 llvm::StringRef operator[](size_t idx) const;
36
37 llvm::StringRef GetRecentmostString() const;
38
39 void AppendString(llvm::StringRef str, bool reject_if_dupe = true);
40
41 void Clear();
42
43 void Dump(Stream &stream, size_t start_idx = 0,
44 size_t stop_idx = SIZE_MAX) const;
45
46 static const char g_repeat_char = '!';
47
48private:
49 DISALLOW_COPY_AND_ASSIGN(CommandHistory);
50
51 typedef std::vector<std::string> History;
52 mutable std::recursive_mutex m_mutex;
53 History m_history;
54};
55
56} // namespace lldb_private
57
58#endif // liblldb_CommandHistory_h_