+void AuthorList::sort() {
+ std::sort(authors_.begin(), authors_.end(), author_smaller);
+}
+
+
+ostream & operator<<(ostream & os, AuthorList const & a) {
+ // Copy the authorlist, because we don't want to sort the original
+ AuthorList sorted = a;
+ sorted.sort();
+
+ AuthorList::Authors::const_iterator a_it = sorted.begin();
+ AuthorList::Authors::const_iterator a_end = sorted.end();
+
+ // Find the buffer id for the current author (internal id 0),
+ // if he doesn't have a buffer_id yet.
+ if (sorted.get(0).buffer_id() == 0) {
+ unsigned int cur_id = 1;
+ for (; a_it != a_end; ++a_it) {
+ if (a_it->buffer_id() == cur_id)
+ ++cur_id;
+ else if (a_it->buffer_id() > cur_id) {
+ break;
+ }
+ }
+ // Set the id in both the original authorlist,
+ // as in the copy.
+ a.get(0).setBufferId(cur_id);
+ sorted.get(0).setBufferId(cur_id);
+ sorted.sort();
+ }
+
+ for (a_it = sorted.begin(); a_it != a_end; ++a_it) {
+ if (a_it->used())
+ os << "\\author " << *a_it << "\n";
+ }
+ return os;
+}
+
+