Skip to content

Commit

Permalink
TASK 5 move chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
sol981 committed Apr 1, 2024
1 parent e2f8ec0 commit f968950
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
23 changes: 12 additions & 11 deletions src/chatlogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/graphnode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "graphedge.h"
#include "graphnode.h"

#include <iostream>
GraphNode::GraphNode(int id)
{
_id = id;
Expand All @@ -11,7 +11,8 @@ GraphNode::~GraphNode()
//// STUDENT CODE
////

delete _chatBot;
// delete _chatBot;
// _chatBot.reset();

////
//// EOF STUDENT CODE
Expand All @@ -34,16 +35,17 @@ void GraphNode::AddEdgeToChildNode(std::shared_ptr<GraphEdge> 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
Expand Down
5 changes: 3 additions & 2 deletions src/graphnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>
#include <string>
#include "chatbot.h"
#include "chatlogic.h"
#include <memory>

// forward declarations
Expand All @@ -20,7 +21,7 @@ class GraphNode

// data handles (not owned)
std::vector<std::shared_ptr<GraphEdge>> _parentEdges; // edges to preceding nodes
ChatBot *_chatBot;
ChatBot _chatBot;

////
//// EOF STUDENT CODE
Expand Down Expand Up @@ -49,7 +50,7 @@ class GraphNode
//// STUDENT CODE
////

void MoveChatbotHere(ChatBot *chatbot);
void MoveChatbotHere(ChatBot chatbot);

////
//// EOF STUDENT CODE
Expand Down

0 comments on commit f968950

Please sign in to comment.