[prev in list] [next in list] [prev in thread] [next in thread]
List: lyx-cvs
Subject: [LyX/master] InsetIndex: simplify the implementation of the has* methods.
From: Thibaut Cuvelier <tcuvelier () lyx ! org>
Date: 2022-10-31 17:40:11
Message-ID: 20221031174011.89D7C28065E () lyx ! lyx ! org
[Download RAW message or body]
commit 54a519a0893af33220dea91bef55f8a5d71b907c
Author: Thibaut Cuvelier <tcuvelier@lyx.org>
Date: Mon Apr 25 03:40:06 2022 +0200
InsetIndex: simplify the implementation of the has* methods.
---
src/insets/InsetIndex.cpp | 48 ++++++++++++++++++++------------------------
1 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp
index 8a75622..21995a0 100644
--- a/src/insets/InsetIndex.cpp
+++ b/src/insets/InsetIndex.cpp
@@ -769,51 +769,47 @@ std::vector<docstring> \
InsetIndex::getSeeAlsoesAsText(OutputParams const & runpa }
-bool InsetIndex::hasSubentries() const
+namespace {
+
+bool hasInsetWithCode(const InsetIndex * const inset_index, const InsetCode code,
+ const std::set<InsetIndexMacroParams::Type> types = {})
{
- Paragraph const & par = paragraphs().front();
+ Paragraph const & par = inset_index->paragraphs().front();
InsetList::const_iterator it = par.insetList().begin();
for (; it != par.insetList().end(); ++it) {
Inset & inset = *it->inset;
- if (inset.lyxCode() == INDEXMACRO_CODE) {
+ if (inset.lyxCode() == code) {
+ if (types.empty())
+ return true;
+
+ LASSERT(code == INDEXMACRO_CODE, return false);
InsetIndexMacro const & iim =
- static_cast<InsetIndexMacro const &>(inset);
- if (iim.params().type == InsetIndexMacroParams::Subindex)
+ static_cast<InsetIndexMacro const &>(inset);
+ if (types.find(iim.params().type) != types.end())
return true;
}
}
return false;
}
+} // namespace
+
+
+bool InsetIndex::hasSubentries() const
+{
+ return hasInsetWithCode(this, INDEXMACRO_CODE, {InsetIndexMacroParams::Subindex});
+}
+
bool InsetIndex::hasSeeRef() const
{
- Paragraph const & par = paragraphs().front();
- InsetList::const_iterator it = par.insetList().begin();
- for (; it != par.insetList().end(); ++it) {
- Inset & inset = *it->inset;
- if (inset.lyxCode() == INDEXMACRO_CODE) {
- InsetIndexMacro const & iim =
- static_cast<InsetIndexMacro const &>(inset);
- if (iim.params().type == InsetIndexMacroParams::See
- || iim.params().type == InsetIndexMacroParams::Seealso)
- return true;
- }
- }
- return false;
+ return hasInsetWithCode(this, INDEXMACRO_CODE, {InsetIndexMacroParams::See, \
InsetIndexMacroParams::Seealso}); }
bool InsetIndex::hasSortKey() const
{
- Paragraph const & par = paragraphs().front();
- InsetList::const_iterator it = par.insetList().begin();
- for (; it != par.insetList().end(); ++it) {
- Inset & inset = *it->inset;
- if (inset.lyxCode() == INDEXMACRO_SORTKEY_CODE)
- return true;
- }
- return false;
+ return hasInsetWithCode(this, INDEXMACRO_SORTKEY_CODE);
}
--
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic