]> git.lyx.org Git - lyx.git/blob - src/BiblioInfo.h
b311a36a6cd147c7da675c2431773cb13d154c9c
[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 BIBLIOINFO_H
15 #define BIBLIOINFO_H
16
17 #include "support/docstring.h"
18
19 #include "Citation.h"
20
21 #include <vector>
22 #include <map>
23 #include <set>
24
25
26 namespace lyx {
27         
28 class Buffer;
29
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 &);
37
38
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         docstring entryType() const { return entry_type_; }
89 private:
90         /// like operator[], except it will also check the given xref
91         docstring getValueForKey(std::string const & key, 
92                         BibTeXInfo const * const xref = 0) const;
93         /// true if from BibTeX; false if from bibliography environment
94         bool is_bibtex_;
95         /// the BibTeX key for this entry
96         docstring bib_key_;
97         /// a single string containing all BibTeX data associated with this key
98         docstring all_data_;
99         /// the BibTeX entry type (article, book, incollection, ...)
100         docstring entry_type_;
101         /// a cache for getInfo()
102         mutable docstring info_;
103         /// our map: <field, value>
104         std::map <docstring, docstring> bimap_;
105 };
106
107
108 /// Class to represent a collection of bibliographical data, whether
109 /// from BibTeX or from bibliography environments.
110 class BiblioInfo {
111 public:
112         /// bibliography key --> data for that key
113         typedef std::map<docstring, BibTeXInfo>::const_iterator const_iterator;
114         /// \return a sorted vector of bibliography keys
115         std::vector<docstring> const getKeys() const;
116         /// \return a sorted vector of present BibTeX fields
117         std::vector<docstring> const getFields() const;
118         /// \return a sorted vector of BibTeX entry types in use
119         std::vector<docstring> const getEntries() const;
120         /// \return the short form of an authorlist
121         docstring const getAbbreviatedAuthor(docstring const & key) const;
122         /// \return the year from the bibtex data record
123         /// Note that this will get the year from the crossref if it's
124         /// not present in the record itself
125         docstring const getYear(docstring const & key) const;
126         /// \return formatted BibTeX data associated with a given key.
127         /// Empty if no info exists. 
128         /// Note that this will retrieve data from the crossref as needed.
129         docstring const getInfo(docstring const & key) const;
130         /**
131           * "Translates" the available Citation Styles into strings for a given key,
132           * either numerical or author-year depending upon the active engine. (See
133           * below for those methods.)
134           */
135         std::vector<docstring> const
136                         getCiteStrings(docstring const & key, Buffer const & buf) const;
137         /**
138                 * "Translates" the available Citation Styles into strings for a given key.
139                 * The returned string is displayed by the GUI.
140                 * [XX] is used in place of the actual reference
141                 * Eg, the vector will contain: [XX], Jones et al. [XX], ...
142                 * User supplies :
143                 *  the key,
144                 *  the buffer
145                 */
146         std::vector<docstring> const
147                         getNumericalStrings(docstring const & key, Buffer const & buf) const;
148         /**
149                 * "Translates" the available Citation Styles into strings for a given key.
150                 * The returned string is displayed by the GUI.
151                 * Eg, the vector will contain:
152                 *  Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
153                 * User supplies :
154                 *  the key,
155                 *  the buffer
156                 */
157         std::vector<docstring> const
158                         getAuthorYearStrings(docstring const & key, Buffer const & buf) const;
159         ///
160         const_iterator begin() const { return bimap_.begin(); }
161         ///
162         void clear() { bimap_.clear(); }
163         ///
164         bool empty() const { return bimap_.empty(); }
165         ///
166         const_iterator end() const { return bimap_.end(); }
167         ///
168         const_iterator find(docstring const & f) const { return bimap_.find(f); }
169         ///
170         void mergeBiblioInfo(BiblioInfo const & info);
171         ///
172         BibTeXInfo & operator[](docstring const & f) { return bimap_[f]; }
173         ///
174         void addFieldName(docstring const & f) { field_names_.insert(f); }
175         ///
176         void addEntryType(docstring const & f) { entry_types_.insert(f); }
177 private:
178         ///
179         std::set<docstring> field_names_;
180         ///
181         std::set<docstring> entry_types_;
182         /// our map: keys --> BibTeXInfo
183         std::map<docstring, BibTeXInfo> bimap_;
184 };
185
186 } // namespace lyx
187
188 #endif // BIBLIOINFO_H