TT Client Library 1.0.0
C++ library for Tandem Tales clients.
Loading...
Searching...
No Matches
Message.h
1#pragma once
2
3#include <nlohmann/json.hpp>
4
5#ifndef MESSAGE_H
6#define MESSAGE_H
7
8namespace tt {
9
10 // forward declaration
11 class Client;
12
14 using json = nlohmann::json;
15
23 class Message {
24 public:
25 // virtual function necessary for JSON serialization
26 // Message must be polymorphic
27 virtual ~Message() = default;
28
32 Message(): client(nullptr) {};
33
40 const Client* getClient() const;
41
49 void setClient(const Client* client);
50
54 virtual std::string type() const = 0;
55
61 virtual std::string toString() const;
62
63 friend std::ostream& operator<<(std::ostream& os, const Message& a);
64
65 private:
70 const Client* client;
71 };
72
79 std::ostream& operator<<(std::ostream& os, const Message& a);
80}
81
82#endif
A client connects to a server to find a partner and play a role in a storytelling session.
Definition Client.h:51
A message is information sent to or from a server in JSON format.
Definition Message.h:23
friend std::ostream & operator<<(std::ostream &os, const Message &a)
Override stream insertion operator to allow printing the Message class.
virtual std::string toString() const
Returns a string representation of this object.
Definition Message.cpp:14
void setClient(const Client *client)
Sets the tt::Client who sent this message.
Definition Message.cpp:9
virtual std::string type() const =0
Type used for JSON deserialization.
Message()
Constructs a message.
Definition Message.h:32
const Client * getClient() const
Returns the tt::Client who sent this message, or null if this message was sent by the server.
Definition Message.cpp:5
Tandem Tales is a platform that enables short, paired storytelling exercises between two agents over ...
Definition Client.h:22
std::ostream & operator<<(std::ostream &os, const Client &a)
Override stream insertion operator to allow printing the Client class.
Definition Client.cpp:556
nlohmann::json json
Alias for nlohmann's json.
Definition Message.h:14