Skip to content

Commit

Permalink
Remove Mile::DisableCopyConstruction, Mile::DisableMoveConstruction a…
Browse files Browse the repository at this point in the history
…nd Mile::ScopeExitTaskHandler.
  • Loading branch information
MouriNaruto committed Nov 9, 2023
1 parent 81bc813 commit ef16cf4
Showing 1 changed file with 0 additions and 83 deletions.
83 changes: 0 additions & 83 deletions NanaGet/NanaGetCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,89 +27,6 @@
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.Streams.h>

namespace Mile
{
/**
* @brief Disables C++ class copy construction.
*/
class DisableCopyConstruction
{
protected:
DisableCopyConstruction() = default;
~DisableCopyConstruction() = default;

private:
DisableCopyConstruction(
const DisableCopyConstruction&) = delete;
DisableCopyConstruction& operator=(
const DisableCopyConstruction&) = delete;
};

/**
* @brief Disables C++ class move construction.
*/
class DisableMoveConstruction
{
protected:
DisableMoveConstruction() = default;
~DisableMoveConstruction() = default;

private:
DisableMoveConstruction(
const DisableMoveConstruction&&) = delete;
DisableMoveConstruction& operator=(
const DisableMoveConstruction&&) = delete;
};

/**
* @brief The template for defining the task when exit the scope.
* @tparam TaskHandlerType The type of the task handler.
* @remark For more information, see ScopeGuard.
*/
template<typename TaskHandlerType>
class ScopeExitTaskHandler :
DisableCopyConstruction,
DisableMoveConstruction
{
private:
bool m_Canceled;
TaskHandlerType m_TaskHandler;

public:

/**
* @brief Creates the instance for the task when exit the scope.
* @param TaskHandler The instance of the task handler.
*/
explicit ScopeExitTaskHandler(TaskHandlerType&& EventHandler) :
m_Canceled(false),
m_TaskHandler(std::forward<TaskHandlerType>(EventHandler))
{

}

/**
* @brief Executes and uninitializes the instance for the task when
* exit the scope.
*/
~ScopeExitTaskHandler()
{
if (!this->m_Canceled)
{
this->m_TaskHandler();
}
}

/**
* @brief Cancels the task when exit the scope.
*/
void Cancel()
{
this->m_Canceled = true;
}
};
}

namespace NanaGet
{
NLOHMANN_JSON_SERIALIZE_ENUM(NanaGet::Aria2UriStatus, {
Expand Down

0 comments on commit ef16cf4

Please sign in to comment.