use instances of less<Check *> to compare pointers for list::sort()

This commit is contained in:
Greg Hewgill 2011-02-02 22:56:14 +13:00
parent be195a72c9
commit bea36d1f83
1 changed files with 18 additions and 12 deletions

View File

@ -39,12 +39,7 @@ class Check
{ {
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
Check(const std::string &aname) Check(const std::string &aname);
: _name(aname), _tokenizer(0), _settings(0), _errorLogger(0)
{
instances().push_back(this);
instances().sort();
}
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
@ -159,17 +154,28 @@ protected:
private: private:
/** compare the names of Check classes, used when sorting the Check descendants */
bool operator<(const Check *other) const
{
return (name() < other->name());
}
/** disabled assignment operator */ /** disabled assignment operator */
void operator=(const Check &); void operator=(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)
: _name(aname), _tokenizer(0), _settings(0), _errorLogger(0)
{
instances().push_back(this);
instances().sort(std::less<Check *>());
}
/// @} /// @}
#endif #endif