mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Streamline use of map<col-type, bool>
Typically, to check whether an element is present and set to true, instead of foo.find(c) != foo.end() && foo.find(c)->second one uses foo[c] The map<> code creates elements automatically when they do not exist and zero-initializes them. This avoids puzzlement of Coverity scan when seeing that find() result is dereferenced without checking that it is not equal to end(). Moreover, this makes the code much much clearer. I still do not understand it, though ;)
This commit is contained in:
parent
fe19855116
commit
9fc19badab
@ -2634,10 +2634,9 @@ void Tabular::TeXTopHLine(otexstream & os, row_type row, list<col_type> const &
|
|||||||
topltrims[c] = topltrims[c-1];
|
topltrims[c] = topltrims[c-1];
|
||||||
toprtrims[c] = toprtrims[c-1];
|
toprtrims[c] = toprtrims[c-1];
|
||||||
}
|
}
|
||||||
if (topline.find(c) != topline.end() && topline.find(c)->second)
|
if (topline[c])
|
||||||
++nset;
|
++nset;
|
||||||
if ((topltrims.find(c) != topltrims.end() && topltrims.find(c)->second)
|
if (topltrims[c] || toprtrims[c])
|
||||||
|| (toprtrims.find(c) != toprtrims.end() && toprtrims.find(c)->second))
|
|
||||||
have_trims = true;
|
have_trims = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2669,7 +2668,7 @@ void Tabular::TeXTopHLine(otexstream & os, row_type row, list<col_type> const &
|
|||||||
if (cl < c)
|
if (cl < c)
|
||||||
continue;
|
continue;
|
||||||
c = cl;
|
c = cl;
|
||||||
if (topline.find(c)->second) {
|
if (topline[c]) {
|
||||||
col_type offset = 0;
|
col_type offset = 0;
|
||||||
for (col_type j = 0 ; j < c; ++j)
|
for (col_type j = 0 ; j < c; ++j)
|
||||||
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
|
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
|
||||||
@ -2679,21 +2678,18 @@ void Tabular::TeXTopHLine(otexstream & os, row_type row, list<col_type> const &
|
|||||||
while (isPartOfMultiColumn(row, c))
|
while (isPartOfMultiColumn(row, c))
|
||||||
++c;
|
++c;
|
||||||
string trim;
|
string trim;
|
||||||
if (topltrims.find(c) != topltrims.end()
|
if (topltrims[c])
|
||||||
&& topltrims.find(c)->second)
|
|
||||||
trim = "l";
|
trim = "l";
|
||||||
col_type cstart = c;
|
col_type cstart = c;
|
||||||
for ( ; c < ncols() - 1 && topline.find(c + 1)->second ; ++c) {
|
for ( ; c < ncols() - 1 && topline[c + 1] ; ++c) {
|
||||||
if (isMultiColumn(cellIndex(row, c))
|
if (isMultiColumn(cellIndex(row, c))
|
||||||
&& c < ncols() - 1 && isPartOfMultiColumn(row, c + 1))
|
&& c < ncols() - 1 && isPartOfMultiColumn(row, c + 1))
|
||||||
continue;
|
continue;
|
||||||
if (c > cstart && topltrims.find(c) != topltrims.end()
|
if (c > cstart && topltrims[c]) {
|
||||||
&& topltrims.find(c)->second) {
|
|
||||||
if (!isPartOfMultiColumn(row, c))
|
if (!isPartOfMultiColumn(row, c))
|
||||||
--c;
|
--c;
|
||||||
break;
|
break;
|
||||||
} else if (toprtrims.find(c) != toprtrims.end()
|
} else if (toprtrims[c])
|
||||||
&& toprtrims.find(c)->second)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2701,8 +2697,7 @@ void Tabular::TeXTopHLine(otexstream & os, row_type row, list<col_type> const &
|
|||||||
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
|
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
|
||||||
++offset;
|
++offset;
|
||||||
col_type lastcol = (*it1 == *it2) ? c + 1 + offset : columns.size() - c + offset;
|
col_type lastcol = (*it1 == *it2) ? c + 1 + offset : columns.size() - c + offset;
|
||||||
if (toprtrims.find(c) != toprtrims.end()
|
if (toprtrims[c])
|
||||||
&& toprtrims.find(c)->second)
|
|
||||||
trim += "r";
|
trim += "r";
|
||||||
|
|
||||||
os << cline;
|
os << cline;
|
||||||
@ -2761,8 +2756,8 @@ void Tabular::TeXBottomHLine(otexstream & os, row_type row, list<col_type> const
|
|||||||
bottomltrims[c] = bottomltrims[c-1];
|
bottomltrims[c] = bottomltrims[c-1];
|
||||||
bottomrtrims[c] = bottomrtrims[c-1];
|
bottomrtrims[c] = bottomrtrims[c-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
nextrowset &= topline.find(c) != topline.end() && topline.find(c)->second;
|
nextrowset &= topline[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
// combine this row's bottom lines and next row's toplines if necessary
|
// combine this row's bottom lines and next row's toplines if necessary
|
||||||
@ -2770,15 +2765,12 @@ void Tabular::TeXBottomHLine(otexstream & os, row_type row, list<col_type> const
|
|||||||
bool have_trims = false;
|
bool have_trims = false;
|
||||||
for (auto const & c : columns) {
|
for (auto const & c : columns) {
|
||||||
if (!nextrowset)
|
if (!nextrowset)
|
||||||
bottomline[c] = bottomline.find(c)->second || topline.find(c)->second;
|
bottomline[c] |= topline[c];
|
||||||
bottomltrims[c] = (bottomltrims.find(c) != bottomltrims.end() && bottomltrims.find(c)->second)
|
bottomltrims[c] |= topltrims[c];
|
||||||
|| (topltrims.find(c) != topltrims.end() && topltrims.find(c)->second);
|
bottomrtrims[c] |= toprtrims[c];
|
||||||
bottomrtrims[c] = (bottomrtrims.find(c) != bottomrtrims.end() && bottomrtrims.find(c)->second)
|
|
||||||
|| (toprtrims.find(c) != toprtrims.end() && toprtrims.find(c)->second);
|
|
||||||
if (bottomline.find(c)->second)
|
if (bottomline.find(c)->second)
|
||||||
++nset;
|
++nset;
|
||||||
if ((bottomltrims.find(c) != bottomltrims.end() && bottomltrims.find(c)->second)
|
if (bottomltrims[c] || bottomrtrims[c])
|
||||||
|| (bottomrtrims.find(c) != bottomrtrims.end() && bottomrtrims.find(c)->second))
|
|
||||||
have_trims = true;
|
have_trims = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2803,7 +2795,7 @@ void Tabular::TeXBottomHLine(otexstream & os, row_type row, list<col_type> const
|
|||||||
if (cl < c)
|
if (cl < c)
|
||||||
continue;
|
continue;
|
||||||
c = cl;
|
c = cl;
|
||||||
if (bottomline.find(c)->second) {
|
if (bottomline[c]) {
|
||||||
col_type offset = 0;
|
col_type offset = 0;
|
||||||
for (col_type j = 0 ; j < c; ++j)
|
for (col_type j = 0 ; j < c; ++j)
|
||||||
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
|
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
|
||||||
@ -2813,23 +2805,19 @@ void Tabular::TeXBottomHLine(otexstream & os, row_type row, list<col_type> const
|
|||||||
while (isPartOfMultiColumn(row, c))
|
while (isPartOfMultiColumn(row, c))
|
||||||
++c;
|
++c;
|
||||||
string trim;
|
string trim;
|
||||||
if (bottomltrims.find(c) != bottomltrims.end()
|
if (bottomltrims[c])
|
||||||
&& bottomltrims.find(c)->second)
|
|
||||||
trim = "l";
|
trim = "l";
|
||||||
col_type cstart = c;
|
col_type cstart = c;
|
||||||
for ( ; c < ncols() - 1 && bottomline.find(c + 1)->second ; ++c) {
|
for ( ; c < ncols() - 1 && bottomline[c + 1] ; ++c) {
|
||||||
if (isMultiColumn(cellIndex(row, c))
|
if (isMultiColumn(cellIndex(row, c))
|
||||||
&& c < ncols() - 1
|
&& c < ncols() - 1
|
||||||
&& isPartOfMultiColumn(row, c + 1))
|
&& isPartOfMultiColumn(row, c + 1))
|
||||||
continue;
|
continue;
|
||||||
if (c > cstart
|
if (c > cstart && bottomltrims[c]) {
|
||||||
&& bottomltrims.find(c) != bottomltrims.end()
|
|
||||||
&& bottomltrims.find(c)->second) {
|
|
||||||
if (!isPartOfMultiColumn(row, c))
|
if (!isPartOfMultiColumn(row, c))
|
||||||
--c;
|
--c;
|
||||||
break;
|
break;
|
||||||
} else if (bottomrtrims.find(c) != bottomrtrims.end()
|
} else if (bottomrtrims[c])
|
||||||
&& bottomrtrims.find(c)->second)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2837,8 +2825,7 @@ void Tabular::TeXBottomHLine(otexstream & os, row_type row, list<col_type> const
|
|||||||
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
|
if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
|
||||||
++offset;
|
++offset;
|
||||||
col_type lastcol = (*it1 == *it2) ? c + 1 + offset : columns.size() - c + offset;
|
col_type lastcol = (*it1 == *it2) ? c + 1 + offset : columns.size() - c + offset;
|
||||||
if (bottomrtrims.find(c) != bottomrtrims.end()
|
if (bottomrtrims[c])
|
||||||
&& bottomrtrims.find(c)->second)
|
|
||||||
trim += "r";
|
trim += "r";
|
||||||
|
|
||||||
os << cline;
|
os << cline;
|
||||||
|
Loading…
Reference in New Issue
Block a user