Implemented copy-assign and move-assign operators for HttpProcessor::Task to satisfy 'Rule of Two'.

This commit is contained in:
Benedikt-Alexander Mokroß 2021-02-23 09:53:24 +01:00
parent ca19e5b072
commit 29650b0557
2 changed files with 32 additions and 0 deletions

View File

@ -244,6 +244,24 @@ HttpProcessor::Task::Task(HttpProcessor::Task &&move)
move.m_counter = nullptr;
}
HttpProcessor::Task &HttpProcessor::Task::operator=(const HttpProcessor::Task &t) {
if (this != &t) {
m_components = t.m_components;
m_connection = t.m_connection;
m_counter = t.m_counter;
(*m_counter)++;
}
return *this;
}
HttpProcessor::Task &HttpProcessor::Task::operator=(HttpProcessor::Task &&t) {
m_components = std::move(t.m_components);
m_connection = std::move(t.m_connection);
m_counter = t.m_counter;
t.m_counter = nullptr;
return *this;
}
void HttpProcessor::Task::run(){
m_connection->initContexts();

View File

@ -207,11 +207,25 @@ public:
*/
Task(const Task &copy);
/**
* Copy-Assignment to correctly count tasks.
* @param t - Task to copy
* @return
*/
Task &operator=(const Task &t);
/**
* Move-Constructor to correclty count tasks;
*/
Task(Task &&move);
/**
* Move-Assignment to correctly count tasks.
* @param t
* @return
*/
Task &operator=(Task &&t);
/**
* Destructor, needed for counting.
*/