]> git.lyx.org Git - features.git/blob - src/CiteEnginesList.h
Rework default bibliography style UI
[features.git] / src / CiteEnginesList.h
1 // -*- C++ -*-
2 /**
3  * \file CiteEnginesList.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Richard Heck
8  * \author Jürgen Spitzmüller
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef CITEENGINESLIST_H
14 #define CITEENGINESLIST_H
15
16 #include "Citation.h"
17
18 #include <string>
19 #include <vector>
20
21 namespace lyx {
22
23 /**
24  *  This class represents a particular LyX "cite engine", which defines the features
25  * of a particular citation backend such as natbib or biblatex. In that sense, it is more like
26  *  a LaTeX package, where a layout file corresponds to a LaTeX class.
27  *
28  *  In general, a given cite engine can be used with any document class. That said,
29  *  one cite engine may `require' another, or it may `exclude' some other cite engine.
30  *  The requires and excludes are given in comments within the cite engine file,
31  *  which must begin roughly so:
32  *  # \DeclareLyXCiteEngine[natbib.sty]{Natbib}
33  *  # DescriptionBegin
34  *  #   Natbib supports a range of both author-year and numerical styles mainly
35  *  #   aimed at the Humanities. It features automatic sorting and merging of
36  *  #   numerical citations, annotations, capitalization of the `van' part of
37  *  #   author names, shortened and full author lists, and more.
38  *  # DescriptionEnd
39  *  # Excludes: basic | jurabib
40  *  The description will be used in the gui to give information to the user. The
41  *  Requires and Excludes lines are read by the configuration script
42  *  and written to a file citeengines.lst in the user configuration directory.
43  *  That file is then read on startup to populate the CiteEnginesList, below.
44  *
45  *  Engines can also be "provided" or "excluded" by document classes, using
46  *  the ProvidesEngine and ExcludesEngine tags.
47  */
48
49 class LyXCiteEngine {
50 public:
51         ///
52         LyXCiteEngine(std::string const & name, std::string const & id,
53                       std::vector<std::string> const & enginetypes,
54                       std::vector<std::string> const & defaultbiblios,
55                       std::string const & description,
56                       std::vector<std::string> const & packagelist,
57                       std::vector<std::string> const & requires,
58                       std::vector<std::string> const & excludes);
59         /// whether the required packages are available
60         bool isAvailable() const;
61         /// the missing prerequisites, if any
62         std::vector<std::string> prerequisites() const;
63         ///
64         std::string const & getName() const { return name_; }
65         ///
66         std::string const & getID() const { return id_; }
67         ///
68         std::string const & getFilename() const { return filename_; }
69         ///
70         std::vector<std::string> const & getEngineType() const { return engine_types_; }
71         ///
72         bool hasEngineType(CiteEngineType const &) const;
73         ///
74         std::string getDefaultBiblio(CiteEngineType const &) const;
75         ///
76         bool isDefaultBiblio(std::string const &) const;
77         ///
78         std::string const & getDescription() const { return description_; }
79         ///
80         std::vector<std::string> const & getPackageList() const
81                 { return package_list_; }
82         ///
83         std::vector<std::string> const & getRequiredEngines() const
84                 { return required_engines_; }
85         /// Engines this one excludes: the list should be treated disjunctively
86         std::vector<std::string> const & getExcludedEngines() const
87                 { return excluded_engines_; }
88         /// \return true if the engine is compatible with this one, i.e.,
89         /// it does not exclude us and we do not exclude it.
90         /// this will also return true if cename is unknown and we do not
91         /// exclude it, since in that case we cannot check its exclusions.
92         bool isCompatible(std::string const & cename) const;
93         ///
94         static bool areCompatible(std::string const & eng1, std::string const & eng2);
95 private:
96         /// what appears in the ui
97         std::string name_;
98         /// the engine's unique identifier
99         /// at present, this is the filename, without the extension
100         std::string id_;
101         /// the filename
102         std::string filename_;
103         /// the engine type(s)
104         std::vector<std::string> engine_types_;
105         /// default bibliography styles
106         std::vector<std::string> default_biblios_;
107         /// a short description for use in the ui
108         std::string description_;
109         /// the LaTeX packages on which this depends, if any
110         std::vector<std::string> package_list_;
111         /// Engines this one requires: at least one
112         std::vector<std::string> required_engines_;
113         /// Engines this one excludes: none of these
114         std::vector<std::string> excluded_engines_;
115         // these are mutable because they are used to cache the results
116         // or an otherwise const operation.
117         ///
118         mutable bool checked_;
119         ///
120         mutable bool available_;
121         ///
122         mutable std::vector<std::string> prerequisites_;
123 };
124
125 typedef std::vector<LyXCiteEngine> LyXCiteEnginesList;
126
127 /**
128  *  The CiteEnginesList represents the various LyXCiteEngine's that are available at
129  *  present.
130  */
131 class CiteEnginesList {
132 public:
133         ///
134         CiteEnginesList() {}
135         ///
136         std::string getTypeAsString(CiteEngineType const &) const;
137         ///
138         CiteEngineType getType(std::string const &) const;
139         /// reads the engines from a file generated by configure.py
140         bool read();
141         ///
142         LyXCiteEnginesList::const_iterator begin() const;
143         ///
144         LyXCiteEnginesList::iterator begin();
145         ///
146         LyXCiteEnginesList::const_iterator end() const;
147         ///
148         LyXCiteEnginesList::iterator end();
149         ///
150         bool empty() const { return englist_.empty(); }
151         /// Returns a pointer to the LyXCiteEngine with filename str.
152         /// Returns a null pointer if no such engine is found.
153         LyXCiteEngine const * operator[](std::string const & str) const;
154         ///
155         LyXCiteEngine * operator[](std::string const & str);
156         private:
157         /// noncopyable
158         CiteEnginesList(CiteEnginesList const &);
159         ///
160         void operator=(CiteEnginesList const &);
161         /// add an engine to the list
162         void addCiteEngine(std::string const &, std::string const &,
163                 std::vector<std::string> const &, std::vector<std::string> const &,
164                 std::string const &, std::vector<std::string> const &,
165                 std::vector<std::string> const &, std::vector<std::string> const &);
166         ///
167         std::vector<LyXCiteEngine> englist_;
168 };
169
170 extern CiteEnginesList theCiteEnginesList;
171 }
172 #endif