]> git.lyx.org Git - lyx.git/blob - src/BiblioInfo.h
12e5754436925371ec653d76cef9e1407755f682
[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 rounf
36 std::string citationStyleToString(CitationStyle const &);
37
38
39 /// Class to represent information about a BibTeX or
40 /// bibliography entry.
41 /// The keys are BibTeX fields (e.g., author, title, etc), 
42 /// and the values are the associated field values.
43 class BibTeXInfo {
44 public:
45         ///
46         typedef std::map<docstring, docstring>::const_iterator const_iterator;
47         ///
48         BibTeXInfo() : is_bibtex_(true) {}
49         /// argument sets isBibTeX_, so should be false only if it's coming
50         /// from a bibliography environment
51         BibTeXInfo(bool ib) : is_bibtex_(ib) {}
52         /// constructor that sets the entryType
53         BibTeXInfo(docstring const & key, docstring const & type);
54         /// Search for the given field and return the associated info.
55         /// The point of this is that BibTeXInfo::operator[] has no const
56         /// form.
57         docstring const & getValueForField(docstring const & field) const;
58         ///
59         docstring const & getValueForField(std::string const & field) const;
60         ///
61         bool hasField(docstring const & field) const;
62         /// return the short form of an authorlist
63         docstring const getAbbreviatedAuthor() const;
64         /// 
65         docstring const getYear() const;
66         /// Returns formatted BibTeX data suitable for framing.
67         docstring const getInfo() const;
68         ///
69         int count(docstring const & f) const { return bimap_.count(f); }
70         ///
71         const_iterator find(docstring const & f) const { return bimap_.find(f); }
72         ///
73         const_iterator end() const { return bimap_.end(); }
74         ///
75         docstring & operator[](docstring const & f) 
76                 { return bimap_[f]; }
77         ///
78         docstring const & allData() const { return all_data_; }
79         ///
80         void setAllData(docstring const & d) { all_data_ = d; }
81         ///
82         docstring entryType() const { return entry_type_; }
83 private:
84         /// true if from BibTeX; false if from bibliography environment
85         bool is_bibtex_;
86         /// the BibTeX key for this entry
87         docstring bib_key_;
88         /// a single string containing all BibTeX data associated with this key
89         docstring all_data_;
90         /// the BibTeX entry type (article, book, incollection, ...)
91         docstring entry_type_;
92         /// our map: <field, value>
93         std::map <docstring, docstring> bimap_;
94 };
95
96
97 /// Class to represent a collection of bibliographical data, whether
98 /// from BibTeX or from bibliography environments.
99 class BiblioInfo {
100 public:
101         /// bibliography key --> data for that key
102         typedef std::map<docstring, BibTeXInfo>::const_iterator const_iterator;
103         /// Returns a sorted vector of bibliography keys
104         std::vector<docstring> const getKeys() const;
105         /// Returns a sorted vector of present BibTeX fields
106         std::vector<docstring> const getFields() const;
107         /// Returns a sorted vector of BibTeX entry types in use
108         std::vector<docstring> const getEntries() const;
109         /// return the short form of an authorlist
110         docstring const getAbbreviatedAuthor(docstring const & key) const;
111         /// return the year from the bibtex data record
112         docstring const getYear(docstring const & key) const;
113         /// Returns formatted BibTeX data associated with a given key.
114         /// Empty if no info exists. 
115         docstring const getInfo(docstring const & key) const;
116         
117         /**
118           * "Translates" the available Citation Styles into strings for a given key,
119           * either numerical or author-year depending upon the active engine. (See
120           * below for those methods.)
121           */
122         std::vector<docstring> const
123                         getCiteStrings(docstring const & key, Buffer const & buf) const;
124         /**
125                 * "Translates" the available Citation Styles into strings for a given key.
126                 * The returned string is displayed by the GUI.
127                 * [XX] is used in place of the actual reference
128                 * Eg, the vector will contain: [XX], Jones et al. [XX], ...
129                 * User supplies :
130                 *  the key,
131                 *  the buffer
132                 */
133         std::vector<docstring> const
134                         getNumericalStrings(docstring const & key, Buffer const & buf) const;
135         /**
136                 * "Translates" the available Citation Styles into strings for a given key.
137                 * The returned string is displayed by the GUI.
138                 * Eg, the vector will contain:
139                 *  Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
140                 * User supplies :
141                 *  the key,
142                 *  the buffer
143                 */
144         std::vector<docstring> const
145                         getAuthorYearStrings(docstring const & key, Buffer const & buf) const;
146         ///
147         const_iterator begin() const { return bimap_.begin(); }
148         ///
149         void clear() { bimap_.clear(); }
150         ///
151         bool empty() const { return bimap_.empty(); }
152         ///
153         const_iterator end() const { return bimap_.end(); }
154         ///
155         const_iterator find(docstring const & f) const { return bimap_.find(f); }
156         ///
157         void mergeBiblioInfo(BiblioInfo const & info);
158         ///
159         BibTeXInfo & operator[](docstring const & f) { return bimap_[f]; }
160         ///
161         void addFieldName(docstring const & f) { field_names_.insert(f); }
162         ///
163         void addEntryType(docstring const & f) { entry_types_.insert(f); }
164 private:
165         ///
166         std::set<docstring> field_names_;
167         ///
168         std::set<docstring> entry_types_;
169         /// our map: keys --> BibTeXInfo
170         std::map<docstring, BibTeXInfo> bimap_;
171 };
172
173 } // namespace lyx
174
175 #endif // BIBLIOINFO_H