2003-02-08 19:18:01 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Author.cpp
|
2003-02-08 19:18:01 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-08 19:18:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Author.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2003-03-02 12:16:00 +00:00
|
|
|
|
2003-09-09 17:25:35 +00:00
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
#include "support/std_istream.h"
|
|
|
|
|
2007-07-17 17:40:44 +00:00
|
|
|
using std::string;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using support::token;
|
|
|
|
using support::trim;
|
2003-09-09 17:25:35 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
bool operator==(Author const & l, Author const & r)
|
|
|
|
{
|
|
|
|
return l.name() == r.name() && l.email() == r.email();
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & os, Author const & a)
|
|
|
|
{
|
2006-12-21 13:58:28 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
os << "\"" << to_utf8(a.name()) << "\" " << to_utf8(a.email());
|
2003-02-08 19:18:01 +00:00
|
|
|
return os;
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
std::istream & operator>>(std::istream & is, Author & a)
|
|
|
|
{
|
|
|
|
string s;
|
|
|
|
getline(is, s);
|
2006-12-21 13:58:28 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
a.name_ = from_utf8(trim(token(s, '\"', 1)));
|
|
|
|
a.email_ = from_utf8(trim(token(s, '\"', 2)));
|
2003-02-08 19:18:01 +00:00
|
|
|
return is;
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
|
|
|
2003-03-12 23:25:59 +00:00
|
|
|
AuthorList::AuthorList()
|
|
|
|
: last_id_(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
int AuthorList::record(Author const & a)
|
|
|
|
{
|
|
|
|
Authors::const_iterator it(authors_.begin());
|
|
|
|
Authors::const_iterator itend(authors_.end());
|
2003-03-02 12:16:00 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
for (; it != itend; ++it) {
|
|
|
|
if (it->second == a)
|
|
|
|
return it->first;
|
2003-03-02 12:16:00 +00:00
|
|
|
}
|
|
|
|
|
2003-03-12 23:25:59 +00:00
|
|
|
authors_[last_id_++] = a;
|
|
|
|
return last_id_ - 1;
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
void AuthorList::record(int id, Author const & a)
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(unsigned(id) < authors_.size());
|
2003-03-02 12:16:00 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
authors_[id] = a;
|
|
|
|
}
|
|
|
|
|
2003-03-02 12:16:00 +00:00
|
|
|
|
2007-03-04 09:37:32 +00:00
|
|
|
Author const & AuthorList::get(int id) const
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
|
|
|
Authors::const_iterator it(authors_.find(id));
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(it != authors_.end());
|
2003-02-08 19:18:01 +00:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2003-03-02 12:16:00 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
AuthorList::Authors::const_iterator AuthorList::begin() const
|
|
|
|
{
|
|
|
|
return authors_.begin();
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
AuthorList::Authors::const_iterator AuthorList::end() const
|
|
|
|
{
|
|
|
|
return authors_.end();
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|