* de.po: sync with branch.
[lyx.git] / src / BiblioInfo.h
blobe0f8f645887fc94ab62fd436f35e4fffeb500f1e
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.
7 * \author Angus Leeming
8 * \author Herbert Voß
9 * \author Richard Heck
11 * Full author contact details are available in file CREDITS.
14 #ifndef BIBLIOINFO_H
15 #define BIBLIOINFO_H
17 #include "support/docstring.h"
19 #include "Citation.h"
21 #include <vector>
22 #include <map>
23 #include <set>
26 namespace lyx {
28 class Buffer;
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
43 /// std::map.
44 class BibTeXInfo {
45 public:
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;
49 ///
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 ///
57 bool hasField(docstring const & field) const;
58 /// \return the short form of an authorlist
59 docstring const getAbbreviatedAuthor() const;
60 ///
61 docstring const getYear() const;
62 ///
63 docstring const getXRef() const;
64 /// \return formatted BibTeX data suitable for framing.
65 /// \param pointer to crossref information
66 docstring const & getInfo(BibTeXInfo const * const xref = 0) const;
67 ///
68 int count(docstring const & f) const { return bimap_.count(f); }
69 ///
70 const_iterator find(docstring const & f) const { return bimap_.find(f); }
71 ///
72 const_iterator end() const { return bimap_.end(); }
73 /// \return value for field f
74 /// note that this will create an empty field if it does not exist
75 docstring & operator[](docstring const & f)
76 { return bimap_[f]; }
77 /// \return value for field f
78 /// this one, since it is const, will simply return docstring() if
79 /// we don't have the field and will NOT create an empty field
80 docstring const & operator[](docstring const & field) const;
81 ///
82 docstring const & operator[](std::string const & field) const;
83 ///
84 docstring const & allData() const { return all_data_; }
85 ///
86 void setAllData(docstring const & d) { all_data_ = d; }
87 ///
88 void label(docstring const & d) { label_= d; }
89 ///
90 docstring const & label() const { return label_; }
91 ///
92 docstring const & key() const { return bib_key_; }
93 ///
94 docstring entryType() const { return entry_type_; }
95 private:
96 /// like operator[], except, if the field is empty, it will attempt
97 /// to get the data from xref BibTeXInfo object, which would normally
98 /// be the one referenced in the crossref field.
99 docstring getValueForKey(std::string const & key,
100 BibTeXInfo const * const xref = 0) const;
101 /// true if from BibTeX; false if from bibliography environment
102 bool is_bibtex_;
103 /// the BibTeX key for this entry
104 docstring bib_key_;
105 /// the label that will appear in citations
106 /// this is easily set from bibliography environments, but has
107 /// to be calculated for entries we get from BibTeX
108 docstring label_;
109 /// a single string containing all BibTeX data associated with this key
110 docstring all_data_;
111 /// the BibTeX entry type (article, book, incollection, ...)
112 docstring entry_type_;
113 /// a cache for getInfo()
114 mutable docstring info_;
115 /// our map: <field, value>
116 std::map <docstring, docstring> bimap_;
120 /// Class to represent a collection of bibliographical data, whether
121 /// from BibTeX or from bibliography environments.
122 class BiblioInfo {
123 public:
124 /// bibliography key --> data for that key
125 typedef std::map<docstring, BibTeXInfo>::const_iterator const_iterator;
126 /// \return a sorted vector of bibliography keys
127 std::vector<docstring> const getKeys() const;
128 /// \return a sorted vector of present BibTeX fields
129 std::vector<docstring> const getFields() const;
130 /// \return a sorted vector of BibTeX entry types in use
131 std::vector<docstring> const getEntries() const;
132 /// \return the short form of an authorlist
133 docstring const getAbbreviatedAuthor(docstring const & key) const;
134 /// \return the year from the bibtex data record
135 /// Note that this will get the year from the crossref if it's
136 /// not present in the record itself
137 docstring const getYear(docstring const & key) const;
138 /// \return formatted BibTeX data associated with a given key.
139 /// Empty if no info exists.
140 /// Note that this will retrieve data from the crossref as needed.
141 docstring const getInfo(docstring const & key) const;
143 * "Translates" the available Citation Styles into strings for a given key,
144 * either numerical or author-year depending upon the active engine. (See
145 * below for those methods.)
147 std::vector<docstring> const
148 getCiteStrings(docstring const & key, Buffer const & buf) const;
150 * "Translates" the available Citation Styles into strings for a given key.
151 * The returned string is displayed by the GUI.
152 * [XX] is used in place of the actual reference
153 * Eg, the vector will contain: [XX], Jones et al. [XX], ...
154 * User supplies :
155 * the key,
156 * the buffer
158 std::vector<docstring> const
159 getNumericalStrings(docstring const & key, Buffer const & buf) const;
161 * "Translates" the available Citation Styles into strings for a given key.
162 * The returned string is displayed by the GUI.
163 * Eg, the vector will contain:
164 * Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
165 * User supplies :
166 * the key,
167 * the buffer
169 std::vector<docstring> const
170 getAuthorYearStrings(docstring const & key, Buffer const & buf) const;
172 const_iterator begin() const { return bimap_.begin(); }
174 void clear() { bimap_.clear(); }
176 bool empty() const { return bimap_.empty(); }
178 const_iterator end() const { return bimap_.end(); }
180 const_iterator find(docstring const & f) const { return bimap_.find(f); }
182 void mergeBiblioInfo(BiblioInfo const & info);
184 BibTeXInfo & operator[](docstring const & f) { return bimap_[f]; }
186 void addFieldName(docstring const & f) { field_names_.insert(f); }
188 void addEntryType(docstring const & f) { entry_types_.insert(f); }
189 private:
191 std::set<docstring> field_names_;
193 std::set<docstring> entry_types_;
194 /// our map: keys --> BibTeXInfo
195 std::map<docstring, BibTeXInfo> bimap_;
198 } // namespace lyx
200 #endif // BIBLIOINFO_H