LyX 1.5.0 is released
[lyx.git] / src / Author.cpp
blob58751d07102aac9c2406163c343c2dc3929a60ef
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.
6 * \author John Levon
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "Author.h"
15 #include "support/lstrings.h"
17 #include <boost/assert.hpp>
19 #include "support/std_istream.h"
21 using std::string;
23 namespace lyx {
25 using support::token;
26 using support::trim;
29 bool operator==(Author const & l, Author const & r)
31 return l.name() == r.name() && l.email() == r.email();
35 std::ostream & operator<<(std::ostream & os, Author const & a)
37 // FIXME UNICODE
38 os << "\"" << to_utf8(a.name()) << "\" " << to_utf8(a.email());
39 return os;
42 std::istream & operator>>(std::istream & is, Author & a)
44 string s;
45 getline(is, s);
46 // FIXME UNICODE
47 a.name_ = from_utf8(trim(token(s, '\"', 1)));
48 a.email_ = from_utf8(trim(token(s, '\"', 2)));
49 return is;
53 AuthorList::AuthorList()
54 : last_id_(0)
59 int AuthorList::record(Author const & a)
61 Authors::const_iterator it(authors_.begin());
62 Authors::const_iterator itend(authors_.end());
64 for (; it != itend; ++it) {
65 if (it->second == a)
66 return it->first;
69 authors_[last_id_++] = a;
70 return last_id_ - 1;
74 void AuthorList::record(int id, Author const & a)
76 BOOST_ASSERT(unsigned(id) < authors_.size());
78 authors_[id] = a;
82 Author const & AuthorList::get(int id) const
84 Authors::const_iterator it(authors_.find(id));
85 BOOST_ASSERT(it != authors_.end());
86 return it->second;
90 AuthorList::Authors::const_iterator AuthorList::begin() const
92 return authors_.begin();
96 AuthorList::Authors::const_iterator AuthorList::end() const
98 return authors_.end();
102 } // namespace lyx