mirror-chatterino2/src/messages/MessageBuilder.hpp

40 lines
814 B
C++
Raw Normal View History

2017-06-06 21:18:05 +02:00
#pragma once
2017-04-12 17:46:44 +02:00
2017-06-11 09:31:45 +02:00
#include "messages/message.hpp"
2017-06-06 21:18:05 +02:00
2017-07-26 09:08:19 +02:00
#include <QRegularExpression>
2017-04-12 17:46:44 +02:00
2017-07-31 00:57:42 +02:00
#include <ctime>
2017-04-14 17:52:22 +02:00
namespace chatterino {
namespace messages {
2017-04-12 17:46:44 +02:00
2018-01-28 03:48:15 +01:00
struct MessageBuilder {
2017-04-12 17:46:44 +02:00
public:
MessageBuilder();
MessagePtr getMessage();
2017-04-12 17:46:44 +02:00
2017-09-24 18:43:24 +02:00
void setHighlight(bool value);
2018-01-28 03:48:15 +01:00
void append(MessageElement *element);
void appendTimestamp();
void appendTimestamp(const QTime &time);
QString matchLink(const QString &string);
2018-01-28 15:28:02 +01:00
template <typename T, typename... Args>
T *emplace(Args &&... args)
{
static_assert(std::is_base_of<MessageElement, T>::value, "T must extend MessageElement");
T *element = new T(std::forward<Args>(args)...);
2018-01-28 03:48:15 +01:00
this->append(element);
return element;
}
2017-12-17 17:48:46 +01:00
protected:
MessagePtr message;
2017-04-12 17:46:44 +02:00
};
2017-06-06 21:18:05 +02:00
} // namespace messages
} // namespace chatterino