bibhtml  1.0
 All Classes Functions Variables Enumerations
bibentry.hpp
1 
2 // bibhtml: Generates HTML page (with images) from BibTex files
3 // See: https://www.telecom-paris.fr/~elc/software/
4 //
5 // Copyright 2020 Eric Lecolinet (eric.lecolinet@gmail.com)
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 
19 #ifndef __BibEntry__
20 #define __BibEntry__
21 #include <list>
22 #include <map>
23 #include "bibdefs.hpp"
24 
25 class Bib;
26 
27 
28 class BibAuthor {
29 public:
30  BibAuthor(const std::string& lastname, const std::string& firstname);
31 
32  std::string lastname_, firstname_, sortname_;
33  class BibGroup* authgroup_;
34  class AuthStats* stats_;
35 };
36 
37 
38 class BibAuthors : public std::list<BibAuthor*> {};
39 
40 
41 
44 class BibEntry {
45 public:
46  struct Field {std::string raw, parsed;};
47  using Fields = std::map<BibFields::ID, Field>;
48 
49  BibEntry(const std::string& key, const std::string& typeName,
51 
52  virtual ~BibEntry() = default;
53 
55  BibTypes::ID typeID() const {return type_;}
56 
58  const std::string& bibkey() const;
59 
61  bool isAuxiliary() const {return isAuxiliary_;}
62 
64  const std::string& field(BibFields::ID) const;
65 
67  void setField(BibFields::ID, const std::string& raw, const std::string& parsed);
68 
69  void setParsedField(BibFields::ID, const std::string& parsed);
70 
72  const Fields& fields() const {return fields_;}
73 
74  const BibAuthors& authors() const {return authors_;}
75 
76  void setMediaAndRank(class Bib&);
77 
78 private:
79  friend class Bib;
80  friend class BibEntryNode;
81  friend class BibReader;
82  BibTypes::ID type_;
83  bool isAuxiliary_{false};
84  Fields fields_;
85  BibAuthors authors_;
86 };
87 
88 
89 class BibGroup : public BibEntry {
90 public:
91  BibGroup(const std::string& name, const std::string& typeName,
92  BibTypes::ID typeID, bool isAuxiliary);
93 
94  const std::string& name() const {return name_;}
95 
96  std::string name_;
97  class AuthStats* stats_;
98 };
99 
100 
101 class BibEntryNode {
102 public:
103  BibEntryNode(BibEntry& entry)
104  : entry_(entry), index_(0), author_(nullptr) {}
105 
106  BibEntryNode(BibEntry& entry, int index, const BibAuthor* author = nullptr)
107  : entry_(entry), index_(index), author_(author) {}
108 
110  BibTypes::ID getTypeID() const {return entry_.type_;}
111 
113  const std::string& bibkey() const {return entry_.bibkey();}
114 
116  bool isAuxiliary() const {return entry_.isAuxiliary_;}
117 
119  const std::string& field(BibFields::ID id) const;
120 
122  void setField(BibFields::ID id, const std::string& raw, const std::string& parsed) {
123  entry_.setField(id, raw, parsed);
124  }
125 
126  void setParsedField(BibFields::ID id, const std::string& parsed) {
127  entry_.setParsedField(id, parsed);
128  }
129 
130  const BibAuthors& authors() const {return entry_.authors_;}
131 
132  void setMediaAndRank(class Bib& btw) {entry_.setMediaAndRank(btw);}
133 
134  BibEntry& entry_;
135  int index_;
136  const BibAuthor* author_;
137 };
138 
139 
142 class BibEntries : public std::list<BibEntryNode> {
143 public:
159  BibEntries* find(const std::string& query, bool ignoreCase, bool abridgedFields) const;
160 
162 
165  BibEntries* sort(const std::string& pattern, bool abridged) const;
166 
167  void setMediaAndRank(Bib&);
168 };
169 
170 #endif