2012-01-17 20:34:53 -05:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 2012-2015 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2012-01-17 20:34:53 -05:00
|
|
|
|
|
|
|
#ifndef __libpbd_unwinder_h__
|
|
|
|
#define __libpbd_unwinder_h__
|
|
|
|
|
2013-10-16 23:30:28 -04:00
|
|
|
#include "pbd/libpbd_visibility.h"
|
|
|
|
|
2012-01-17 20:34:53 -05:00
|
|
|
namespace PBD {
|
|
|
|
|
|
|
|
template <typename T>
|
2013-12-01 09:26:08 -05:00
|
|
|
class /*LIBPBD_API*/ Unwinder {
|
2012-01-17 20:34:53 -05:00
|
|
|
public:
|
|
|
|
Unwinder (T& var, T new_val) : _var (var), _old_val (var) { var = new_val; }
|
|
|
|
~Unwinder () { _var = _old_val; }
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-01-17 20:34:53 -05:00
|
|
|
private:
|
|
|
|
T& _var;
|
|
|
|
T _old_val;
|
|
|
|
};
|
|
|
|
|
2022-06-13 12:51:04 -04:00
|
|
|
template <typename T>
|
|
|
|
class /*LIBPBD_API*/ ExceptionSafeIncDec {
|
|
|
|
public:
|
|
|
|
ExceptionSafeIncDec (T& var) : _var (var) { _var++; }
|
|
|
|
~ExceptionSafeIncDec () { _var--; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
T& _var;
|
|
|
|
};
|
|
|
|
|
2012-01-17 20:34:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __libpbd_unwinder_h__ */
|