aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-03-01 07:25:17 +0100
committerMax Kellermann <max@duempel.org>2014-03-01 07:49:13 +0100
commit4ba7427fa0f4c8495df331829eb67b27be9c9078 (patch)
treed34390e68bcd7a26145ea308ea0ee842d637ba32 /src
parent9dc5335e3e4e07371cfae96eca2cb5b2a93c8dd2 (diff)
downloadmpd-4ba7427fa0f4c8495df331829eb67b27be9c9078.tar.gz
mpd-4ba7427fa0f4c8495df331829eb67b27be9c9078.tar.xz
mpd-4ba7427fa0f4c8495df331829eb67b27be9c9078.zip
util/{Const,Writable}Buffer: add operator[]
Diffstat (limited to '')
-rw-r--r--src/input/TextInputStream.cxx2
-rw-r--r--src/pcm/FallbackResampler.cxx6
-rw-r--r--src/util/ConstBuffer.hxx11
-rw-r--r--src/util/WritableBuffer.hxx11
4 files changed, 26 insertions, 4 deletions
diff --git a/src/input/TextInputStream.cxx b/src/input/TextInputStream.cxx
index 25b9b42fe..d7cb440b3 100644
--- a/src/input/TextInputStream.cxx
+++ b/src/input/TextInputStream.cxx
@@ -63,7 +63,7 @@ bool TextInputStream::ReadLine(std::string &line)
the current line */
dest = buffer.Write();
assert(!dest.IsEmpty());
- dest.data[0] = '\n';
+ dest[0] = '\n';
buffer.Append(1);
}
} while (p == nullptr);
diff --git a/src/pcm/FallbackResampler.cxx b/src/pcm/FallbackResampler.cxx
index d005a831c..bd3f20d86 100644
--- a/src/pcm/FallbackResampler.cxx
+++ b/src/pcm/FallbackResampler.cxx
@@ -85,7 +85,7 @@ pcm_resample_fallback(PcmBuffer &buffer,
while (dest_pos < dest_samples) {
unsigned src_pos = dest_pos * src_rate / dest_rate;
- dest_buffer[dest_pos++] = src.data[src_pos];
+ dest_buffer[dest_pos++] = src[src_pos];
}
break;
case 2:
@@ -93,8 +93,8 @@ pcm_resample_fallback(PcmBuffer &buffer,
unsigned src_pos = dest_pos * src_rate / dest_rate;
src_pos &= ~1;
- dest_buffer[dest_pos++] = src.data[src_pos];
- dest_buffer[dest_pos++] = src.data[src_pos + 1];
+ dest_buffer[dest_pos++] = src[src_pos];
+ dest_buffer[dest_pos++] = src[src_pos + 1];
}
break;
}
diff --git a/src/util/ConstBuffer.hxx b/src/util/ConstBuffer.hxx
index 7f1fa5aa6..6754cb065 100644
--- a/src/util/ConstBuffer.hxx
+++ b/src/util/ConstBuffer.hxx
@@ -143,6 +143,17 @@ struct ConstBuffer {
constexpr const_iterator cend() const {
return data + size;
}
+
+#ifdef NDEBUG
+ constexpr
+#endif
+ const T &operator[](size_type i) const {
+#ifndef NDEBUG
+ assert(i < size);
+#endif
+
+ return data[i];
+ }
};
#endif
diff --git a/src/util/WritableBuffer.hxx b/src/util/WritableBuffer.hxx
index 64e6d0c62..d13f80867 100644
--- a/src/util/WritableBuffer.hxx
+++ b/src/util/WritableBuffer.hxx
@@ -145,6 +145,17 @@ struct WritableBuffer {
constexpr const_iterator cend() const {
return data + size;
}
+
+#ifdef NDEBUG
+ constexpr
+#endif
+ T &operator[](size_type i) const {
+#ifndef NDEBUG
+ assert(i < size);
+#endif
+
+ return data[i];
+ }
};
#endif