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