]> git.lyx.org Git - features.git/commitdiff
The comment preceding getValueForField() reflected an earlier implmentation.
authorRichard Heck <rgheck@comcast.net>
Wed, 19 Nov 2008 04:16:12 +0000 (04:16 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 19 Nov 2008 04:16:12 +0000 (04:16 +0000)
There is now no reason not to use operator[] here, which is more natural.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27635 a592a061-630c-0410-9148-cb99ea01b6c8

src/BiblioInfo.cpp
src/BiblioInfo.h
src/frontends/qt4/GuiCitation.cpp

index dfa24ab7915c4f2c873b67995f02cceea45c7db6..0756e33078d805a7e1281c539f4c4d6b09d6e317 100644 (file)
@@ -54,7 +54,7 @@ bool BibTeXInfo::hasField(docstring const & field) const
 }
 
 
-docstring const & BibTeXInfo::getValueForField(docstring const & field) const
+docstring const & BibTeXInfo::operator[](docstring const & field) const
 {
        BibTeXInfo::const_iterator it = find(field);
        if (it != end())
@@ -64,9 +64,9 @@ docstring const & BibTeXInfo::getValueForField(docstring const & field) const
 }
        
        
-docstring const & BibTeXInfo::getValueForField(string const & field) const
+docstring const & BibTeXInfo::operator[](string const & field) const
 {
-       return getValueForField(from_ascii(field));
+       return operator[](from_ascii(field));
 }
 
 
@@ -98,7 +98,7 @@ docstring familyName(docstring const & name)
 docstring const BibTeXInfo::getAbbreviatedAuthor() const
 {
        if (!is_bibtex_) {
-               docstring const opt = trim(getValueForField("label"));
+               docstring const opt = trim(operator[]("label"));
                if (opt.empty())
                        return docstring();
 
@@ -107,9 +107,9 @@ docstring const BibTeXInfo::getAbbreviatedAuthor() const
                return authors;
        }
 
-       docstring author = getValueForField("author");
+       docstring author = operator[]("author");
        if (author.empty()) {
-               author = getValueForField("editor");
+               author = operator[]("editor");
                if (author.empty())
                        return bib_key_;
        }
@@ -133,7 +133,7 @@ docstring const BibTeXInfo::getAbbreviatedAuthor() const
 docstring const BibTeXInfo::getYear() const
 {
        if (!is_bibtex_) {
-               docstring const opt = trim(getValueForField("label"));
+               docstring const opt = trim(operator[]("label"));
                if (opt.empty())
                        return docstring();
 
@@ -144,7 +144,7 @@ docstring const BibTeXInfo::getYear() const
                return year;
        }
 
-       docstring year = getValueForField("year");
+       docstring year = operator[]("year");
        if (year.empty())
                year = _("No year");
        return year;
@@ -163,31 +163,31 @@ docstring const BibTeXInfo::getInfo() const
        // field to customize the output based upon entry type.
        
        // Search for all possible "required" fields
-       docstring author = getValueForField("author");
+       docstring author = operator[]("author");
        if (author.empty())
-               author = getValueForField("editor");
+               author = operator[]("editor");
  
-       docstring year      = getValueForField("year");
-       docstring title     = getValueForField("title");
-       docstring docLoc    = getValueForField("pages");
+       docstring year   = operator[]("year");
+       docstring title  = operator[]("title");
+       docstring docLoc = operator[]("pages");
        if (docLoc.empty()) {
-               docLoc = getValueForField("chapter");
+               docLoc = operator[]("chapter");
                if (!docLoc.empty())
                        docLoc = from_ascii("Ch. ") + docLoc;
        }       else {
                docLoc = from_ascii("pp. ") + docLoc;
        }
 
-       docstring media = getValueForField("journal");
+       docstring media = operator[]("journal");
        if (media.empty()) {
-               media = getValueForField("publisher");
+               media = operator[]("publisher");
                if (media.empty()) {
-                       media = getValueForField("school");
+                       media = operator[]("school");
                        if (media.empty())
-                               media = getValueForField("institution");
+                               media = operator[]("institution");
                }
        }
-       docstring volume = getValueForField("volume");
+       docstring volume = operator[]("volume");
 
        odocstringstream result;
        if (!author.empty())
index ff6e88a783abba54f20622869f5b0dca9e100943..0baa06c5c2d97b57d7e5122a081282ac1d54d63b 100644 (file)
@@ -38,6 +38,9 @@ std::string citationStyleToString(CitationStyle const &);
 
 /// Class to represent information about a BibTeX or
 /// bibliography entry.
+/// This class basically wraps a std::map, and many of its
+/// methods simply delegate to the corresponding methods of
+/// std::map.
 class BibTeXInfo {
 public:
        /// The keys are BibTeX fields (e.g., author, title, etc), 
@@ -50,12 +53,6 @@ public:
        BibTeXInfo(bool ib) : is_bibtex_(ib) {}
        /// 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;
        ///
        bool hasField(docstring const & field) const;
        /// \return the short form of an authorlist
@@ -70,9 +67,16 @@ public:
        const_iterator find(docstring const & f) const { return bimap_.find(f); }
        ///
        const_iterator end() const { return bimap_.end(); }
-       ///
+       /// \return value for field f
+       /// note that this will create an empty field if it does not exist
        docstring & operator[](docstring const & f) 
                { return bimap_[f]; }
+       /// \return value for field f
+       /// this one, since it is const, will simply return docstring() if
+       /// we don't have the field and will NOT create an empty field
+       docstring const & operator[](docstring const & field) const;
+       ///
+       docstring const & operator[](std::string const & field) const;
        ///
        docstring const & allData() const { return all_data_; }
        ///
index 57e7cc6e98138930c063a7a93709cedd36b09bef..3c8c133c1040a3ce8319a19d5bf00c71b73e3708 100644 (file)
@@ -702,7 +702,7 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
                else if (field.empty())
                        data = to_utf8(*it) + ' ' + to_utf8(kvm.allData());
                else if (kvm.hasField(field))
-                       data = to_utf8(kvm.getValueForField(field));
+                       data = to_utf8(kvm[field]);
                
                if (data.empty())
                        continue;