plugin code
[lbook_fbreader.git] / fbreader / src / description / Author.h
blob6b5c2391a09709d15e2042132dd4035a1e8054c3
1 /*
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
17 * 02110-1301, USA.
20 #ifndef __AUTHOR_H__
21 #define __AUTHOR_H__
23 #include <string>
24 #include <vector>
26 #include <shared_ptr.h>
28 class Author;
29 typedef shared_ptr<Author> AuthorPtr;
31 class Author {
33 protected:
34 Author();
36 public:
37 virtual ~Author();
39 virtual const std::string &displayName() const = 0;
40 virtual const std::string &sortKey() const = 0;
41 virtual bool isSingle() const = 0;
43 private:
44 Author(const Author&);
45 const Author &operator= (const Author&);
48 class SingleAuthor : public Author {
50 public:
51 static AuthorPtr create(const std::string &displayName, const std::string &sortKey);
52 static AuthorPtr create();
54 private:
55 SingleAuthor(const std::string &displayName, const std::string &sortKey);
57 public:
58 const std::string &displayName() const;
59 const std::string &sortKey() const;
60 bool isSingle() const;
62 private:
63 std::string myDisplayName;
64 std::string mySortKey;
67 class MultiAuthor : public Author {
69 public:
70 static AuthorPtr create(AuthorPtr author);
72 private:
73 MultiAuthor(AuthorPtr author);
75 public:
76 void addAuthor(AuthorPtr author) ;
77 const std::string &displayName() const;
78 const std::string &sortKey() const;
79 bool isSingle() const;
81 private:
82 std::vector<AuthorPtr > myAuthors;
83 mutable std::string myDisplayName;
84 mutable std::string mySortKey;
87 class AuthorComparator {
89 public:
90 AuthorComparator();
91 ~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) {
108 return
109 (a1->sortKey() < a2->sortKey()) ||
110 ((a1->sortKey() == a2->sortKey()) && (a1->displayName() < a2->displayName()));
113 #endif /* __AUTHOR_H__ */