Brunot
Loading...
Searching...
No Matches
Message.h
Go to the documentation of this file.
1// File: Message.h
2// Description: The base class of all messages. All derived messages should hold information, this class exists
3// so we can polymorphically pass around messages
4// Author(s): Ori Balashov (ori.balashov@digipen.edu)
5// 2025 / 10 / 24
6// (C) Digipen 2025
7// ____ __ __ __
8// /\__ _\/\ \ /\ \/\ \
9// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
10// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
11// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
12// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
13// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
14#pragma once
15#include <memory>
16#include "System/json.h"
18
19namespace sys
20{
21class Json;
22}
23
24using Stream = sys::Json;
25
26
27#define MSG_CLONE(MessageClass) auto clone() const -> std::unique_ptr<Message> override \
28{ \
29 return std::make_unique<MessageClass>(*this); \
30}
31
32// Note: This implementation is inspired by Ravi Richards' (Man O' Ware) Message class, although no code has been copied
33
34struct Message
35{
36
37 Message() = default;
38 Message(const Message& other) = default;
39 Message(Message&& other) noexcept = default;
40 auto operator=(const Message& other) -> Message& = default;
41 auto operator=(Message&& other) noexcept -> Message& = default;
42 virtual ~Message() = default;
43
44 auto virtual clone() const -> std::unique_ptr<Message>
45 {
46 return std::make_unique<Message>(*this);
47 }
48
49 static auto bindLuaTypes(sol::state& lua) -> void;
50
51 virtual auto load(const Stream& stream) -> void;
52 virtual auto save(Stream& stream) const -> void;
53
54
62 template <typename T>
63 auto convertTo() const -> const T*
64 {
65 return dynamic_cast<const T*>(this);
66 }
67
68 // Holds no data
69};
sys::Json Stream
Definition AudioObject.h:20
system for managing lua, and how the lua state interacts with scripts
Definition Json.h:32
the type of elements in a basic_json container
Definition GameObject.h:37
auto convertTo() const -> const T *
A function that converts messages to the specific type so you don't need to call static_cast yourself...
Definition Message.h:63
virtual auto save(Stream &stream) const -> void
Definition Message.cpp:28
Message()=default
virtual auto clone() const -> std::unique_ptr< Message >
Definition Message.h:44
Message(Message &&other) noexcept=default
virtual ~Message()=default
virtual auto load(const Stream &stream) -> void
Definition Message.cpp:23
Message(const Message &other)=default
auto operator=(const Message &other) -> Message &=default
auto operator=(Message &&other) noexcept -> Message &=default
static auto bindLuaTypes(sol::state &lua) -> void
Definition Message.cpp:18