about summary refs log tree commit diff
path: root/src/libutil/util.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-08-14T20·42+0200
committerEelco Dolstra <edolstra@gmail.com>2017-08-16T18·56+0200
commitbf1f123b09ec7402b0565808619e11b5bfe6b16b (patch)
treed0e4c9af039b8bf05244f648907c21274ee37054 /src/libutil/util.hh
parent0e0dcf2c7ec054f1b30629e275f53f56039b8257 (diff)
Progress indicator: Show number of active items
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r--src/libutil/util.hh14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index f37f2c5d1be5..35909c8d5b31 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -462,4 +462,18 @@ struct ReceiveInterrupts
     { }
 };
 
+
+
+/* A RAII helper that increments a counter on construction and
+   decrements it on destruction. */
+template<typename T>
+struct MaintainCount
+{
+    T & counter;
+    long delta;
+    MaintainCount(T & counter, long delta = 1) : counter(counter), delta(delta) { counter += delta; }
+    ~MaintainCount() { counter -= delta; }
+};
+
+
 }