]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/track.cpp
Add a function to retrieve track attachments in order
[r2c2.git] / source / libr2c2 / track.cpp
index 26fb59e0fa7e756b619ad718d090dec6b6f05314..455cc88055c6301a8b7d53d29998a5d98cea8eb1 100644 (file)
@@ -5,11 +5,26 @@
 #include "driver.h"
 #include "layout.h"
 #include "track.h"
+#include "trackattachment.h"
 #include "tracktype.h"
 
 using namespace std;
 using namespace Msp;
 
+namespace {
+
+struct AttachmentCompare
+{
+       unsigned entry;
+
+       AttachmentCompare(unsigned e): entry(e) { }
+
+       bool operator()(const R2C2::TrackAttachment *a1, const R2C2::TrackAttachment *a2) const
+       { return a1->get_offset_from_endpoint(entry)<a2->get_offset_from_endpoint(entry); }
+};
+
+}
+
 namespace R2C2 {
 
 Track::Track(Layout &l, const TrackType &t):
@@ -347,6 +362,13 @@ void Track::remove_attachment(TrackAttachment &a)
        attachments.erase(i);
 }
 
+Track::AttachmentList Track::get_attachments_ordered(unsigned epi) const
+{
+       AttachmentList result = attachments;
+       result.sort(AttachmentCompare(epi));
+       return result;
+}
+
 void Track::save(list<DataFile::Statement> &st) const
 {
        st.push_back((DataFile::Statement("position"), position.x, position.y, position.z));