xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Breakpoint/StopCondition.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===----------------------------------------------------------------------===//
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_BREAKPOINT_STOPCONDITION_H
10 #define LLDB_BREAKPOINT_STOPCONDITION_H
11 
12 #include "lldb/lldb-private.h"
13 #include "llvm/ADT/StringRef.h"
14 
15 namespace lldb_private {
16 
17 class StopCondition {
18 public:
19   StopCondition() = default;
20   StopCondition(std::string text,
21                 lldb::LanguageType language = lldb::eLanguageTypeUnknown)
m_language(language)22       : m_language(language) {
23     SetText(std::move(text));
24   }
25 
26   explicit operator bool() const { return !m_text.empty(); }
27 
GetText()28   llvm::StringRef GetText() const { return m_text; }
29 
SetText(std::string text)30   void SetText(std::string text) {
31     static std::hash<std::string> hasher;
32     m_text = std::move(text);
33     m_hash = hasher(text);
34   }
35 
GetHash()36   size_t GetHash() const { return m_hash; }
37 
GetLanguage()38   lldb::LanguageType GetLanguage() const { return m_language; }
39 
SetLanguage(lldb::LanguageType language)40   void SetLanguage(lldb::LanguageType language) { m_language = language; }
41 
42 private:
43   /// The condition to test.
44   std::string m_text;
45 
46   /// Its hash, so that locations know when the condition is updated.
47   size_t m_hash = 0;
48 
49   /// The language for this condition.
50   lldb::LanguageType m_language = lldb::eLanguageTypeUnknown;
51 };
52 
53 } // namespace lldb_private
54 
55 #endif // LLDB_BREAKPOINT_STOPCONDITION_H
56