From: Richard Heck Date: Thu, 14 Feb 2008 05:00:54 +0000 (+0000) Subject: Do not inherit from std::map. X-Git-Tag: 1.6.10~6276 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=485478e47c94665df7872148e04a3a94db68c8ce;p=features.git Do not inherit from std::map. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22993 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index 9f00a3753d..1f76e55af3 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -42,8 +42,13 @@ namespace lyx { // ////////////////////////////////////////////////////////////////////// -BibTeXInfo::BibTeXInfo() - : isBibTeX(true) +BibTeXInfo::BibTeXInfo(bool ib) + : isBibTeX_(ib) +{} + + +BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type) + : isBibTeX_(true), bibKey_(key), entryType_(type) {} @@ -97,7 +102,7 @@ static docstring familyName(docstring const & name) docstring const BibTeXInfo::getAbbreviatedAuthor() const { - if (!isBibTeX) + if (!isBibTeX_) return docstring(); docstring author = getValueForField("author"); @@ -105,7 +110,7 @@ docstring const BibTeXInfo::getAbbreviatedAuthor() const if (author.empty()) { author = getValueForField("editor"); if (author.empty()) - return bibKey; + return bibKey_; } // OK, we've got some names. Let's format them. @@ -126,7 +131,7 @@ docstring const BibTeXInfo::getAbbreviatedAuthor() const docstring const BibTeXInfo::getYear() const { - if (!isBibTeX) + if (!isBibTeX_) return docstring(); docstring year = getValueForField("year"); @@ -138,7 +143,7 @@ docstring const BibTeXInfo::getYear() const docstring const BibTeXInfo::getInfo() const { - if (!isBibTeX) { + if (!isBibTeX_) { BibTeXInfo::const_iterator it = find(from_ascii("ref")); return it->second; } diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h index 7f57a31c6b..525cab50fd 100644 --- a/src/BiblioInfo.h +++ b/src/BiblioInfo.h @@ -73,13 +73,18 @@ std::vector const getCiteStyles(CiteEngine const ); /// bibliography entry. /// The keys are BibTeX fields (e.g., author, title, etc), /// and the values are the associated field values. -class BibTeXInfo : public std::map { +class BibTeXInfo { public: /// - BibTeXInfo(); - ///Search for the given field and return the associated info. - ///The point of this is that BibTeXInfo::operator[] has no const - ///form. + typedef std::map::const_iterator const_iterator; + /// argument sets isBibTeX_, so should be false only if it's coming + /// from a bibliography environment + BibTeXInfo(bool ib = true); + /// constructor that sets the entryType + BibTeXInfo(docstring const & key, docstring const & type); + /// Search for the given field and return the associated info. + /// The point of this is that BibTeXInfo::operator[] has no const + /// form. docstring const & getValueForField(docstring const & field) const; /// docstring const & getValueForField(std::string const & field) const; @@ -91,14 +96,32 @@ public: docstring const getYear() const; /// Returns formatted BibTeX data suitable for framing. docstring const getInfo() const; + /// + int count(docstring const & f) const { return bimap_.count(f); } + /// + const_iterator find(docstring const & f) const { return bimap_.find(f); } + /// + const_iterator end() const { return bimap_.end(); } + /// + docstring & operator[](docstring const & f) + { return bimap_[f]; } + /// + docstring allData() const { return allData_; } + /// + void allData(docstring const & d) { allData_ = d; } + /// + docstring entryType() const { return entryType_; } +private: /// the BibTeX key for this entry - docstring bibKey; + docstring bibKey_; /// a single string containing all BibTeX data associated with this key - docstring allData; + docstring allData_; /// the BibTeX entry type (article, book, incollection, ...) - docstring entryType; + docstring entryType_; /// true if from BibTeX; false if from bibliography environment - bool isBibTeX; + bool isBibTeX_; + /// our map: + std::map bimap_; }; diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index d9b8a4f8f0..1c6499586f 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -641,7 +641,7 @@ void GuiCitation::filterByEntryType( BiblioInfo::const_iterator cit = bibkeysInfo_.find(key); if (cit == bibkeysInfo_.end()) continue; - if (cit->second.entryType == entryType) + if (cit->second.entryType() == entryType) result.push_back(key); } keyVector = result; @@ -725,7 +725,7 @@ vector GuiCitation::searchKeys( if (only_keys) data = to_utf8(*it); else if (field.empty()) - data = to_utf8(*it) + ' ' + to_utf8(kvm.allData); + data = to_utf8(*it) + ' ' + to_utf8(kvm.allData()); else if (kvm.hasField(field)) data = to_utf8(kvm.getValueForField(field)); diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index db5bc53e4e..3a6f083cb0 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -198,12 +198,11 @@ void InsetBibitem::fillWithBibKeys(Buffer const & buf, BiblioInfo & keys, InsetIterator const & it) const { docstring const key = getParam("key"); - BibTeXInfo keyvalmap; + BibTeXInfo keyvalmap(false); keyvalmap[from_ascii("label")] = getParam("label"); DocIterator doc_it(it); doc_it.forwardPos(); keyvalmap[from_ascii("ref")] = doc_it.paragraph().asString(buf, false); - keyvalmap.isBibTeX = false; keys[key] = keyvalmap; } diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index e80e839691..7d017204ce 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -740,8 +740,7 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer, docstring value; docstring commaNewline; docstring data; - BibTeXInfo keyvalmap; - keyvalmap.entryType = entryType; + BibTeXInfo keyvalmap(key, entryType); bool readNext = removeWSAndComma(ifs); @@ -773,9 +772,7 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer, // add the new entry keylist.entryTypes.insert(entryType); - keyvalmap.allData = data; - keyvalmap.isBibTeX = true; - keyvalmap.bibKey = key; + keyvalmap.allData(data); keylist[key] = keyvalmap; } } //< searching '@'