]> git.lyx.org Git - lyx.git/blob - src/BiblioInfo.h
525cab50fdec27b0c290d1929d5622d18758d149
[lyx.git] / src / BiblioInfo.h
1 // -*- C++ -*-
2 /**
3  * \file BiblioInfo.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  * \author Herbert Voß
9  * \author Richard Heck
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef BIBLIO_H
15 #define BIBLIO_H
16
17 #include "support/docstring.h"
18
19 #include <vector>
20 #include <map>
21 #include <set>
22
23
24 namespace lyx {
25         
26 class Buffer;
27
28 namespace biblio {
29
30 enum CiteEngine {
31         ENGINE_BASIC,
32         ENGINE_NATBIB_AUTHORYEAR,
33         ENGINE_NATBIB_NUMERICAL,
34         ENGINE_JURABIB
35 };
36
37 enum CiteStyle {
38         CITE,
39         NOCITE,
40         CITET,
41         CITEP,
42         CITEALT,
43         CITEALP,
44         CITEAUTHOR,
45         CITEYEAR,
46         CITEYEARPAR
47 };
48
49
50 class CitationStyle {
51 public:
52         ///
53         CitationStyle(CiteStyle s = CITE, bool f = false, bool force = false)
54                 : style(s), full(f), forceUCase(force) {}
55         /// \param latex_str a LaTeX command, "cite", "Citep*", etc
56         CitationStyle(std::string const & latex_str);
57         ///
58         std::string const asLatexStr() const;
59         ///
60         CiteStyle style;
61         ///
62         bool full;
63         ///
64         bool forceUCase;
65 };
66
67 /// Returns a vector of available Citation styles.
68 std::vector<CiteStyle> const getCiteStyles(CiteEngine const );
69
70 } // namespace biblio
71
72 /// Class to represent information about a BibTeX or
73 /// bibliography entry.
74 /// The keys are BibTeX fields (e.g., author, title, etc), 
75 /// and the values are the associated field values.
76 class BibTeXInfo {
77 public:
78         ///
79         typedef std::map<docstring, docstring>::const_iterator const_iterator;
80         /// argument sets isBibTeX_, so should be false only if it's coming
81         /// from a bibliography environment
82         BibTeXInfo(bool ib = true);
83         /// constructor that sets the entryType
84         BibTeXInfo(docstring const & key, docstring const & type);
85         /// Search for the given field and return the associated info.
86         /// The point of this is that BibTeXInfo::operator[] has no const
87         /// form.
88         docstring const & getValueForField(docstring const & field) const;
89         ///
90         docstring const & getValueForField(std::string const & field) const;
91         ///
92         bool hasField(docstring const & field) const;
93         /// return the short form of an authorlist
94         docstring const getAbbreviatedAuthor() const;
95         /// 
96         docstring const getYear() const;
97         /// Returns formatted BibTeX data suitable for framing.
98         docstring const getInfo() const;
99         ///
100         int count(docstring const & f) const { return bimap_.count(f); }
101         ///
102         const_iterator find(docstring const & f) const { return bimap_.find(f); }
103         ///
104         const_iterator end() const { return bimap_.end(); }
105         ///
106         docstring & operator[](docstring const & f) 
107                 { return bimap_[f]; }
108         ///
109         docstring allData() const { return allData_; }
110         ///
111         void allData(docstring const & d) { allData_ = d; }
112         ///
113         docstring entryType() const { return entryType_; }
114 private:
115         /// the BibTeX key for this entry
116         docstring bibKey_;
117         /// a single string containing all BibTeX data associated with this key
118         docstring allData_;
119         /// the BibTeX entry type (article, book, incollection, ...)
120         docstring entryType_;
121         /// true if from BibTeX; false if from bibliography environment
122         bool isBibTeX_;
123         /// our map: <field, value>
124         std::map <docstring, docstring> bimap_;
125 };
126
127
128 /// Class to represent a collection of bibliographical data, whether
129 /// from BibTeX or from bibliography environments.
130 /// BiblioInfo.first is the bibliography key
131 /// BiblioInfo.second is the data for that key
132 class BiblioInfo : public std::map<docstring, BibTeXInfo> {
133 public:
134         /// Returns a sorted vector of bibliography keys
135         std::vector<docstring> const getKeys() const;
136         /// Returns a sorted vector of present BibTeX fields
137         std::vector<docstring> const getFields() const;
138         /// Returns a sorted vector of BibTeX entry types in use
139         std::vector<docstring> const getEntries() const;
140         /// Fills keys with BibTeX information derived from the various insets
141         /// in a given buffer, in its master document.
142         void fillWithBibKeys(Buffer const * const buf);
143         /// return the short form of an authorlist
144         docstring const getAbbreviatedAuthor(docstring const & key) const;
145         /// return the year from the bibtex data record
146         docstring const getYear(docstring const & key) const;
147         /// Returns formatted BibTeX data associated with a given key.
148         /// Empty if no info exists. 
149         docstring const getInfo(docstring const & key) const;
150         
151         /**
152           * "Translates the available Citation Styles into strings for a given key,
153           * either numerical or author-year depending upon the active engine. (See
154           * below for those methods.)
155           */
156         std::vector<docstring> const
157                         getCiteStrings(docstring const & key, Buffer const & buf) const;
158         /**
159                 * "Translates" the available Citation Styles into strings for a given key.
160                 * The returned string is displayed by the GUI.
161                 * [XX] is used in place of the actual reference
162                 * Eg, the vector will contain: [XX], Jones et al. [XX], ...
163                 * User supplies :
164                 *  the key,
165                 *  the buffer
166                 */
167         std::vector<docstring> const
168                         getNumericalStrings(docstring const & key, Buffer const & buf) const;
169         /**
170                 * "Translates" the available Citation Styles into strings for a given key.
171                 * The returned string is displayed by the GUI.
172                 * Eg, the vector will contain:
173                 *  Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
174                 * User supplies :
175                 *  the key,
176                 *  the buffer
177                 */
178         std::vector<docstring> const
179                         getAuthorYearStrings(docstring const & key, Buffer const & buf) const;
180
181         std::set<docstring> fieldNames;
182         std::set<docstring> entryTypes;
183 };
184
185 } // namespace lyx
186 #endif