4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
17 #include "support/docstring.h"
30 /// FIXME: To Citation.cpp?
31 /// Returns a vector of available Citation styles.
32 std::vector<CiteStyle> citeStyles(CiteEngine);
33 /// \param latex_str a LaTeX command, "cite", "Citep*", etc
34 CitationStyle citationStyleFromString(std::string const & latex_str);
35 /// the other way round
36 std::string citationStyleToString(CitationStyle const &);
39 /// Class to represent information about a BibTeX or
40 /// bibliography entry.
41 /// This class basically wraps a std::map, and many of its
42 /// methods simply delegate to the corresponding methods of
46 /// The keys are BibTeX fields (e.g., author, title, etc),
47 /// and the values are the associated field values.
48 typedef std::map<docstring, docstring>::const_iterator const_iterator;
50 BibTeXInfo() : is_bibtex_(true) {}
51 /// argument sets isBibTeX_, so should be false only if it's coming
52 /// from a bibliography environment
53 BibTeXInfo(bool ib) : is_bibtex_(ib) {}
54 /// constructor that sets the entryType
55 BibTeXInfo(docstring const & key, docstring const & type);
56 /// \return the short form of an authorlist
57 docstring const getAbbreviatedAuthor() const;
59 docstring const getYear() const;
61 docstring const getXRef() const;
62 /// \return formatted BibTeX data suitable for framing.
63 /// \param pointer to crossref information
64 docstring const & getInfo(BibTeXInfo const * const xref = 0) const;
66 const_iterator find(docstring const & f) const { return bimap_.find(f); }
68 const_iterator end() const { return bimap_.end(); }
69 /// \return value for field f
70 /// note that this will create an empty field if it does not exist
71 docstring & operator[](docstring const & f)
73 /// \return value for field f
74 /// this one, since it is const, will simply return docstring() if
75 /// we don't have the field and will NOT create an empty field
76 docstring const & operator[](docstring const & field) const;
78 docstring const & operator[](std::string const & field) const;
80 docstring const & allData() const { return all_data_; }
82 void setAllData(docstring const & d) { all_data_ = d; }
84 void label(docstring const & d) { label_= d; }
86 docstring const & label() const { return label_; }
88 docstring const & key() const { return bib_key_; }
89 /// numerical key for citing this entry. currently used only
90 /// by XHTML output routines.
91 docstring citeNumber() const { return cite_number_; }
93 void setCiteNumber(docstring const & num) { cite_number_ = num; }
94 /// a,b,c, etc, for author-year. currently used only by XHTML
96 char modifier() const { return modifier_; }
98 void setModifier(char c) { modifier_ = c; }
100 docstring entryType() const { return entry_type_; }
102 bool isBibTeX() const { return is_bibtex_; }
104 /// like operator[], except, if the field is empty, it will attempt
105 /// to get the data from xref BibTeXInfo object, which would normally
106 /// be the one referenced in the crossref field.
107 docstring getValueForKey(std::string const & key,
108 BibTeXInfo const * const xref = 0) const;
109 /// true if from BibTeX; false if from bibliography environment
111 /// the BibTeX key for this entry
113 /// the label that will appear in citations
114 /// this is easily set from bibliography environments, but has
115 /// to be calculated for entries we get from BibTeX
117 /// a single string containing all BibTeX data associated with this key
119 /// the BibTeX entry type (article, book, incollection, ...)
120 docstring entry_type_;
121 /// a cache for getInfo()
122 mutable docstring info_;
124 docstring cite_number_;
127 /// our map: <field, value>
128 std::map <docstring, docstring> bimap_;
132 /// Class to represent a collection of bibliographical data, whether
133 /// from BibTeX or from bibliography environments.
136 /// bibliography key --> data for that key
137 typedef std::map<docstring, BibTeXInfo>::const_iterator const_iterator;
138 /// \return a sorted vector of bibliography keys
139 std::vector<docstring> const getKeys() const;
140 /// \return a sorted vector of present BibTeX fields
141 std::vector<docstring> const getFields() const;
142 /// \return a sorted vector of BibTeX entry types in use
143 std::vector<docstring> const getEntries() const;
144 /// \return the short form of an authorlist
145 docstring const getAbbreviatedAuthor(docstring const & key) const;
146 /// \return the year from the bibtex data record for \param key
147 /// if \param use_modifier is true, then we will also append any
148 /// modifier for this entry (e.g., 1998b).
149 /// Note that this will get the year from the crossref if it's
150 /// not present in the record itself.
151 docstring const getYear(docstring const & key,
152 bool use_modifier = false) const;
154 docstring const getCiteNumber(docstring const & key) const;
155 /// \return formatted BibTeX data associated with a given key.
156 /// Empty if no info exists.
157 /// Note that this will retrieve data from the crossref as needed.
158 docstring const getInfo(docstring const & key) const;
159 /// Is this a reference from a bibtex database
160 /// or from a bibliography environment?
161 bool isBibtex(docstring const & key) const;
163 * "Translates" the available Citation Styles into strings for a given key,
164 * either numerical or author-year depending upon the active engine. (See
165 * below for those methods.)
167 std::vector<docstring> const
168 getCiteStrings(docstring const & key, Buffer const & buf) const;
170 * "Translates" the available Citation Styles into strings for a given key.
171 * The returned string is displayed by the GUI.
172 * [XX] is used in place of the actual reference
173 * Eg, the vector will contain: [XX], Jones et al. [XX], ...
178 std::vector<docstring> const
179 getNumericalStrings(docstring const & key, Buffer const & buf) const;
181 * "Translates" the available Citation Styles into strings for a given key.
182 * The returned string is displayed by the GUI.
183 * Eg, the vector will contain:
184 * Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
189 std::vector<docstring> const
190 getAuthorYearStrings(docstring const & key, Buffer const & buf) const;
191 /// Collects the cited entries from buf.
192 void collectCitedEntries(Buffer const & buf);
193 /// A list of BibTeX keys cited in the current document, sorted by
194 /// the last name of the author.
195 /// Make sure you have called collectCitedEntries() before you try to
196 /// use this. You should probably call it just before you use this.
197 std::vector<docstring> const & citedEntries() const
198 { return cited_entries_; }
200 void makeCitationLabels(Buffer const & buf);
202 const_iterator begin() const { return bimap_.begin(); }
204 void clear() { bimap_.clear(); }
206 bool empty() const { return bimap_.empty(); }
208 const_iterator end() const { return bimap_.end(); }
210 const_iterator find(docstring const & f) const { return bimap_.find(f); }
212 void mergeBiblioInfo(BiblioInfo const & info);
214 BibTeXInfo & operator[](docstring const & f) { return bimap_[f]; }
216 void addFieldName(docstring const & f) { field_names_.insert(f); }
218 void addEntryType(docstring const & f) { entry_types_.insert(f); }
221 std::set<docstring> field_names_;
223 std::set<docstring> entry_types_;
224 /// our map: keys --> BibTeXInfo
225 std::map<docstring, BibTeXInfo> bimap_;
226 /// a possibly sorted list of entries cited in our Buffer.
227 /// do not try to make this a vector<BibTeXInfo *> or anything of
228 /// the sort, because reloads will invalidate those pointers.
229 std::vector<docstring> cited_entries_;
234 #endif // BIBLIOINFO_H