Commit 2d6ad569 authored by hjk's avatar hjk
Browse files

coreplugin: introduce an 'Id' class, intended as successor for generic QStrings

to identify actions etc.
parent 05b07bfe
......@@ -44,12 +44,12 @@ UniqueIDManager::~UniqueIDManager()
m_instance = 0;
}
bool UniqueIDManager::hasUniqueIdentifier(const QString &id) const
bool UniqueIDManager::hasUniqueIdentifier(const Id &id) const
{
return m_uniqueIdentifiers.contains(id);
}
int UniqueIDManager::uniqueIdentifier(const QString &id)
int UniqueIDManager::uniqueIdentifier(const Id &id)
{
if (hasUniqueIdentifier(id))
return m_uniqueIdentifiers.value(id);
......@@ -69,13 +69,13 @@ QString UniqueIDManager::stringForUniqueIdentifier(int uid)
static int toId(const char *id)
{
return UniqueIDManager::instance()->uniqueIdentifier(QLatin1String(id));
return UniqueIDManager::instance()->uniqueIdentifier(id);
}
Context::Context(const char *id, int offset)
{
d.append(UniqueIDManager::instance()
-> uniqueIdentifier(QString(id) + QString::number(offset)));
-> uniqueIdentifier(Id(QString(id) + QString::number(offset))));
}
void Context::add(const char *id)
......
......@@ -37,6 +37,36 @@
namespace Core {
// FIXME: The intention is to use this class instead of the
// generic QString to identify actions.
class CORE_EXPORT Id
{
public:
Id() {}
Id(const char *name) : m_name(QLatin1String(name)) {}
// FIXME: Replace with QByteArray
Id(const QString &name) : m_name(name) {}
// FIXME: Remove.
operator QString() const { return m_name; }
// FIXME: Replace with QByteArray
QString name() const { return m_name; }
bool isValid() const { return !m_name.isEmpty(); }
bool operator==(const Id &id) const { return m_name == id.m_name; }
bool operator!=(const Id &id) const { return m_name != id.m_name; }
private:
// Intentionally unimplemented
Id(const QLatin1String &);
// FIXME: Replace with QByteArray
QString m_name;
};
inline uint qHash(const Id &id)
{
return qHash(id.name());
}
class CORE_EXPORT UniqueIDManager
{
public:
......@@ -45,12 +75,12 @@ public:
static UniqueIDManager *instance() { return m_instance; }
bool hasUniqueIdentifier(const QString &id) const;
int uniqueIdentifier(const QString &id);
bool hasUniqueIdentifier(const Id &id) const;
int uniqueIdentifier(const Id &id);
QString stringForUniqueIdentifier(int uid);
private:
QHash<QString, int> m_uniqueIdentifiers;
QHash<Id, int> m_uniqueIdentifiers;
static UniqueIDManager *m_instance;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment