Fix the authorlist code, shouldn't crash now

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6474 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-03-12 23:25:59 +00:00
parent 3327eb85a4
commit f36772d66a
6 changed files with 28 additions and 18 deletions

View File

@ -1,3 +1,11 @@
2003-03-12 John Levon <levon@movementarian.org>
* author.h:
* author.C:
* bufferparams.h:
* bufferparams.C:
* paragraph_funcs.C: fix per-buffer authorlists
2003-03-12 John Levon <levon@movementarian.org>
* text.C: fix newline in right address

View File

@ -12,20 +12,11 @@
#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;
namespace {
int cur_id;
}
bool operator==(Author const & l, Author const & r)
{
return l.name() == r.name() && l.email() == r.email();
@ -44,11 +35,16 @@ std::istream & operator>>(std::istream & is, Author & a)
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;
}
AuthorList::AuthorList()
: last_id_(0)
{
}
int AuthorList::record(Author const & a)
{
Authors::const_iterator it(authors_.begin());
@ -59,16 +55,14 @@ int AuthorList::record(Author const & a)
return it->first;
}
lyxerr[Debug::CHANGES] << "Adding author " << a << endl;
authors_[cur_id++] = a;
return cur_id - 1;
authors_[last_id_++] = a;
return last_id_ - 1;
}
void AuthorList::record(int id, Author const & a)
{
lyx::Assert(id < authors_.size());
lyx::Assert(unsigned(id) < authors_.size());
authors_[id] = a;
}

View File

@ -42,6 +42,8 @@ private:
class AuthorList {
public:
AuthorList();
int record(Author const & a);
void record(int id, Author const & a);
@ -55,6 +57,8 @@ public:
Authors::const_iterator end() const;
private:
int last_id_;
Authors authors_;
};

View File

@ -189,7 +189,7 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
istringstream ss(lex.getString());
Author a;
ss >> a;
authorlist.record(a);
author_map.push_back(authorlist.record(a));
} else if (token == "\\paperorientation") {
int tmpret = lex.findToken(string_orientation);
if (tmpret == -1)

View File

@ -24,6 +24,7 @@
#include "insets/insetquotes.h"
#include <boost/array.hpp>
#include <vector>
class LyXLex;
class LatexFeatures;
@ -232,6 +233,9 @@ public:
/// Time ago we agreed that this was a buffer property [ale990407]
string parentname;
/// map of the file's author IDs to buffer author IDs
std::vector<int> author_map;
private:
/// the author list
AuthorList authorlist;

View File

@ -945,7 +945,7 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
lyx::time_type ct;
istr >> aid;
istr >> ct;
change = Change(Change::INSERTED, aid, ct);
change = Change(Change::INSERTED, bp.author_map[aid], ct);
} else if (token == "\\change_deleted") {
lex.nextToken();
istringstream istr(lex.getString());
@ -953,7 +953,7 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
lyx::time_type ct;
istr >> aid;
istr >> ct;
change = Change(Change::DELETED, aid, ct);
change = Change(Change::DELETED, bp.author_map[aid], ct);
} else {
lex.eatLine();
#if USE_BOOST_FORMAT