blob: fbb42247f11a01e22c415a52966aaacbcc29c2c0 [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
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02009#ifndef LLDB_INTERPRETER_COMMANDHISTORY_H
10#define LLDB_INTERPRETER_COMMANDHISTORY_H
Andrew Walbran3d2c1972020-04-07 12:24:26 +010011
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:
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020049 CommandHistory(const CommandHistory &) = delete;
50 const CommandHistory &operator=(const CommandHistory &) = delete;
Andrew Walbran3d2c1972020-04-07 12:24:26 +010051
52 typedef std::vector<std::string> History;
53 mutable std::recursive_mutex m_mutex;
54 History m_history;
55};
56
57} // namespace lldb_private
58
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020059#endif // LLDB_INTERPRETER_COMMANDHISTORY_H