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
20 #ifndef __BOOKCOLLECTION_H__
21 #define __BOOKCOLLECTION_H__
28 #include <ZLOptions.h>
30 #include "../description/BookDescription.h"
32 typedef std::vector
<BookDescriptionPtr
> Books
;
34 class DescriptionComparator
{
37 DescriptionComparator();
38 ~DescriptionComparator();
39 bool operator() (const BookDescriptionPtr d1
, const BookDescriptionPtr d2
);
42 class BookCollection
{
45 ZLStringOption PathOption
;
46 ZLBooleanOption ScanSubdirsOption
;
52 const std::vector
<AuthorPtr
> &authors() const;
53 const Books
&books(AuthorPtr author
) const;
54 bool isBookExternal(BookDescriptionPtr description
) const;
56 void rebuild(bool strong
);
57 bool synchronize() const;
61 void collectDirNames(std::set
<std::string
> &names
) const;
62 void collectBookFileNames(std::set
<std::string
> &bookFileNames
) const;
64 void addDescription(BookDescriptionPtr description
) const;
67 mutable std::vector
<AuthorPtr
> myAuthors
;
68 mutable std::map
<AuthorPtr
,Books
> myCollection
;
69 mutable std::set
<BookDescriptionPtr
> myExternalBooks
;
71 mutable std::string myPath
;
72 mutable bool myScanSubdirs
;
73 mutable bool myDoStrongRebuild
;
74 mutable bool myDoWeakRebuild
;
77 class LastOpenedBooks
{
80 ZLIntegerRangeOption MaxListSizeOption
;
85 void addBook(const std::string
&fileName
);
86 const Books
&books() const;
92 inline DescriptionComparator::DescriptionComparator() {}
93 inline DescriptionComparator::~DescriptionComparator() {}
95 inline const std::vector
<AuthorPtr
> &BookCollection::authors() const {
100 inline const Books
&BookCollection::books(AuthorPtr author
) const {
102 return (*myCollection
.find(author
)).second
;
105 inline bool BookCollection::isBookExternal(BookDescriptionPtr description
) const {
107 return myExternalBooks
.find(description
) != myExternalBooks
.end();
110 inline const Books
&LastOpenedBooks::books() const { return myBooks
; }
112 #endif /* __BOOKCOLLECTION_H__ */