Skip to content

Commit 981e8f0

Browse files
committed
csgrep: use C++11 syntax to override virtual methods
PR: #51
1 parent 8befc10 commit 981e8f0

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/csgrep.cc

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@
3535
class StatWriter: public AbstractWriter {
3636
public:
3737
/// silently drop scan properties when printing stats only
38-
virtual void setScanProps(const TScanProps &) { }
38+
void setScanProps(const TScanProps &) override { }
3939
};
4040

4141
class FilePrinter: public StatWriter {
4242
private:
4343
std::string file_;
4444

4545
protected:
46-
virtual void notifyFile(const std::string &fileName) {
46+
void notifyFile(const std::string &fileName) override {
4747
file_ = fileName;
4848
}
4949

50-
virtual void handleDef(const Defect &) {
50+
void handleDef(const Defect &) override {
5151
if (file_.empty())
5252
return;
5353

@@ -61,11 +61,11 @@ class GroupPrinter: public StatWriter {
6161
std::string file_;
6262

6363
protected:
64-
virtual void notifyFile(const std::string &fileName) {
64+
void notifyFile(const std::string &fileName) override {
6565
file_ = fileName;
6666
}
6767

68-
virtual void handleDef(const Defect &def) {
68+
void handleDef(const Defect &def) override {
6969
if (!file_.empty()) {
7070
std::cout << "\n\n=== " << file_ << " ===\n";
7171
file_.clear();
@@ -78,7 +78,7 @@ class GroupPrinter: public StatWriter {
7878

7979
class KeyEventPrinter: public StatWriter {
8080
protected:
81-
virtual void handleDef(const Defect &def) {
81+
void handleDef(const Defect &def) override {
8282
const DefEvent &keyEvent = def.events[def.keyEventIdx];
8383
std::cout << def.checker << "\t" << keyEvent.event << "\n";
8484
}
@@ -90,11 +90,11 @@ class DefCounter: public StatWriter {
9090
TMap cnt_;
9191

9292
public:
93-
virtual void handleDef(const Defect &def) {
93+
void handleDef(const Defect &def) override {
9494
++cnt_[def.checker];
9595
}
9696

97-
virtual void flush() {
97+
void flush() override {
9898
for (TMap::const_reference item : cnt_) {
9999
using namespace std;
100100
const ios_base::fmtflags oldFlags = cout.flags();
@@ -114,13 +114,13 @@ class EvtCounter: public StatWriter {
114114
TMap cnt_;
115115

116116
public:
117-
virtual void handleDef(const Defect &def) {
117+
void handleDef(const Defect &def) override {
118118
const DefEvent &evt = def.events[def.keyEventIdx];
119119
const TKey key(def.checker, evt.event);
120120
++cnt_[key];
121121
}
122122

123-
virtual void flush() {
123+
void flush() override {
124124
for (TMap::const_reference item : cnt_) {
125125
using namespace std;
126126
const TKey &key = item.first;
@@ -147,12 +147,12 @@ class FileDefCounter: public StatWriter {
147147
TMap cntMap_;
148148

149149
public:
150-
virtual ~FileDefCounter() {
150+
~FileDefCounter() override {
151151
for (TMap::const_reference item : cntMap_)
152152
delete /* (DefCounter *) */ item.second;
153153
}
154154

155-
virtual void handleDef(const Defect &def) {
155+
void handleDef(const Defect &def) override {
156156
const std::string fName = def.events[def.keyEventIdx].fileName;
157157
TMap::const_iterator it = cntMap_.find(fName);
158158

@@ -163,7 +163,7 @@ class FileDefCounter: public StatWriter {
163163
defCnt->handleDef(def);
164164
}
165165

166-
virtual void flush() {
166+
void flush() override {
167167
for (TMap::const_reference item : cntMap_) {
168168
const std::string fName = item.first;
169169
std::cout << "\n\n--- " << fName << " ---\n";
@@ -184,7 +184,7 @@ class MsgPredicate: public IPredicate {
184184
{
185185
}
186186

187-
virtual bool matchDef(const Defect &def) const {
187+
bool matchDef(const Defect &def) const override {
188188
for (const DefEvent &evt : def.events) {
189189
if (boost::regex_search(evt.msg, re_))
190190
return true;
@@ -204,7 +204,7 @@ class KeyEventPredicate: public IPredicate {
204204
{
205205
}
206206

207-
virtual bool matchDef(const Defect &def) const {
207+
bool matchDef(const Defect &def) const override {
208208
const DefEvent &keyEvent = def.events[def.keyEventIdx];
209209
return boost::regex_search(keyEvent.event, re_);
210210
}
@@ -220,7 +220,7 @@ class ErrorPredicate: public IPredicate {
220220
{
221221
}
222222

223-
virtual bool matchDef(const Defect &def) const {
223+
bool matchDef(const Defect &def) const override {
224224
const DefEvent &evt = def.events[def.keyEventIdx];
225225
return boost::regex_search(evt.msg, re_);
226226
}
@@ -236,7 +236,7 @@ class PathPredicate: public IPredicate {
236236
{
237237
}
238238

239-
virtual bool matchDef(const Defect &def) const {
239+
bool matchDef(const Defect &def) const override {
240240
const DefEvent &evt = def.events[def.keyEventIdx];
241241
return boost::regex_search(evt.fileName, re_);
242242
}
@@ -252,7 +252,7 @@ class CheckerPredicate: public IPredicate {
252252
{
253253
}
254254

255-
virtual bool matchDef(const Defect &def) const {
255+
bool matchDef(const Defect &def) const override {
256256
return boost::regex_search(def.checker, re_);
257257
}
258258
};
@@ -267,7 +267,7 @@ class AnnotPredicate: public IPredicate {
267267
{
268268
}
269269

270-
virtual bool matchDef(const Defect &def) const {
270+
bool matchDef(const Defect &def) const override {
271271
return boost::regex_search(def.annotation, re_);
272272
}
273273
};
@@ -283,7 +283,7 @@ class SrcAnnotPredicate: public IPredicate {
283283
}
284284

285285
// FIXME: this implementation is desperately inefficient
286-
virtual bool matchDef(const Defect &def) const {
286+
bool matchDef(const Defect &def) const override {
287287
const DefEvent &evt = def.events[def.keyEventIdx];
288288
const std::string &fname = evt.fileName;
289289
std::fstream fstr(fname.c_str(), std::ios::in);
@@ -323,7 +323,7 @@ class PathStripper: public GenericAbstractFilter {
323323
{
324324
}
325325

326-
virtual void handleDef(const Defect &defOrig) {
326+
void handleDef(const Defect &defOrig) override {
327327
Defect def(defOrig);
328328

329329
// iterate through all events
@@ -356,17 +356,16 @@ class DropScanProps: public GenericAbstractFilter {
356356
}
357357

358358
/// ignore any given scan properties
359-
virtual void setScanProps(const TScanProps &) {
360-
}
359+
void setScanProps(const TScanProps &) override { }
361360

362361
/// always return empty scan properties
363-
virtual const TScanProps& getScanProps() const {
362+
const TScanProps& getScanProps() const override {
364363
return emp_;
365364
}
366365

367366
protected:
368367
/// trivial pass-through
369-
virtual void handleDef(const Defect &def) {
368+
void handleDef(const Defect &def) override {
370369
agent_->handleDef(def);
371370
}
372371

@@ -382,7 +381,7 @@ class DuplicateFilter: public AbstractFilter {
382381
}
383382

384383
protected:
385-
virtual bool matchDef(const Defect &def) {
384+
bool matchDef(const Defect &def) override {
386385
DefEvent evt = def.events[def.keyEventIdx];
387386

388387
// abstract out differences we do not deem important

0 commit comments

Comments
 (0)