Debian Codegraph @

DebugAdapterClient/SessionBreakpoints.cpp

raw
1 #include "SessionBreakpoints.hpp"
2
3 #include <algorithm>
4
5 SessionBreakpoints::SessionBreakpoints() {}
6
7 SessionBreakpoints::~SessionBreakpoints() {}
8
9 void SessionBreakpoints::clear() { m_breakpoints.clear(); }
10
11 int SessionBreakpoints::find_by_id_internal(int id)
12 {
13 for(size_t i = 0; i < m_breakpoints.size(); ++i) {
14 if(m_breakpoints[i].id == id) {
15 return i;
16 }
17 }
18 return wxNOT_FOUND;
19 }
20
21 bool SessionBreakpoints::find_by_id(int id, dap::Breakpoint* bp)
22 {
23 if(!bp) {
24 return false;
25 }
26
27 int index = find_by_id_internal(id);
28 if(index == wxNOT_FOUND)
29 return false;
30 *bp = m_breakpoints[index];
31 return true;
32 }
33
34 size_t SessionBreakpoints::find_by_path(const wxString& path, std::vector<dap::Breakpoint>* bps)
35 {
36 if(!bps) {
37 return 0;
38 }
39
40 for(const auto& bp : m_breakpoints) {
41 if(bp.source.path == path) {
42 bps->push_back(bp);
43 }
44 }
45 return bps->size();
46 }
47
48 bool SessionBreakpoints::update_or_insert(const dap::Breakpoint& bp)
49 {
50 if(bp.id <= 0) {
51 return false;
52 }
53
54 int where = find_by_id_internal(bp.id);
55 if(where == wxNOT_FOUND) {
56 m_breakpoints.push_back(bp);
57 } else {
58 // only update when the bp is changing from not-verified -> verified
59 if(bp.verified) {
60 m_breakpoints[where] = bp;
61 }
62 }
63 return true;
64 }
65
66 void SessionBreakpoints::bulk_update(const std::vector<dap::Breakpoint>& list)
67 {
68 for(const auto& bp : list) {
69 update_or_insert(bp);
70 }
71 }
72
73 size_t SessionBreakpoints::find_by_path_internal(const wxString& path, std::vector<dap::Breakpoint>* bps)
74 {
75 if(path.empty() || !bps) {
76 return 0;
77 }
78
79 bps->reserve(m_breakpoints.size());
80 for(size_t i = 0; i < m_breakpoints.size(); ++i) {
81 if(m_breakpoints[i].source.path == path) {
82 bps->push_back(m_breakpoints[i]);
83 }
84 }
85 return bps->size();
86 }
87
88 void SessionBreakpoints::delete_by_id(int id)
89 {
90 int index = find_by_id_internal(id);
91 if(index == wxNOT_FOUND) {
92 return;
93 }
94 m_breakpoints.erase(m_breakpoints.begin() + index);
95 }
96
97 void SessionBreakpoints::delete_by_path(const wxString& path)
98 {
99 std::vector<dap::Breakpoint> bps;
100 find_by_path_internal(path, &bps);
101
102 for(const auto& bp : bps) {
103 delete_by_id(bp.id);
104 }
105 }
106
107 void SessionBreakpoints::delete_by_paths(const std::vector<dap::Breakpoint>& bps)
108 {
109 std::unordered_set<wxString> files;
110 for(const auto& bp : bps) {
111 if(!bp.source.path.empty()) {
112 files.insert(bp.source.path);
113 }
114 }
115
116 for(const auto& path : files) {
117 delete_by_path(path);
118 }
119 }