From acf586b058598169e9e00d419906a5b7b34bd22f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 23 Sep 2016 12:07:00 -0500 Subject: [PATCH] add MidiByteArray::compare_n() --- libs/surfaces/push2/midi_byte_array.cc | 19 +++++++++++++++++++ libs/surfaces/push2/midi_byte_array.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/libs/surfaces/push2/midi_byte_array.cc b/libs/surfaces/push2/midi_byte_array.cc index 45d0439a75..e66cd7d287 100644 --- a/libs/surfaces/push2/midi_byte_array.cc +++ b/libs/surfaces/push2/midi_byte_array.cc @@ -94,3 +94,22 @@ MidiByteArray & operator << (MidiByteArray & mba, const std::string & st) mba.insert (mba.end(), st.begin(), st.end()); return mba; } + +bool +MidiByteArray::compare_n (const MidiByteArray& other, MidiByteArray::size_type n) const +{ + MidiByteArray::const_iterator us = begin(); + MidiByteArray::const_iterator them = other.begin(); + + while (n && us != end() && them != other.end()) { + if ((*us) != (*them)) { + return false; + } + --n; + ++us; + ++them; + } + + return true; +} + diff --git a/libs/surfaces/push2/midi_byte_array.h b/libs/surfaces/push2/midi_byte_array.h index 3d3bcecd28..f9ab60e31b 100644 --- a/libs/surfaces/push2/midi_byte_array.h +++ b/libs/surfaces/push2/midi_byte_array.h @@ -52,6 +52,8 @@ public: MidiByteArray( size_t count, MIDI::byte array[] ); + bool compare_n (const MidiByteArray& other, MidiByteArray::size_type len) const; + /** Accepts a preceding count, and then a list of bytes */ -- 2.30.2