]> git.lyx.org Git - lyx.git/blob - src/author.C
cosmetic fix
[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 using namespace lyx::support;
21
22 bool operator==(Author const & l, Author const & r)
23 {
24         return l.name() == r.name() && l.email() == r.email();
25 }
26
27
28 std::ostream & operator<<(std::ostream & os, Author const & a)
29 {
30         os << "\"" << a.name() << "\" " << a.email();
31         return os;
32 }
33
34 std::istream & operator>>(std::istream & is, Author & a)
35 {
36         string s;
37         getline(is, s);
38         a.name_ = trim(token(s, '\"', 1));
39         a.email_ = trim(token(s, '\"', 2));
40         return is;
41 }
42
43
44 AuthorList::AuthorList()
45         : last_id_(0)
46 {
47 }
48
49
50 int AuthorList::record(Author const & a)
51 {
52         Authors::const_iterator it(authors_.begin());
53         Authors::const_iterator itend(authors_.end());
54
55         for (;  it != itend; ++it) {
56                 if (it->second == a)
57                         return it->first;
58         }
59
60         authors_[last_id_++] = a;
61         return last_id_ - 1;
62 }
63
64
65 void AuthorList::record(int id, Author const & a)
66 {
67         Assert(unsigned(id) < authors_.size());
68
69         authors_[id] = a;
70 }
71
72
73 Author const & AuthorList::get(int id)
74 {
75         Authors::const_iterator it(authors_.find(id));
76         Assert(it != authors_.end());
77         return it->second;
78 }
79
80
81 AuthorList::Authors::const_iterator AuthorList::begin() const
82 {
83         return authors_.begin();
84 }
85
86
87 AuthorList::Authors::const_iterator AuthorList::end() const
88 {
89         return authors_.end();
90 }