diff --git a/src/chatlogic.cpp b/src/chatlogic.cpp index 87b9bc06..1e4f302b 100644 --- a/src/chatlogic.cpp +++ b/src/chatlogic.cpp @@ -18,10 +18,10 @@ ChatLogic::ChatLogic() //// // create instance of chatbot - _chatBot = new ChatBot("../images/chatbot.png"); + // _chatBot = new ChatBot("../images/chatbot.png"); - // add pointer to chatlogic so that chatbot answers can be passed on to the GUI - _chatBot->SetChatLogicHandle(this); + // // add pointer to chatlogic so that chatbot answers can be passed on to the GUI + // _chatBot->SetChatLogicHandle(this); //// //// EOF STUDENT CODE @@ -33,13 +33,13 @@ ChatLogic::~ChatLogic() //// // delete chatbot instance - delete _chatBot; + // delete _chatBot; // delete all nodes - for (auto it = std::begin(_nodes); it != std::end(_nodes); ++it) - { - (*it).reset(); - } + // for (auto it = std::begin(_nodes); it != std::end(_nodes); ++it) + // { + // (*it).reset(); + // } //// //// EOF STUDENT CODE @@ -208,9 +208,10 @@ void ChatLogic::LoadAnswerGraphFromFile(std::string filename) } } - // add chatbot to graph root node - _chatBot->SetRootNode(rootNode); - rootNode->MoveChatbotHere(_chatBot); + ChatBot lChatBot("../images/chatbot.png"); + lChatBot.SetChatLogicHandle(this); + lChatBot.SetRootNode(rootNode); + rootNode->MoveChatbotHere(std::move(lChatBot)); //// //// EOF STUDENT CODE diff --git a/src/graphnode.cpp b/src/graphnode.cpp index e80724fc..9a115e68 100644 --- a/src/graphnode.cpp +++ b/src/graphnode.cpp @@ -1,6 +1,6 @@ #include "graphedge.h" #include "graphnode.h" - +#include GraphNode::GraphNode(int id) { _id = id; @@ -11,7 +11,8 @@ GraphNode::~GraphNode() //// STUDENT CODE //// - delete _chatBot; + // delete _chatBot; + // _chatBot.reset(); //// //// EOF STUDENT CODE @@ -34,16 +35,17 @@ void GraphNode::AddEdgeToChildNode(std::shared_ptr edge) //// STUDENT CODE //// -void GraphNode::MoveChatbotHere(ChatBot *chatbot) +void GraphNode::MoveChatbotHere(ChatBot chatbot) { - _chatBot = chatbot; - _chatBot->SetCurrentNode(this); + _chatBot = std::move(chatbot); + _chatBot.GetChatLogicHandle()->SetChatbotHandle(&_chatBot); + _chatBot.SetCurrentNode(this); + } void GraphNode::MoveChatbotToNewNode(GraphNode *newNode) { - newNode->MoveChatbotHere(_chatBot); - _chatBot = nullptr; // invalidate pointer at source + newNode->MoveChatbotHere(std::move(_chatBot)); } //// //// EOF STUDENT CODE diff --git a/src/graphnode.h b/src/graphnode.h index 690dc051..450884a6 100644 --- a/src/graphnode.h +++ b/src/graphnode.h @@ -4,6 +4,7 @@ #include #include #include "chatbot.h" +#include "chatlogic.h" #include // forward declarations @@ -20,7 +21,7 @@ class GraphNode // data handles (not owned) std::vector> _parentEdges; // edges to preceding nodes - ChatBot *_chatBot; + ChatBot _chatBot; //// //// EOF STUDENT CODE @@ -49,7 +50,7 @@ class GraphNode //// STUDENT CODE //// - void MoveChatbotHere(ChatBot *chatbot); + void MoveChatbotHere(ChatBot chatbot); //// //// EOF STUDENT CODE