Simplified check registration:

- Use sorted insert instead of calling std::list<Check*>::sort() on each insertion
- Removed DJGPP/__sun hack in check.h (should be obsolete by our compiler requirements for C++11
This commit is contained in:
PKEuS 2014-04-02 19:01:37 +02:00
parent 40be775efa
commit dbf2c44a81
1 changed files with 12 additions and 20 deletions

View File

@ -41,7 +41,16 @@
class CPPCHECKLIB Check {
public:
/** This constructor is used when registering the CheckClass */
explicit Check(const std::string &aname);
explicit Check(const std::string &aname)
: _tokenizer(0), _settings(0), _errorLogger(0), _name(aname) {
for (std::list<Check*>::iterator i = instances().begin(); i != instances(). end(); ++i) {
if ((*i)->name() > aname) {
instances().insert(i, this);
return;
}
}
instances().push_back(this);
}
/** This constructor is used when running checks. */
Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
@ -49,9 +58,8 @@ public:
}
virtual ~Check() {
#if !defined(DJGPP) && !defined(__sun)
instances().remove(this);
#endif
if (!_tokenizer)
instances().remove(this);
}
/** List of registered check classes. This is used by Cppcheck to run checks and generate documentation */
@ -141,22 +149,6 @@ private:
Check(const Check &);
};
namespace std {
/** compare the names of Check classes, used when sorting the Check descendants */
template <> struct less<Check *> {
bool operator()(const Check *p1, const Check *p2) const {
return (p1->name() < p2->name());
}
};
}
inline Check::Check(const std::string &aname)
: _tokenizer(0), _settings(0), _errorLogger(0), _name(aname)
{
instances().push_back(this);
instances().sort(std::less<Check *>());
}
/// @}
//---------------------------------------------------------------------------
#endif // checkH