put singletons into their namespace
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
namespace util {
|
||||
|
||||
template <typename TKey, typename TValue>
|
||||
class ConcurrentMap
|
||||
{
|
||||
public:
|
||||
ConcurrentMap()
|
||||
{
|
||||
}
|
||||
|
||||
bool tryGet(const TKey &name, TValue &value) const
|
||||
{
|
||||
QMutexLocker lock(&this->mutex);
|
||||
|
||||
auto a = this->data.find(name);
|
||||
if (a == this->data.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
value = a.value();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TValue getOrAdd(const TKey &name, std::function<TValue()> addLambda)
|
||||
{
|
||||
QMutexLocker lock(&this->mutex);
|
||||
|
||||
auto a = this->data.find(name);
|
||||
if (a == this->data.end()) {
|
||||
TValue value = addLambda();
|
||||
this->data.insert(name, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
return a.value();
|
||||
}
|
||||
|
||||
TValue &operator[](const TKey &name)
|
||||
{
|
||||
QMutexLocker lock(&this->mutex);
|
||||
|
||||
return this->data[name];
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
QMutexLocker lock(&this->mutex);
|
||||
|
||||
this->data.clear();
|
||||
}
|
||||
|
||||
void insert(const TKey &name, const TValue &value)
|
||||
{
|
||||
QMutexLocker lock(&this->mutex);
|
||||
|
||||
this->data.insert(name, value);
|
||||
}
|
||||
|
||||
void each(std::function<void(const TKey &name, const TValue &value)> func) const
|
||||
{
|
||||
QMutexLocker lock(&this->mutex);
|
||||
|
||||
QMapIterator<TKey, TValue> it(this->data);
|
||||
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
func(it.key(), it.value());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable QMutex mutex;
|
||||
QMap<TKey, TValue> data;
|
||||
};
|
||||
} // namespace chatterino
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "messages/lazyloadedimage.hpp"
|
||||
#include "util/concurrentmap.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace util {
|
||||
|
||||
struct EmoteData {
|
||||
EmoteData()
|
||||
{
|
||||
}
|
||||
|
||||
EmoteData(messages::LazyLoadedImage *_image)
|
||||
: image(_image)
|
||||
{
|
||||
}
|
||||
|
||||
messages::LazyLoadedImage *image = nullptr;
|
||||
};
|
||||
|
||||
typedef ConcurrentMap<QString, EmoteData> EmoteMap;
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ static void put(QUrl url, std::function<void(QJsonObject)> successCallback)
|
||||
{
|
||||
QNetworkRequest request(url);
|
||||
|
||||
auto &accountManager = AccountManager::getInstance();
|
||||
auto &accountManager = singletons::AccountManager::getInstance();
|
||||
auto currentTwitchUser = accountManager.Twitch.getCurrent();
|
||||
QByteArray oauthToken;
|
||||
if (currentTwitchUser) {
|
||||
|
||||
Reference in New Issue
Block a user