Chatterino
Emote.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "common/Atomic.hpp"
4 #include "messages/Image.hpp"
5 #include "messages/ImageSet.hpp"
6 
7 #include <boost/optional.hpp>
8 #include <functional>
9 #include <memory>
10 #include <unordered_map>
11 
12 namespace chatterino {
13 
14 struct Emote {
15  EmoteName name;
17  Tooltip tooltip;
18  Url homePage;
19  bool zeroWidth;
20  EmoteId id;
21  EmoteAuthor author;
26  boost::optional<EmoteName> baseName;
27 
28  // FOURTF: no solution yet, to be refactored later
29  const QString &getCopyString() const
30  {
31  return name.string;
32  }
33 };
34 
35 bool operator==(const Emote &a, const Emote &b);
36 bool operator!=(const Emote &a, const Emote &b);
37 
38 using EmotePtr = std::shared_ptr<const Emote>;
39 
40 class EmoteMap : public std::unordered_map<EmoteName, EmotePtr>
41 {
42 public:
54  EmoteMap::const_iterator findEmote(const QString &emoteNameHint,
55  const QString &emoteID) const;
56 };
57 using EmoteIdMap = std::unordered_map<EmoteId, EmotePtr>;
58 using WeakEmoteMap = std::unordered_map<EmoteName, std::weak_ptr<const Emote>>;
59 using WeakEmoteIdMap = std::unordered_map<EmoteId, std::weak_ptr<const Emote>>;
60 
61 static const std::shared_ptr<const EmoteMap> EMPTY_EMOTE_MAP = std::make_shared<
62  const EmoteMap>(); // NOLINT(cert-err58-cpp) -- assume this doesn't throw an exception
63 
66  Emote &&emote,
67  std::unordered_map<EmoteId, std::weak_ptr<const Emote>> &cache,
68  std::mutex &mutex, const EmoteId &id);
69 
70 } // namespace chatterino
EmotePtr emote
Definition: InputCompletionPopup.cpp:20
Tooltip tooltip
Definition: Emote.hpp:17
Definition: Emote.hpp:14
ImageSet images
Definition: Emote.hpp:16
const QString & getCopyString() const
Definition: Emote.hpp:29
Definition: Application.cpp:48
Url homePage
Definition: Emote.hpp:18
Definition: ImageSet.hpp:7
std::shared_ptr< const Emote > EmotePtr
Definition: Emote.hpp:38
Definition: Emote.hpp:40
boost::optional< EmoteName > baseName
Definition: Emote.hpp:26
EmoteAuthor author
Definition: Emote.hpp:21
EmoteName name
Definition: Emote.hpp:15
std::unordered_map< EmoteId, EmotePtr > EmoteIdMap
Definition: Emote.hpp:57
std::unordered_map< EmoteId, std::weak_ptr< const Emote > > WeakEmoteIdMap
Definition: Emote.hpp:59
bool operator==(const Emote &a, const Emote &b)
Definition: Emote.cpp:7
bool zeroWidth
Definition: Emote.hpp:19
EmotePtr cachedOrMakeEmotePtr(Emote &&emote, const EmoteMap &cache)
Definition: Emote.cpp:18
std::unordered_map< EmoteName, std::weak_ptr< const Emote > > WeakEmoteMap
Definition: Emote.hpp:58
EmoteId id
Definition: Emote.hpp:20
bool operator!=(const Emote &a, const Emote &b)
Definition: Emote.cpp:13
Definition: lrucache.hpp:16