The code for managing author details for each change. Authors are stored
in the lyx file, and a new author is added automatically. Later patches
provide prefs for author details, and the author is also visible in the
UI.
diff -u -r1.151 Makefile.am
--- src/Makefile.am 12 Jan 2003 22:20:21 -0000 1.151
+++ src/Makefile.am 7 Feb 2003 11:31:45 -0000
@@ -87,6 +87,8 @@
ToolbarDefaults.C \
ToolbarDefaults.h \
WordLangTuple.h \
+ author.C \
+ author.h \
boost.C \
boost-inst.C \
box.h \
Index: src/author.C
===================================================================
RCS file: src/author.C
diff -N src/author.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/author.C 7 Feb 2003 11:31:45 -0000
@@ -0,0 +1,96 @@
+/**
+ * \file author.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+#include "author.h"
+
+#include "debug.h"
+
+#include "support/LAssert.h"
+#include "support/LOstream.h"
+#include "support/LIstream.h"
+#include "support/lstrings.h"
+
+using std::endl;
+
+AuthorList authorlist;
+
+namespace {
+ int cur_id;
+}
+
+
+bool operator==(Author const & l, Author const & r)
+{
+ return l.name() == r.name() && l.email() == r.email();
+}
+
+
+std::ostream & operator<<(std::ostream & os, Author const & a)
+{
+ os << "\"" << a.name() << "\" " << a.email();
+ return os;
+}
+
+std::istream & operator>>(std::istream & is, Author & a)
+{
+ string s;
+ getline(is, s);
+ a.name_ = trim(token(s, '\"', 1));
+ a.email_ = trim(token(s, '\"', 2));
+ lyxerr << "Read name " << a.name_ << " email " << a.email_ << endl;
+ return is;
+}
+
+
+int AuthorList::record(Author const & a)
+{
+ Authors::const_iterator it(authors_.begin());
+ Authors::const_iterator itend(authors_.end());
+
+ for (; it != itend; ++it) {
+ if (it->second == a)
+ return it->first;
+ }
+
+ lyxerr[Debug::CHANGES] << "Adding author " << a << endl;
+
+ authors_[cur_id++] = a;
+ return cur_id - 1;
+}
+
+
+void AuthorList::record(int id, Author const & a)
+{
+ lyx::Assert(id < authors_.size());
+
+ authors_[id] = a;
+}
+
+
+Author const & AuthorList::get(int id)
+{
+ Authors::const_iterator it(authors_.find(id));
+ lyx::Assert(it != authors_.end());
+ return it->second;
+}
+
+
+AuthorList::Authors::const_iterator AuthorList::begin() const
+{
+ return authors_.begin();
+}
+
+
+AuthorList::Authors::const_iterator AuthorList::end() const
+{
+ return authors_.end();
+}
Index: src/author.h
===================================================================
RCS file: src/author.h
diff -N src/author.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/author.h 7 Feb 2003 11:31:45 -0000
@@ -0,0 +1,70 @@
+/**
+ * \file author.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef AUTHOR_H
+#define AUTHOR_H
+
+#include <map>
+#include <iosfwd>
+
+#include "LString.h"
+
+class Author {
+public:
+ Author() {}
+
+ Author(string n, string e)
+ : name_(n), email_(e) {}
+
+ string const name() const {
+ return name_;
+ }
+
+ string const email() const {
+ return email_;
+ }
+
+ friend std::istream & operator>>(std::istream & os, Author & a);
+
+private:
+ string name_;
+
+ string email_;
+};
+
+
+class AuthorList {
+public:
+ int record(Author const & a);
+
+ void record(int id, Author const & a);
+
+ Author const & get(int id);
+
+ typedef std::map<int, Author> Authors;
+
+ Authors::const_iterator begin() const;
+
+ Authors::const_iterator end() const;
+
+private:
+ Authors authors_;
+};
+
+bool operator==(Author const & l, Author const & r);
+
+std::ostream & operator<<(std::ostream & os, Author const & a);
+
+std::istream & operator>>(std::istream & os, Author & a);
+
+/// singleton of all authors
+extern AuthorList authorlist;
+
+#endif // AUTHOR_H
Index: src/buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.399
diff -u -r1.399 buffer.C
--- src/buffer.C 23 Jan 2003 16:23:36 -0000 1.399
+++ src/buffer.C 7 Feb 2003 11:31:48 -0000
@@ -45,6 +45,7 @@
#include "lyxtextclasslist.h"
#include "sgml.h"
#include "paragraph_funcs.h"
+#include "author.h"
#include "frontends/LyXView.h"
@@ -1356,6 +1404,15 @@
// now write out the buffer paramters.
params.writeFile(ofs);
+ // if we're tracking, list all possible authors
+ if (params.tracking_changes) {
+ AuthorList::Authors::const_iterator it = authorlist.begin();
+ AuthorList::Authors::const_iterator end = authorlist.end();
+ for (; it != end; ++it) {
+ ofs << "\\author " << it->second << "\n";
+ }
+ }
+
Paragraph::depth_type depth = 0;
// this will write out all the paragraphs