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