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