summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libutil.h
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source/libutil.h')
-rw-r--r--crawl-ref/source/libutil.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/crawl-ref/source/libutil.h b/crawl-ref/source/libutil.h
index 1191ca6312..e327ab6d74 100644
--- a/crawl-ref/source/libutil.h
+++ b/crawl-ref/source/libutil.h
@@ -116,23 +116,29 @@ void usleep( unsigned long time );
int snprintf( char *str, size_t size, const char *format, ... );
#endif
-// Sets a boolean to a new value in the scope of the object instance.
-class unwind_bool
+template <typename T>
+class unwind_var
{
public:
- unwind_bool(bool &val_, bool newval) : val(val_), oldval(val_)
+ unwind_var(T &val_, T newval, T reset_to) : val(val_), oldval(reset_to)
{
val = newval;
}
- ~unwind_bool()
+ unwind_var(T &val_, T newval) : val(val_), oldval(val_)
+ {
+ val = newval;
+ }
+ ~unwind_var()
{
val = oldval;
}
private:
- bool &val;
- bool oldval;
+ T &val;
+ T oldval;
};
+typedef unwind_var<bool> unwind_bool;
+
class base_pattern
{
public: