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 <string>
14 #include <vector>
15 
16 #include "lldb/Utility/Stream.h"
17 #include "lldb/lldb-private.h"
18 
19 namespace lldb_private {
20 
21 class CommandHistory {
22 public:
23   CommandHistory() = default;
24 
25   ~CommandHistory() = default;
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 
48 private:
49   CommandHistory(const CommandHistory &) = delete;
50   const CommandHistory &operator=(const CommandHistory &) = delete;
51 
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 
59 #endif // LLDB_INTERPRETER_COMMANDHISTORY_H
60