add MidiByteArray::compare_n()
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 23 Sep 2016 17:07:00 +0000 (12:07 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 27 Sep 2016 19:59:31 +0000 (14:59 -0500)
libs/surfaces/push2/midi_byte_array.cc
libs/surfaces/push2/midi_byte_array.h

index 45d0439a75531052824e830071ee9c14dbebd8a3..e66cd7d28718c2da73395d81106663d58a2f0262 100644 (file)
@@ -94,3 +94,22 @@ MidiByteArray & operator <<  (MidiByteArray & mba, const std::string & st)
        mba.insert (mba.end(), st.begin(), st.end());
        return mba;
 }
        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;
+}
+       
index 3d3bcecd28d1688f09e487b180992c6dda7d8277..f9ab60e31b84086f8eda0aadb1f689a8cc170036 100644 (file)
@@ -52,6 +52,8 @@ public:
 
        MidiByteArray( size_t count, MIDI::byte array[] );
 
 
        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
        */
        /**
                Accepts a preceding count, and then a list of bytes
        */