From a03746c0343c9588db91c20161de8c46eeba339e Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Tue, 15 Jun 2021 22:03:11 -0500 Subject: [PATCH] Make ChatCommands archivable --- application/ChatCommand.cpp | 40 +++++++++++++++++++++++++++++++++++++ application/ChatCommand.h | 8 +++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/application/ChatCommand.cpp b/application/ChatCommand.cpp index 117e346..088b992 100644 --- a/application/ChatCommand.cpp +++ b/application/ChatCommand.cpp @@ -23,6 +23,46 @@ ChatCommand::ChatCommand(const char* name, BMessage msg, bool toProtocol, } +ChatCommand::ChatCommand(BMessage* data) + : BArchivable(data) +{ + data->FindString("_name", &fName); + data->FindString("_desc", &fDescription); + data->FindBool("_proto", &fToProto); + data->FindMessage("_msg", &fMessage); + + int32 argType, i = 0; + while (data->FindInt32("_argtype", i, &argType) == B_OK) { + fArgTypes.AddItem(argType); + i++; + } +} + + +status_t +ChatCommand::Archive(BMessage* data, bool deep) +{ + status_t ret = BArchivable::Archive(data, deep); + data->AddString("_name", fName); + data->AddString("_desc", fDescription); + data->AddBool("_proto", fToProto); + data->AddMessage("_msg", new BMessage(fMessage)); + + for (int i = 0; i < fArgTypes.CountItems(); i++) + data->AddInt32("_argtype", fArgTypes.ItemAt(i)); + return ret; +} + + +ChatCommand* +ChatCommand::Instantiate(BMessage* data) +{ + if (!validate_instantiation(data, "ChatCommand")) + return NULL; + return new ChatCommand(data); +} + + void ChatCommand::SetDesc(const char* description) { diff --git a/application/ChatCommand.h b/application/ChatCommand.h index b1e9b58..fa7f206 100644 --- a/application/ChatCommand.h +++ b/application/ChatCommand.h @@ -5,6 +5,7 @@ #ifndef CHAT_COMMAND_H #define CHAT_COMMAND_H +#include #include #include @@ -23,10 +24,15 @@ enum cmd_arg_type }; -class ChatCommand { +class ChatCommand : public BArchivable { public: ChatCommand(const char* name, BMessage msg, bool toProtocol, List argTypes); + ChatCommand(BMessage* data); + + status_t Archive(BMessage* data, bool deep=true); + ChatCommand* Instantiate(BMessage* data); + const char* GetName() { return fName.String(); }