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