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