2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include <shared_ptr.h>
29 typedef shared_ptr
<Author
> AuthorPtr
;
39 virtual const std::string
&displayName() const = 0;
40 virtual const std::string
&sortKey() const = 0;
41 virtual bool isSingle() const = 0;
44 Author(const Author
&);
45 const Author
&operator= (const Author
&);
48 class SingleAuthor
: public Author
{
51 static AuthorPtr
create(const std::string
&displayName
, const std::string
&sortKey
);
52 static AuthorPtr
create();
55 SingleAuthor(const std::string
&displayName
, const std::string
&sortKey
);
58 const std::string
&displayName() const;
59 const std::string
&sortKey() const;
60 bool isSingle() const;
63 std::string myDisplayName
;
64 std::string mySortKey
;
67 class MultiAuthor
: public Author
{
70 static AuthorPtr
create(AuthorPtr author
);
73 MultiAuthor(AuthorPtr author
);
76 void addAuthor(AuthorPtr author
) ;
77 const std::string
&displayName() const;
78 const std::string
&sortKey() const;
79 bool isSingle() const;
82 std::vector
<AuthorPtr
> myAuthors
;
83 mutable std::string myDisplayName
;
84 mutable std::string mySortKey
;
87 class AuthorComparator
{
92 bool operator() (const AuthorPtr a1
, const AuthorPtr a2
);
95 inline Author::Author() {}
96 inline Author::~Author() {}
98 inline AuthorPtr
SingleAuthor::create(const std::string
&displayName
, const std::string
&sortKey
) { return new SingleAuthor(displayName
, sortKey
); }
99 inline AuthorPtr
SingleAuthor::create() { return create("Unknown Author", "___"); }
100 inline SingleAuthor::SingleAuthor(const std::string
&displayName
, const std::string
&sortKey
) : myDisplayName(displayName
), mySortKey(sortKey
) {}
102 inline AuthorPtr
MultiAuthor::create(AuthorPtr author
) { return new MultiAuthor(author
); }
103 inline MultiAuthor::MultiAuthor(AuthorPtr author
) { addAuthor(author
); }
105 inline AuthorComparator::AuthorComparator() {}
106 inline AuthorComparator::~AuthorComparator() {}
107 inline bool AuthorComparator::operator() (const AuthorPtr a1
, const AuthorPtr a2
) {
109 (a1
->sortKey() < a2
->sortKey()) ||
110 ((a1
->sortKey() == a2
->sortKey()) && (a1
->displayName() < a2
->displayName()));
113 #endif /* __AUTHOR_H__ */