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