summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Moore <neil@s-z.org>2014-08-14 16:35:06 -0400
committerNeil Moore <neil@s-z.org>2014-08-14 16:35:06 -0400
commit319ca6a20c040f66867e42ea5fc28efefddeed22 (patch)
treef8aadf8f00ba3a04885ef546ea8ffea167dbc928
parent717b5469982b9393369e883ab6b27d5a22cfceb2 (diff)
downloadcrawl-ref-319ca6a20c040f66867e42ea5fc28efefddeed22.tar.gz
crawl-ref-319ca6a20c040f66867e42ea5fc28efefddeed22.zip
Document unwind_var.
-rw-r--r--crawl-ref/source/unwind.h23
1 files changed, 20 insertions, 3 deletions
diff --git a/crawl-ref/source/unwind.h b/crawl-ref/source/unwind.h
index 426d629225..c13dda320b 100644
--- a/crawl-ref/source/unwind.h
+++ b/crawl-ref/source/unwind.h
@@ -1,29 +1,46 @@
#ifndef UNWIND_H
#define UNWIND_H
+/** Type that gives an lvalue dynamically-scoped temporary value. An
+ * unwind_var remembers the old value of a variable or other writable lvalue,
+ * and restores the original (or a specified) value when the unwind_var goes
+ * out of scope or is otherwise destroyed.
+ */
template <typename T>
class unwind_var
{
public:
- unwind_var(T &val_, T newval, T reset_to) : val(val_), oldval(reset_to)
+ /** Wrap the lvalue val_ and on unwinding restore its original value. */
+ unwind_var(T &val_) : val(val_), oldval(val_) { }
+
+ /** Wrap the lvalue val_, assign it the temporary value newval, and
+ * on unwinding restore its original value.
+ */
+ unwind_var(T &val_, T newval) : val(val_), oldval(val_)
{
val = newval;
}
- unwind_var(T &val_, T newval) : val(val_), oldval(val_)
+
+ /** Wrap the lvalue val_, assign it the temporary value newval, and
+ * on unwinding assign it the value reset_to.
+ */
+ unwind_var(T &val_, T newval, T reset_to) : val(val_), oldval(reset_to)
{
val = newval;
}
- unwind_var(T &val_) : val(val_), oldval(val_) { }
+
~unwind_var()
{
val = oldval;
}
+ /** Get the current (temporary) value of the wrapped lvalue. */
T value() const
{
return val;
}
+ /** Get the value that will be used to restore the wrapped lvalue. */
T original_value() const
{
return oldval;