Skip to content

Commit

Permalink
final version.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongyu1988 committed Feb 22, 2024
1 parent 37e6c37 commit ae04a37
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 161 deletions.
194 changes: 194 additions & 0 deletions build/CMakeFiles/CMakeError.log

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions build/CMakeFiles/CMakeOutput.log
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,55 @@ Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" p

The CXX compiler identification is GNU, found in "/home/xiongyu1988/CppND-Memory-Management-Chatbot/build/CMakeFiles/3.20.4/CompilerIdCXX/CMakeCXXCompilerId.o"

Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /mnt/c/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
Build flags:
Id flags: -c

The output was:
0


Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.o"

The C compiler identification is GNU, found in "/home/xiongyu1988/CppND-Memory-Management-Chatbot/build/CMakeFiles/3.20.4/CompilerIdC/CMakeCCompilerId.o"

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /mnt/c/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe
Build flags:
Id flags: -c

The output was:
0


Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.o"

The CXX compiler identification is GNU, found in "/home/xiongyu1988/CppND-Memory-Management-Chatbot/build/CMakeFiles/3.20.4/CompilerIdCXX/CMakeCXXCompilerId.o"

Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /mnt/c/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
Build flags:
Id flags: -c

The output was:
0


Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.o"

The C compiler identification is GNU, found in "/home/xiongyu1988/CppND-Memory-Management-Chatbot/build/CMakeFiles/3.20.4/CompilerIdC/CMakeCCompilerId.o"

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /mnt/c/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe
Build flags:
Id flags: -c

The output was:
0


Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.o"

The CXX compiler identification is GNU, found in "/home/xiongyu1988/CppND-Memory-Management-Chatbot/build/CMakeFiles/3.20.4/CompilerIdCXX/CMakeCXXCompilerId.o"

122 changes: 49 additions & 73 deletions src/chatbot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,89 +44,65 @@ ChatBot::~ChatBot()

//// STUDENT CODE
////

//Copy Constructor
ChatBot::ChatBot(const ChatBot& other)
{
std::cout << "ChatBot Copy Constructor\n";

this->_image = new wxBitmap();
*_image = *other._image;

this->_currentNode = other._currentNode;
this->_rootNode = other._rootNode;
this->_chatLogic = other._chatLogic;
this->_chatLogic->SetChatbotHandle(this);
}

