bibhtml  1.0
 All Classes Functions Variables Enumerations
bib.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 __Bib__
20 #define __Bib__
21 
22 #include <vector>
23 #include <map>
24 #include "bibdefs.hpp"
25 #include "bibentry.hpp"
26 
27 class BibStyle;
28 class BibExtension;
29 
30 
32 enum class ShowImages{None, Left, Right};
33 
35 enum class ShowLinks{None, Text, Icon};
36 
37 
40 class Bib {
41 public:
42  typedef std::map<std::string, BibAuthors> AuthorMap;
43  typedef std::map<std::string, BibGroup*> GroupMap;
44  typedef std::map<std::string, BibEntry*> EntryMap;
45 
46  static Bib instance;
47  static std::list<BibExtension*> extensions;
48 
49  ~Bib();
50  void init(int argc, char *argv[]);
51 
52  bool interMode() const {return interMode_;}
53  bool verboseMode() const {return verboseMode_;}
54  bool breakLines() const {return breakLines_;}
55  bool showNumbers() const {return showNumbers_;}
56  ShowImages showImages() const {return showImages_;}
57  ShowLinks showLinks() const {return showLinks_;}
58  BibFields::ID showHeaders() const {return showHeaders_;}
59  const std::string& imageDir() const {return imageDir_;}
60  const std::string& htmlBegin() const {return htmlBegin_;}
61  const std::string& htmlEnd() const {return htmlEnd_;}
62  const BibEntries& medias() const {return medias_;}
63 
64  // - - Entries - -
65 
73  BibEntry* addEntry(const std::string& bibkey, const std::string& typeName, bool isAuxiliary);
74 
76  void completeEntry(BibEntry&);
77 
79  const BibEntry* getEntry(const std::string& bibkey) const;
80 
90  void select(const std::string& query_pattern);
91 
100  void sort(const std::string& sort_pattern);
101 
103  void clear();
104 
113  void readBib(const std::string& fileName, bool isAuxiliary);
114 
116  void setHtmlFile(const std::string& fileName);
117 
119  void setBibFile(const std::string& fileName);
120 
125  void writeHtml(bool display);
126 
131  void writeBib(bool display);
132 
133  // - - Authors - -
134 
135  BibAuthor* addAuthor(const std::string& lastname, const std::string& firstname);
136 
137  BibAuthor* getAuthor(const std::string& lastname, const std::string& firstname) const;
138 
139  const Bib::AuthorMap& authors() const {return authorMap_;}
140 
141  // - - Formatting - -
142 
144  void readTemplate(const std::string& fileName);
145 
147  void setFormat(const std::string& options);
148 
150  void setStyle(const std::string& styleKey);
151 
152  // - - Misc. - -
153 
155  void checkLinks(const std::string& fieldName);
156 
158  void showStats(std::string filename);
159 
161  void doCommand(const std::string& cmd, const std::string& args, bool& interFound, bool& showFound);
162 
164  static void echo(const std::string& msg);
165 
167  static void error(const char* command, const std::string& msg);
168 
170  static bool help();
171 
172 private:
173  friend class BibStats;
174  bool
175  templateSearched_{false}, hasMedias_{false},
176  interMode_{false}, verboseMode_{false},
177  breakLines_{true}, showNumbers_{false};
178  ShowImages showImages_{ShowImages::Left};
179  ShowLinks showLinks_{ShowLinks::Text};
180  BibFields::ID showHeaders_{BibFields::ID::year};
181  std::string imageDir_;
182  std::string outHtml_{BibSettings::OutHtml};
183  std::string outBib_{BibSettings::OutBib};
184  std::string htmlBegin_, htmlEnd_;
185  AuthorMap authorMap_;
186  GroupMap groupMap_;
187  EntryMap entryMap_, styleMap_;
188  BibEntries *selectEntries_{nullptr}, allEntries_, medias_;
189  BibStyle *style_{nullptr};
190 
191  class Commands {
192 #define BIBCOMMANDS \
193 read, aux, images, templ, out, outhtml, outbib, format, all, select, sort,\
194 clear, show, showhtml, showbib, check, stats, help, i, inter, verbose, quit
195  public:
196  enum ID {BIBCOMMANDS}; // command IDs
197  ccuty::stringset names; // command names
198  Commands() : names(STRINGIFY(BIBCOMMANDS)) {}
199  };
200  Commands commands_;
201 #undef BIBCOMMANDS
202 };
203 
204 #endif