]> git.lyx.org Git - lyx.git/blob - src/author.C
Fix the authorlist code, shouldn't crash now
[lyx.git] / src / author.C
1 /**
2  * \file author.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #include "author.h"
14
15 #include "support/LAssert.h"
16 #include "support/LOstream.h"
17 #include "support/LIstream.h"
18 #include "support/lstrings.h"
19
20 bool operator==(Author const & l, Author const & r)
21 {
22         return l.name() == r.name() && l.email() == r.email();
23 }
24
25
26 std::ostream & operator<<(std::ostream & os, Author const & a)
27 {
28         os << "\"" << a.name() << "\" " << a.email();
29         return os;
30 }
31
32 std::istream & operator>>(std::istream & is, Author & a)
33 {
34         string s;
35         getline(is, s);
36         a.name_ = trim(token(s, '\"', 1));
37         a.email_ = trim(token(s, '\"', 2));
38         return is;
39 }
40
41
42 AuthorList::AuthorList()
43         : last_id_(0)
44 {
45 }
46
47
48 int AuthorList::record(Author const & a)
49 {
50         Authors::const_iterator it(authors_.begin());
51         Authors::const_iterator itend(authors_.end());
52
53         for (;  it != itend; ++it) {
54                 if (it->second == a)
55                         return it->first;
56         }
57
58         authors_[last_id_++] = a;
59         return last_id_ - 1;
60 }
61
62
63 void AuthorList::record(int id, Author const & a)
64 {
65         lyx::Assert(unsigned(id) < authors_.size());
66
67         authors_[id] = a;
68 }
69
70
71 Author const & AuthorList::get(int id)
72 {
73         Authors::const_iterator it(authors_.find(id));
74         lyx::Assert(it != authors_.end());
75         return it->second;
76 }
77
78
79 AuthorList::Authors::const_iterator AuthorList::begin() const
80 {
81         return authors_.begin();
82 }
83
84
85 AuthorList::Authors::const_iterator AuthorList::end() const
86 {
87         return authors_.end();
88 }