]> git.lyx.org Git - lyx.git/blob - src/Author.cpp
Changed references as to where/how known issues are shown, i.e. added reference to...
[lyx.git] / src / Author.cpp
1 /**
2  * \file Author.cpp
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         // FIXME UNICODE
39         os << "\"" << to_utf8(a.name()) << "\" " << to_utf8(a.email());
40         return os;
41 }
42
43 std::istream & operator>>(std::istream & is, Author & a)
44 {
45         string s;
46         getline(is, s);
47         // FIXME UNICODE
48         a.name_ = from_utf8(trim(token(s, '\"', 1)));
49         a.email_ = from_utf8(trim(token(s, '\"', 2)));
50         return is;
51 }
52
53
54 AuthorList::AuthorList()
55         : last_id_(0)
56 {
57 }
58
59
60 int AuthorList::record(Author const & a)
61 {
62         Authors::const_iterator it(authors_.begin());
63         Authors::const_iterator itend(authors_.end());
64
65         for (;  it != itend; ++it) {
66                 if (it->second == a)
67                         return it->first;
68         }
69
70         authors_[last_id_++] = a;
71         return last_id_ - 1;
72 }
73
74
75 void AuthorList::record(int id, Author const & a)
76 {
77         BOOST_ASSERT(unsigned(id) < authors_.size());
78
79         authors_[id] = a;
80 }
81
82
83 Author const & AuthorList::get(int id) const
84 {
85         Authors::const_iterator it(authors_.find(id));
86         BOOST_ASSERT(it != authors_.end());
87         return it->second;
88 }
89
90
91 AuthorList::Authors::const_iterator AuthorList::begin() const
92 {
93         return authors_.begin();
94 }
95
96
97 AuthorList::Authors::const_iterator AuthorList::end() const
98 {
99         return authors_.end();
100 }
101
102
103 } // namespace lyx