aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util/ConstBuffer.hxx59
-rw-r--r--src/util/WritableBuffer.hxx59
2 files changed, 118 insertions, 0 deletions
diff --git a/src/util/ConstBuffer.hxx b/src/util/ConstBuffer.hxx
index bb114d44d..319102126 100644
--- a/src/util/ConstBuffer.hxx
+++ b/src/util/ConstBuffer.hxx
@@ -164,6 +164,65 @@ struct ConstBuffer {
return data[i];
}
+
+ /**
+ * Returns a reference to the first element. Buffer must not
+ * be empty.
+ */
+#ifdef NDEBUG
+ constexpr
+#endif
+ reference_type front() const {
+#ifndef NDEBUG
+ assert(!IsEmpty());
+#endif
+ return data[0];
+ }
+
+ /**
+ * Returns a reference to the last element. Buffer must not
+ * be empty.
+ */
+#ifdef NDEBUG
+ constexpr
+#endif
+ reference_type back() const {
+#ifndef NDEBUG
+ assert(!IsEmpty());
+#endif
+ return data[size - 1];
+ }
+
+ /**
+ * Remove the first element (by moving the head pointer, does
+ * not actually modify the buffer). Buffer must not be empty.
+ */
+ void pop_front() {
+ assert(!IsEmpty());
+
+ ++data;
+ --size;
+ }
+
+ /**
+ * Remove the last element (by moving the tail pointer, does
+ * not actually modify the buffer). Buffer must not be empty.
+ */
+ void pop_back() {
+ assert(!IsEmpty());
+
+ --size;
+ }
+
+ /**
+ * Remove the first element and return a reference to it.
+ * Buffer must not be empty.
+ */
+ reference_type shift() {
+ reference_type result = front();
+ pop_front();
+ return result;
+ }
};
#endif
diff --git a/src/util/WritableBuffer.hxx b/src/util/WritableBuffer.hxx
index 1fe1b254f..f9e6d4a96 100644
--- a/src/util/WritableBuffer.hxx
+++ b/src/util/WritableBuffer.hxx
@@ -158,6 +158,65 @@ struct WritableBuffer {
return data[i];
}
+
+ /**
+ * Returns a reference to the first element. Buffer must not
+ * be empty.
+ */
+#ifdef NDEBUG
+ constexpr
+#endif
+ reference_type front() const {
+#ifndef NDEBUG
+ assert(!IsEmpty());
+#endif
+ return data[0];
+ }
+
+ /**
+ * Returns a reference to the last element. Buffer must not
+ * be empty.
+ */
+#ifdef NDEBUG
+ constexpr
+#endif
+ reference_type back() const {
+#ifndef NDEBUG
+ assert(!IsEmpty());
+#endif
+ return data[size - 1];
+ }
+
+ /**
+ * Remove the first element (by moving the head pointer, does
+ * not actually modify the buffer). Buffer must not be empty.
+ */
+ void pop_front() {
+ assert(!IsEmpty());
+
+ ++data;
+ --size;
+ }
+
+ /**
+ * Remove the last element (by moving the tail pointer, does
+ * not actually modify the buffer). Buffer must not be empty.
+ */
+ void pop_back() {
+ assert(!IsEmpty());
+
+ --size;
+ }
+
+ /**
+ * Remove the first element and return a reference to it.
+ * Buffer must not be empty.
+ */
+ reference_type shift() {
+ reference_type result = front();
+ pop_front();
+ return result;
+ }
};
#endif