]> git.lyx.org Git - lyx.git/commitdiff
Make some code that handle authors more readable
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 10 Sep 2024 13:29:36 +0000 (15:29 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 10 Sep 2024 13:32:49 +0000 (15:32 +0200)
Create accssors authodmap() in BufferParams.

Use [] operator instead of find().

Hopefully this will avoid to confuse Coverity scan.

src/BufferParams.cpp
src/BufferParams.h
src/Text.cpp
src/insets/InsetTabular.cpp

index e1a31b1a183cb5bad2b23d68dbe3055429ac2fa6..3906e5f665b6e6e77791cc9a363b21f64c74e1cb 100644 (file)
@@ -341,6 +341,7 @@ public:
        Impl();
 
        AuthorList authorlist;
+       AuthorMap authormap;
        BranchList branchlist;
        WordLangTable spellignore;
        Bullet temp_bullets[4];
@@ -494,7 +495,7 @@ BufferParams::BufferParams()
        use_lineno = false;
 
        // map current author
-       author_map_[pimpl_->authorlist.get(0).bufferId()] = 0;
+       pimpl_->authormap[pimpl_->authorlist.get(0).bufferId()] = 0;
 }
 
 
@@ -578,9 +579,21 @@ AuthorList const & BufferParams::authors() const
 }
 
 
+BufferParams::AuthorMap & BufferParams::authormap()
+{
+       return pimpl_->authormap;
+}
+
+
+BufferParams::AuthorMap const & BufferParams::authormap() const
+{
+       return pimpl_->authormap;
+}
+
+
 void BufferParams::addAuthor(Author const & a)
 {
-       author_map_[a.bufferId()] = pimpl_->authorlist.record(a);
+       pimpl_->authormap[a.bufferId()] = pimpl_->authorlist.record(a);
 }
 
 
index 4444f31f2b5f577d5ab92e4f72ebbf1668a7f67e..52abc6f229ef17fd277023d7fd1f2651cfd11fd8 100644 (file)
@@ -494,7 +494,8 @@ public:
 
        /// map of the file's author IDs to AuthorList indexes
        typedef std::map<int, int> AuthorMap;
-       AuthorMap author_map_;
+       AuthorMap & authormap();
+       AuthorMap const & authormap() const;
 
        /// the buffer's active font encoding
        std::string const main_font_encoding() const;
index 327e3949ee259c4aa41b8a520b3be2e30b73034e..81a76d2545e02f96887727422c0383685803a2e0 100644 (file)
@@ -594,7 +594,7 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
                int aid;
                time_t ct;
                is >> aid >> ct;
-               BufferParams::AuthorMap const & am = bp.author_map_;
+               BufferParams::AuthorMap & am = bp.authormap();
                if (am.find(aid) == am.end()) {
                        errorList.push_back(ErrorItem(
                                _("Change tracking author index missing"),
@@ -609,9 +609,9 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
                        bp.addAuthor(Author(aid));
                }
                if (token == "\\change_inserted")
-                       change = Change(Change::INSERTED, am.find(aid)->second, ct);
+                       change = Change(Change::INSERTED, am[aid], ct);
                else
-                       change = Change(Change::DELETED, am.find(aid)->second, ct);
+                       change = Change(Change::DELETED, am[aid], ct);
        } else {
                lex.eatLine();
                errorList.push_back(ErrorItem(_("Unknown token"),
index 63d6a4eb8a480620a0b444544ea9cfb528a0e2d7..a36808fd5673f23406cb16ec1e478aa18304b3f8 100644 (file)
@@ -470,7 +470,7 @@ bool getTokenValue(string const & str, char const * token, Change & change, Buff
                                         "is incomplete. I will ignore this."));
                        return false;
                }
-               BufferParams::AuthorMap const & am = bp.author_map_;
+               BufferParams::AuthorMap & am = bp.authormap();
                int aid = convert<int>(changedata[1]);
                if (am.find(aid) == am.end()) {
                        // FIXME Use ErrorList
@@ -488,10 +488,10 @@ bool getTokenValue(string const & str, char const * token, Change & change, Buff
                time_t ct;
                is >> ct;
                if (changedata[0] == "inserted") {
-                       change = Change(Change::INSERTED, am.find(aid)->second, ct);
+                       change = Change(Change::INSERTED, am[aid], ct);
                        return true;
                } else if (changedata[0] == "deleted") {
-                       change = Change(Change::DELETED, am.find(aid)->second, ct);
+                       change = Change(Change::DELETED, am[aid], ct);
                        return true;
                }
        }