diff options
author | David Robillard <d@drobilla.net> | 2009-02-01 03:15:31 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-02-01 03:15:31 +0000 |
commit | e666c8e98fb95a69afae8818f22c25094adae7eb (patch) | |
tree | 096ced3dde2248d17e48887f042c9f4465643bb2 /libs/ardour/ardour/midi_buffer.h | |
parent | aaa91db6d9592684258267981e619b44cc2b7c40 (diff) |
Templateify MidiBuffer iterators (avoid code duplication since they're about to get less trivial).
Clean up MidiBuffer code.
git-svn-id: svn://localhost/ardour2/branches/3.0@4469 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/midi_buffer.h')
-rw-r--r-- | libs/ardour/ardour/midi_buffer.h | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/libs/ardour/ardour/midi_buffer.h b/libs/ardour/ardour/midi_buffer.h index 812f697aa3..2a368673a9 100644 --- a/libs/ardour/ardour/midi_buffer.h +++ b/libs/ardour/ardour/midi_buffer.h @@ -46,29 +46,24 @@ public: void resize(size_t); bool merge(const MidiBuffer& a, const MidiBuffer& b); - bool merge_in_place( const MidiBuffer &other ); + bool merge_in_place(const MidiBuffer &other); - struct iterator { - iterator(MidiBuffer& b, size_t i) : buffer(b), index(i) {} - - inline Evoral::MIDIEvent& operator*() const { return buffer[index]; } - inline iterator& operator++() { ++index; return *this; } // prefix - inline bool operator!=(const iterator& other) const { return index != other.index; } + template<typename B, typename E> + struct iterator_base { + iterator_base<B,E>(B& b, size_t i) : buffer(b), index(i) {} + + inline E& operator*() const { return buffer[index]; } + inline iterator_base<B,E>& operator++() { ++index; return *this; } // prefix + inline bool operator!=(const iterator_base<B,E>& other) const { + return index != other.index; + } - MidiBuffer& buffer; - size_t index; + B& buffer; + size_t index; }; - struct const_iterator { - const_iterator(const MidiBuffer& b, size_t i) : buffer(b), index(i) {} - - inline const Evoral::MIDIEvent& operator*() const { return buffer[index]; } - inline const_iterator& operator++() { ++index; return *this; } // prefix - inline bool operator!=(const const_iterator& other) const { return index != other.index; } - - const MidiBuffer& buffer; - size_t index; - }; + typedef iterator_base<MidiBuffer, Evoral::MIDIEvent> iterator; + typedef iterator_base<const MidiBuffer, const Evoral::MIDIEvent> const_iterator; iterator begin() { return iterator(*this, 0); } iterator end() { return iterator(*this, _size); } @@ -78,8 +73,8 @@ public: private: - friend class iterator; - friend class const_iterator; + friend class iterator_base<MidiBuffer, Evoral::MIDIEvent>; + friend class iterator_base<const MidiBuffer, const Evoral::MIDIEvent>; const Evoral::MIDIEvent& operator[](size_t i) const { assert(i < _size); return _events[i]; } Evoral::MIDIEvent& operator[](size_t i) { assert(i < _size); return _events[i]; } |