/*****************************************************************************
 * $LastChangedDate: 2010-02-27 16:02:48 -0500 (Sat, 27 Feb 2010) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   AutoFlag class.
 *//*
 * LEGAL:   COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef BASE_AUTO_FLAG_HH
#define BASE_AUTO_FLAG_HH 1

#include "base/safe_ptr.hh"

namespace base {

////////////////////////////////////////////////////////////////////////////////
/// @brief Automatically ensures a flag is cleared before a function returns.
/// ~AutoFlag() will be invoked regardless of an unexpected early return or exception.
///
class AutoFlag
{
public:
    AutoFlag( SafePtr<bool> pFlag ) : mFlag(pFlag) { *pFlag = true; }
    ~AutoFlag( void ) { *mFlag = false; }
private:
    const SafePtr<bool> mFlag;
};

} // namespace base

#endif // BASE_AUTO_FLAG_HH
