[LyX/master] Make some code that handle authors more readable

Jean-Marc Lasgouttes lasgouttes at lyx.org
Wed Sep 11 11:31:29 UTC 2024


commit 3f5b836aa9f263e8680d80726cae35a245495b5a
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Tue Sep 10 15:29:36 2024 +0200

    Make some code that handle authors more readable
    
    Create accssors authodmap() in BufferParams.
    
    Use [] operator instead of find().
    
    Hopefully this will avoid to confuse Coverity scan.
---
 src/BufferParams.cpp        | 17 +++++++++++++++--
 src/BufferParams.h          |  3 ++-
 src/Text.cpp                |  6 +++---
 src/insets/InsetTabular.cpp |  6 +++---
 4 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index e1a31b1a18..3906e5f665 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -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);
 }
 
 
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 4444f31f2b..52abc6f229 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -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;
diff --git a/src/Text.cpp b/src/Text.cpp
index 327e3949ee..81a76d2545 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -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"),
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 63d6a4eb8a..a36808fd56 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -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;
 		}
 	}


More information about the lyx-cvs mailing list