NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
breakpointmanager.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2017 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18#include "breakpointmanager.hpp"
19#include "../utils/tools.hpp"
20
21// Constructor
23{
24 mBreakpoints.clear();
25}
26
27// Copy constructor
29{
30 passBreakpoints(_messenger.mBreakpoints);
31}
32
33// This member function adds a breakpoint to the passed
34// file at the indicated line number
35void BreakpointManager::addBreakpoint(const std::string& _sFilename, size_t nLine)
36{
37 // Try to find the current file in the map
38 if (mBreakpoints.find(replacePathSeparator(_sFilename)) != mBreakpoints.end())
39 {
40 // Get the current breakpoint set of this file
41 std::vector<size_t> vLine = mBreakpoints[replacePathSeparator(_sFilename)];
42
43 // Try to find the current line
44 for (size_t i = 0; i < vLine.size(); i++)
45 {
46 if (vLine[i] == nLine)
47 return;
48 }
49
50 // If the line was not part of the breakpoint set
51 // add it to this set and store it in the map
52 vLine.push_back(nLine);
53 mBreakpoints[replacePathSeparator(_sFilename)] = vLine;
54 }
55 else
56 {
57 // This file does not yet exist. Create it and
58 // store the passed breakpoint
59 std::vector<size_t> vLine;
60 vLine.push_back(nLine);
61 mBreakpoints[replacePathSeparator(_sFilename)] = vLine;
62 }
63}
64
65// This member function removes a breakpoint from the
66// passed file at the indicated line number
67void BreakpointManager::removeBreakpoint(const std::string& _sFilename, size_t nLine)
68{
69 // Try to find the current file in the map
70 if (mBreakpoints.find(replacePathSeparator(_sFilename)) == mBreakpoints.end())
71 {
72 // If it does not exist, do nothing
73 return;
74 }
75 else
76 {
77 // Get the current breakpoint set of this file
78 std::vector<size_t> vLine = mBreakpoints[replacePathSeparator(_sFilename)];
79
80 // Try to find the current line
81 for (size_t i = 0; i < vLine.size(); i++)
82 {
83 if (vLine[i] == nLine)
84 {
85 // Erase the breakpoint from the set
86 vLine.erase(vLine.begin()+i);
87 }
88 }
89
90 // If this was the last breakpoint, erase the whole
91 // file from the map. Otherwise store the new breakpoint
92 // set in the map
93 if (!vLine.size())
94 mBreakpoints.erase(replacePathSeparator(_sFilename));
95 else
96 mBreakpoints[replacePathSeparator(_sFilename)] = vLine;
97 }
98}
99
100// This member function removes all breakpoints from
101// the passed file
102void BreakpointManager::clearBreakpoints(const std::string& _sFilename)
103{
104 if (mBreakpoints.find(replacePathSeparator(_sFilename)) != mBreakpoints.end())
105 mBreakpoints.erase(replacePathSeparator(_sFilename));
106}
107
108// This member function accepts the breakpoints passed
109// by a map of the corresponding type
110void BreakpointManager::passBreakpoints(const std::map<std::string,std::vector<size_t> >& _mBreakpoints)
111{
112 mBreakpoints.clear();
113 mBreakpoints = _mBreakpoints;
114}
115
116// This member function returns true, if the user has set
117// a breakpoint in the passed file at the passed line number
118bool BreakpointManager::isBreakpoint(const std::string& _sFilename, size_t nLine)
119{
120 // Try to find the current file in the map
121 if (mBreakpoints.find(replacePathSeparator(_sFilename)) == mBreakpoints.end())
122 {
123 // If it does not exist, return false
124 return false;
125 }
126 else
127 {
128 // Get the current breakpoint set of this file
129 std::vector<size_t> vLine = mBreakpoints[replacePathSeparator(_sFilename)];
130
131 // Try to find the current line
132 for (size_t i = 0; i < vLine.size(); i++)
133 {
134 if (vLine[i] == nLine)
135 {
136 return true;
137 }
138 }
139 }
140
141 // Nothing found
142 return false;
143}
144
std::map< std::string, std::vector< size_t > > mBreakpoints
void addBreakpoint(const std::string &_sFilename, size_t nLine)
bool isBreakpoint(const std::string &_sFilename, size_t nLine)
void removeBreakpoint(const std::string &_sFilename, size_t nLine)
void clearBreakpoints(const std::string &_sFilename)
void passBreakpoints(const std::map< std::string, std::vector< size_t > > &_mBreakpoints)
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.