//Copy Assignment
ChatBot& ChatBot::operator=(const ChatBot& other)
{
std::cout << "ChatBot Copy Assignment\n";
if(this == &other) { return *(this); }
this->_image = new wxBitmap();
*_image = *other._image;

this->_currentNode = other._currentNode;
this->_rootNode = other._rootNode;
this->_chatLogic = other._chatLogic;
this->_chatLogic->SetChatbotHandle(this);
return *(this);
ChatBot::ChatBot(const ChatBot &source) // 2 : copy constructor
{
_chatLogic->SetChatbotHandle(this);
_rootNode = source._rootNode;
_currentNode = source._currentNode;
_image = new wxBitmap();
*_image = *source._image;
std::cout << "ChatBot Copy Constructor Called\n";
}

//Move Constructor
//_currentNode , _rootNode , _chatLogic
ChatBot::ChatBot(ChatBot&& other)
{
std::cout << "ChatBot Move Constructor\n";
this->_image = other._image;
other._image = nullptr;

this->_currentNode = other._currentNode;
other._currentNode = nullptr;

this->_rootNode = other._rootNode;
other._rootNode = nullptr;

this->_chatLogic = other._chatLogic;
this->_chatLogic->SetChatbotHandle(this);
other._chatLogic = nullptr;
ChatBot &ChatBot::operator=(const ChatBot &source) // 3 : copy assignment operator
{
std::cout << "ChatBot Copy Assignment Operator Called\n";
if (this == &source) {
return *this;
}
//delete _image;
_image = new wxBitmap();
*_image = *source._image;
_chatLogic->SetChatbotHandle(this);
return *this;
}

//Move Assignment
ChatBot& ChatBot::operator=(ChatBot&& other)
ChatBot::ChatBot(ChatBot &&source) // 4 : move constructor
{
std::cout << "ChatBot Move Assignment\n";
if (this == &other) { return *(this); }
if(_image != nullptr) { delete _image; }

this->_image = other._image;
other._image = nullptr;

this->_currentNode = other._currentNode;
other._currentNode = nullptr;

this->_rootNode = other._rootNode;
other._rootNode = nullptr;
std::cout << "ChatBot Move Constructor Called\n";
_chatLogic = source._chatLogic;
_currentNode = source._currentNode;
_rootNode = source._rootNode;
_image = source._image;
source._currentNode = nullptr;
source._chatLogic = nullptr;
source._rootNode = nullptr;
source._image = nullptr;
}

this->_chatLogic = other._chatLogic;
ChatBot &ChatBot::operator=(ChatBot &&source) // 5 : move assignment operator
{
std::cout << "ChatBot Move Assignment Operator Called\n";
if (this == &source) {
return *this;
}
if (_image!=nullptr) {
delete _image;
}
_image = source._image;
_chatLogic = source._chatLogic;
_chatLogic->SetChatbotHandle(this);

other._chatLogic = nullptr;

return *(this);
}


// ChatLogic::ChatLogic* getChatLogic()
// {
// return std::move(_chatLogic);
// }

_rootNode = source._rootNode;
_currentNode = source._currentNode;
source._currentNode = nullptr;
source._chatLogic = nullptr;
source._rootNode = nullptr;
source._image = nullptr;
return *this;
}
////
//// EOF STUDENT CODE


void ChatBot::ReceiveMessageFromUser(std::string message)
{
// loop over all edges and keywords and compute Levenshtein distance to query
Expand Down
17 changes: 10 additions & 7 deletions src/chatbot.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ class ChatBot
//// STUDENT CODE
////

ChatBot(const ChatBot& other); // Copy Constructor
ChatBot(ChatBot&& other); // Move Constructor
ChatBot& operator=(const ChatBot& other); // Copy Assignment operator
ChatBot& operator=(ChatBot&& other); // Move Assignment operator

ChatLogic* getChatLogic() { return std::move(_chatLogic); }

// copy constructor
ChatBot(const ChatBot &source);
// copy assignment operator
ChatBot& operator=(const ChatBot& source);
// move constructor
ChatBot(ChatBot&& source);
// move assignment operator
ChatBot &operator=(ChatBot &&source);

ChatLogic* GetChatLogic() { return _chatLogic; }
////
//// EOF STUDENT CODE

Expand Down
80 changes: 40 additions & 40 deletions src/graphnode.cpp
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
#include "graphedge.h"
#include "graphnode.h"
#ifndef GRAPHNODE_H_
#define GRAPHNODE_H_

#include <vector>
#include <string>
#include "chatbot.h"
#include <memory>

GraphNode::GraphNode(int id)
{
_id = id;
}

GraphNode::~GraphNode()
// forward declarations
class GraphEdge;

class GraphNode
{
private:
//// STUDENT CODE
////

//delete _chatBot;
// data handles (owned)
std::vector<std::unique_ptr<GraphEdge>> _childEdges; // edges to subsequent nodes

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

////
//// EOF STUDENT CODE
}

void GraphNode::AddToken(std::string token)
{
_answers.push_back(token);
}
// proprietary members
int _id;
std::vector<std::string> _answers;

void GraphNode::AddEdgeToParentNode(GraphEdge *edge)
{
_parentEdges.push_back(edge);
}
public:
// constructor / destructor
GraphNode(int id);
~GraphNode();

void GraphNode::AddEdgeToChildNode(std::unique_ptr<GraphEdge> edge)
{
_childEdges.push_back(std::move(edge));
}
// getter / setter
int GetID() { return _id; }
int GetNumberOfChildEdges() { return _childEdges.size(); }
GraphEdge *GetChildEdgeAtIndex(int index);
std::vector<std::string> GetAnswers() { return _answers; }
int GetNumberOfParents() { return _parentEdges.size(); }

//// STUDENT CODE
////
void GraphNode::MoveChatbotHere(ChatBot chatbot)
{
_chatBot = std::move(chatbot);
_chatBot.SetCurrentNode(this);
}

void GraphNode::MoveChatbotToNewNode(GraphNode *newNode)
{
newNode->MoveChatbotHere(std::move(_chatBot));
//_chatBot = nullptr; // invalidate pointer at source
}
////
//// EOF STUDENT CODE
// proprietary functions
void AddToken(std::string token); // add answers to list
void AddEdgeToParentNode(GraphEdge *edge);
void AddEdgeToChildNode(std::unique_ptr<GraphEdge> edge);

GraphEdge *GraphNode::GetChildEdgeAtIndex(int index)
{
//// STUDENT CODE
////

return _childEdges[index].get();
void MoveChatbotHere(ChatBot chatbot);

////
//// EOF STUDENT CODE
}

void MoveChatbotToNewNode(GraphNode *newNode);
};

#endif /* GRAPHNODE_H_ */
Loading

0 comments on commit ae04a37

Please sign in to comment.