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