From cb343652934540050a4da3f9a8446463db37b98b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 24 May 2014 14:07:19 +0300 Subject: Add macro for quick rules definiton. --- src/Makefile.am | 4 ++-- src/lintmanager.cpp | 14 ++++++++++++-- src/lintmanager.h | 2 ++ src/rulebase.cpp | 5 +++++ src/rulebase.h | 2 ++ src/rules/dump.cpp | 16 ++++++---------- src/rules/dump.h | 38 -------------------------------------- src/template.hpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 72 insertions(+), 52 deletions(-) delete mode 100644 src/rules/dump.h create mode 100644 src/template.hpp (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 4367755..b90361d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,8 +13,8 @@ mplint_SOURCES = \ main.cpp \ rulebase.cpp \ rulebase.h \ - rules/dump.cpp \ - rules/dump.h + template.hpp \ + rules/dump.cpp # set the include path found by configure AM_CPPFLAGS = $(all_includes) diff --git a/src/lintmanager.cpp b/src/lintmanager.cpp index 69cd21c..01c28e8 100644 --- a/src/lintmanager.cpp +++ b/src/lintmanager.cpp @@ -22,8 +22,6 @@ #include "rulebase.h" -#include "rules/dump.h" - #include #include #include @@ -48,6 +46,18 @@ void LintManager::addRule(RuleBase *const rule) mRules.push_back(rule); } +void LintManager::deleteRule(RuleBase *const rule) +{ + FOR_EACH (std::vector::iterator, it, mRules) + { + if (*it == rule) + { + mRules.erase(it); + return; + } + } +} + void LintManager::enumFiles(std::string path) { path += "/"; diff --git a/src/lintmanager.h b/src/lintmanager.h index 4fe6902..b504482 100644 --- a/src/lintmanager.h +++ b/src/lintmanager.h @@ -37,6 +37,8 @@ class LintManager final void addRule(RuleBase *const rule); + void deleteRule(RuleBase *const rule); + protected: void enumFiles(std::string path); diff --git a/src/rulebase.cpp b/src/rulebase.cpp index 7a53c9b..c5a795d 100644 --- a/src/rulebase.cpp +++ b/src/rulebase.cpp @@ -45,3 +45,8 @@ void RuleBase::addMask(const std::string &mask) { mFileMasks.insert(mask); } + +void RuleBase::deleteSelf() +{ + lint.deleteRule(this); +} diff --git a/src/rulebase.h b/src/rulebase.h index 7d8b0b0..a92516b 100644 --- a/src/rulebase.h +++ b/src/rulebase.h @@ -59,6 +59,8 @@ class RuleBase void addMask(const std::string &mask); + void deleteSelf(); + std::set mFileMasks; std::string file; diff --git a/src/rules/dump.cpp b/src/rules/dump.cpp index 3140e6a..87c1aff 100644 --- a/src/rules/dump.cpp +++ b/src/rules/dump.cpp @@ -18,27 +18,23 @@ * along with this program. If not, see . */ -#include "rules/dump.h" +#include "template.hpp" -#include "localconsts.h" +registerRule(dump) -namespace -{ - Dump instance; -} - -Dump::Dump() +constructRule(dump) { addMask("(.+)[.]cpp"); addMask("(.+)[.]h"); + deleteSelf(); } -void Dump::init() +initRule(dump) { printRaw("Checking file: " + file); } -void Dump::parseLine(const std::string &data) +parseLineRule(dump) { print(data); } diff --git a/src/rules/dump.h b/src/rules/dump.h deleted file mode 100644 index 6a91ef9..0000000 --- a/src/rules/dump.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef RULES_DUMP_H -#define RULES_DUMP_H - -#include "rulebase.h" - -#include "localconsts.h" - -class Dump : public RuleBase -{ - public: - Dump(); - - void init(); - - void parseLine(const std::string &data); -}; - -#endif // RULES_DUMP_H diff --git a/src/template.hpp b/src/template.hpp new file mode 100644 index 0000000..3aa0003 --- /dev/null +++ b/src/template.hpp @@ -0,0 +1,43 @@ +/* + * The ManaPlus Client + * Copyright (C) 2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "rulebase.h" + +#include "localconsts.h" + +#define registerRule(name) \ +class name : public RuleBase \ +{ \ + public: \ + name(); \ +\ + void init(); \ +\ + void parseLine(const std::string &data); \ +}; \ +\ +namespace \ +{ \ + name instance; \ +} \ + +#define constructRule(name) name::name() +#define initRule(name) void name::init() +#define parseLineRule(name) void name::parseLine(const std::string &data) -- cgit v1.2.3-70-g09d2