]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/biblio.h
Convert most of the bibtex machinery to docstring.
[lyx.git] / src / frontends / controllers / biblio.h
1 // -*- C++ -*-
2 /**
3  * \file biblio.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef BIBLIOHELPERS_H
13 #define BIBLIOHELPERS_H
14
15 #include "support/docstring.h"
16
17 #include <map>
18 #include <vector>
19
20 class Buffer;
21
22 /** Functions of use to citation and bibtex GUI controllers and views */
23 namespace lyx {
24 namespace biblio {
25
26 class CiteEngine_enum;
27
28 CiteEngine_enum getEngine(Buffer const &);
29
30
31 enum CiteStyle {
32         CITE,
33         CITET,
34         CITEP,
35         CITEALT,
36         CITEALP,
37         CITEAUTHOR,
38         CITEYEAR,
39         CITEYEARPAR
40 };
41
42
43 enum Search {
44         SIMPLE,
45         REGEX
46 };
47
48
49 enum Direction {
50         FORWARD,
51         BACKWARD
52 };
53
54
55 /** Each citation engine recognizes only a subset of all possible
56  *  citation commands. Given a latex command \c input, this function
57  *  returns an appropriate command, valid for \c engine.
58  */
59 std::string const asValidLatexCommand(std::string const & input,
60                                       CiteEngine_enum const & engine);
61
62 /// First entry is the bibliography key, second the data
63 typedef std::map<std::string, docstring> InfoMap;
64
65 /// Returns a vector of bibliography keys
66 std::vector<std::string> const getKeys(InfoMap const &);
67
68 /** Returns the BibTeX data associated with a given key.
69     Empty if no info exists. */
70 docstring const getInfo(InfoMap const &, std::string const & key);
71
72 /// return the year from the bibtex data record
73 docstring const getYear(InfoMap const & map, std::string const & key);
74
75 /// return the short form of an authorlist
76 docstring const getAbbreviatedAuthor(InfoMap const & map, std::string const & key);
77
78 // return only the family name
79 docstring const familyName(docstring const & name);
80
81 /** Search a BibTeX info field for the given key and return the
82     associated field. */
83 docstring const parseBibTeX(docstring data, std::string const & findkey);
84
85 /** Returns an iterator to the first key that meets the search
86     criterion, or end() if unsuccessful.
87
88     User supplies :
89     the InfoMap of bibkeys info,
90     the vector of keys to be searched,
91     the search criterion,
92     an iterator defining the starting point of the search,
93     an enum defining a Simple or Regex search,
94     an enum defining the search direction.
95 */
96
97 std::vector<std::string>::const_iterator
98 searchKeys(InfoMap const & map,
99            std::vector<std::string> const & keys_to_search,
100            docstring const & search_expression,
101            std::vector<std::string>::const_iterator start,
102            Search,
103            Direction,
104            bool caseSensitive=false);
105
106
107 class CitationStyle {
108 public:
109         ///
110         CitationStyle(CiteStyle s = CITE, bool f = false, bool force = false)
111                 : style(s), full(f), forceUCase(force) {}
112         /// \param latex_str a LaTeX command, "cite", "Citep*", etc
113         CitationStyle(std::string const & latex_str);
114         ///
115         std::string const asLatexStr() const;
116         ///
117         CiteStyle style;
118         ///
119         bool full;
120         ///
121         bool forceUCase;
122 };
123
124
125 /// Returns a vector of available Citation styles.
126 std::vector<CiteStyle> const getCiteStyles(CiteEngine_enum const &);
127
128 /**
129    "Translates" the available Citation Styles into strings for this key.
130    The returned string is displayed by the GUI.
131
132
133    [XX] is used in place of the actual reference
134    Eg, the vector will contain: [XX], Jones et al. [XX], ...
135
136    User supplies :
137    the key,
138    the InfoMap of bibkeys info,
139    the available citation styles
140 */
141 std::vector<docstring> const
142 getNumericalStrings(std::string const & key,
143                     InfoMap const & map,
144                     std::vector<CiteStyle> const & styles);
145
146 /**
147    "Translates" the available Citation Styles into strings for this key.
148    The returned string is displayed by the GUI.
149
150    Eg, the vector will contain:
151    Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
152
153    User supplies :
154    the key,
155    the InfoMap of bibkeys info,
156    the available citation styles
157 */
158 std::vector<docstring> const
159 getAuthorYearStrings(std::string const & key,
160                      InfoMap const & map,
161                      std::vector<CiteStyle> const & styles);
162
163 } // namespace biblio
164 } // namespace lyx
165
166 #endif // BIBLIOHELPERS_H