forked from qt-creator/qt-creator
Refactoring LookupContext.h
Extracting class AlreadyConsideredClassContainer to separate file Change-Id: If3bb89df5ce0bae87723ad4ecab7118337df0655 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
eb39b57e24
commit
70e3356a02
45
src/libs/cplusplus/AlreadyConsideredClassContainer.h
Normal file
45
src/libs/cplusplus/AlreadyConsideredClassContainer.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef CPLUSPLUS_ALREADYCONSIDEREDCLASSCONTAINER_H
|
||||
#define CPLUSPLUS_ALREADYCONSIDEREDCLASSCONTAINER_H
|
||||
|
||||
#include <QSet>
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
template<typename T>
|
||||
class AlreadyConsideredClassContainer
|
||||
{
|
||||
public:
|
||||
AlreadyConsideredClassContainer() : _class(0) {}
|
||||
void insert(const T *item)
|
||||
{
|
||||
if (_container.isEmpty())
|
||||
_class = item;
|
||||
_container.insert(item);
|
||||
}
|
||||
bool contains(const T *item)
|
||||
{
|
||||
if (_container.contains(item))
|
||||
return true;
|
||||
|
||||
foreach (const T *existingItem, _container) {
|
||||
if (existingItem->isEqualTo(item))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void clear(const T *item)
|
||||
{
|
||||
if (_class != item || _container.size() == 1)
|
||||
_container.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
QSet<const T *> _container;
|
||||
const T * _class;
|
||||
};
|
||||
|
||||
} // namespace CPlusPlus
|
||||
|
||||
#endif // CPLUSPLUS_ALREADYCONSIDEREDCLASSCONTAINER_H
|
||||
Reference in New Issue
Block a user