Added CallOnExit class

Former-commit-id: d4b6bb17a8183f46e4631d727fc8056eb2fcb254
This commit is contained in:
Lynix 2014-02-18 01:01:30 +01:00
parent 4df6c30a26
commit c42eff2db0
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,28 @@
// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CALLONEXIT_HPP
#define NAZARA_CALLONEXIT_HPP
#include <Nazara/Prerequesites.hpp>
class NzCallOnExit
{
using Func = void (*)();
public:
NzCallOnExit(Func func = nullptr);
~NzCallOnExit();
void Reset(Func func = nullptr);
private:
Func m_func;
};
#include <Nazara/Core/CallOnExit.inl>
#endif // NAZARA_CALLONEXIT_HPP

View File

@ -0,0 +1,23 @@
// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Debug.hpp>
inline NzCallOnExit::NzCallOnExit(Func func) :
m_func(func)
{
}
inline NzCallOnExit::~NzCallOnExit()
{
if (m_func)
m_func();
}
inline void NzCallOnExit::Reset(Func func)
{
m_func = func;
}
#include <Nazara/Core/DebugOff.hpp>