Skip to content

Commit 8bafec5

Browse files
committed
Refactoring: remove avoidable const_cast's
1 parent a697e11 commit 8bafec5

19 files changed

+110
-111
lines changed

src/conceptdef.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -766,18 +766,6 @@ ConceptDefMutable *toConceptDefMutable(Definition *d)
766766
}
767767
}
768768

769-
ConceptDefMutable *toConceptDefMutable(const Definition *d)
770-
{
771-
if (d && typeid(*d)==typeid(ConceptDefImpl))
772-
{
773-
return const_cast<ConceptDefMutable*>(static_cast<const ConceptDefMutable*>(d));
774-
}
775-
else
776-
{
777-
return nullptr;
778-
}
779-
}
780-
781769
// -- helpers
782770

783771
ConceptDef *getConcept(const QCString &n)

src/conceptdef.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ ConceptDef *toConceptDef(Definition *d);
8383
ConceptDef *toConceptDef(DefinitionMutable *d);
8484
const ConceptDef *toConceptDef(const Definition *d);
8585
ConceptDefMutable *toConceptDefMutable(Definition *d);
86-
ConceptDefMutable *toConceptDefMutable(const Definition *d);
8786

8887
// --- Helpers
8988

src/definition.cpp

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -367,58 +367,6 @@ bool DefinitionImpl::hasSections() const
367367
return FALSE;
368368
}
369369

370-
void DefinitionImpl::addSectionsToIndex()
371-
{
372-
if (m_impl->sectionRefs.empty()) return;
373-
//printf("DefinitionImpl::addSectionsToIndex()\n");
374-
int level=1;
375-
for (auto it = m_impl->sectionRefs.begin(); it!=m_impl->sectionRefs.end(); ++it)
376-
{
377-
const SectionInfo *si = *it;
378-
SectionType type = si->type();
379-
if (type.isSection())
380-
{
381-
//printf(" level=%d title=%s\n",level,qPrint(si->title));
382-
int nextLevel = type.level();
383-
if (nextLevel>level)
384-
{
385-
for (int i=level;i<nextLevel;i++)
386-
{
387-
Doxygen::indexList->incContentsDepth();
388-
}
389-
}
390-
else if (nextLevel<level)
391-
{
392-
for (int i=nextLevel;i<level;i++)
393-
{
394-
Doxygen::indexList->decContentsDepth();
395-
}
396-
}
397-
QCString title = si->title();
398-
if (title.isEmpty()) title = si->label();
399-
const MemberDef *md = m_impl->def->definitionType()==Definition::TypeMember ? toMemberDef(m_impl->def) : nullptr;
400-
const Definition *scope = m_impl->def->definitionType()==Definition::TypeMember ? m_impl->def->getOuterScope() : m_impl->def;
401-
title = parseCommentAsText(scope,md,title,si->fileName(),si->lineNr());
402-
// determine if there is a next level inside this item, but be aware of the anchor and table section references.
403-
auto it_next = std::next(it);
404-
bool isDir = (it_next!=m_impl->sectionRefs.end()) ?
405-
((*it_next)->type().isSection() && (*it_next)->type().level() > nextLevel) : false;
406-
Doxygen::indexList->addContentsItem(isDir,title,
407-
getReference(),
408-
m_impl->def->getOutputFileBase(),
409-
si->label(),
410-
false,
411-
true);
412-
level = nextLevel;
413-
}
414-
}
415-
while (level>1)
416-
{
417-
Doxygen::indexList->decContentsDepth();
418-
level--;
419-
}
420-
}
421-
422370
void DefinitionImpl::writeDocAnchorsToTagFile(TextStream &tagFile) const
423371
{
424372
if (!m_impl->sectionRefs.empty())

src/definition.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ class DefinitionMutable
365365
virtual void addSourceReferences(MemberDef *d,const QCString &sourceRefName) = 0;
366366
virtual void mergeRefItems(Definition *d) = 0;
367367
virtual void addInnerCompound(Definition *d) = 0;
368-
virtual void addSectionsToIndex() = 0;
369368
virtual void mergeReferences(const Definition *other) = 0;
370369
virtual void mergeReferencedBy(const Definition *other) = 0;
371370
virtual void computeTooltip() = 0;

src/definitionimpl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ class DefinitionImpl
122122
QCString pathFragment() const;
123123
void writeDocAnchorsToTagFile(TextStream &) const;
124124
void setLocalName(const QCString &name);
125-
void addSectionsToIndex();
126125
void writeToc(OutputList &ol, const LocalToc &lt) const;
127126
void computeTooltip();
128127
void _setSymbolName(const QCString &name);
@@ -282,8 +281,6 @@ class DefinitionMixin : public Base
282281
{ m_impl.writeDocAnchorsToTagFile(fs); }
283282
void setLocalName(const QCString &name) override
284283
{ m_impl.setLocalName(name); }
285-
void addSectionsToIndex() override
286-
{ m_impl.addSectionsToIndex(); }
287284
void writeToc(OutputList &ol, const LocalToc &lt) const override
288285
{ m_impl.writeToc(ol,lt); }
289286
void computeTooltip() override

src/dirdef.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class DirDefImpl : public DefinitionMixin<DirDef>
5151
const QCString shortName() const override { return m_shortName; }
5252
void addSubDir(DirDef *subdir) override;
5353
const FileList &getFiles() const override { return m_fileList; }
54-
void addFile(const FileDef *fd) override;
54+
void addFile(FileDef *fd) override;
5555
const DirList &subDirs() const override { return m_subdirs; }
5656
bool hasSubdirs() const override { return !m_subdirs.empty(); }
5757
int level() const override { return m_level; }
@@ -173,10 +173,10 @@ void DirDefImpl::setDirIndex(int index)
173173
m_dirIndex=index;
174174
}
175175

176-
void DirDefImpl::addFile(const FileDef *fd)
176+
void DirDefImpl::addFile(FileDef *fd)
177177
{
178178
m_fileList.push_back(fd);
179-
const_cast<FileDef*>(fd)->setDirDef(this);
179+
fd->setDirDef(this);
180180
}
181181

182182
void DirDefImpl::sort()

src/dirdef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class DirDef : public DefinitionMutable, public Definition
115115
virtual const QCString shortName() const = 0;
116116
virtual void addSubDir(DirDef *subdir) = 0;
117117
virtual const FileList &getFiles() const = 0;
118-
virtual void addFile(const FileDef *fd) = 0;
118+
virtual void addFile(FileDef *fd) = 0;
119119
virtual const DirList &subDirs() const = 0;
120120
virtual bool hasSubdirs() const = 0;
121121
virtual int level() const = 0;

src/doxygen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,10 +1484,10 @@ static ClassDefMutable *createTagLessInstance(const ClassDef *rootCd,const Class
14841484
cd->setFileDef(fd);
14851485
fd->insertClass(cd);
14861486
}
1487-
for (const auto &gd : rootCd->partOfGroups())
1487+
for (auto &gd : rootCd->partOfGroups())
14881488
{
14891489
cd->makePartOfGroup(gd);
1490-
const_cast<GroupDef*>(gd)->addClass(cd);
1490+
gd->addClass(cd);
14911491
}
14921492

14931493
MemberList *ml = templ->getMemberList(MemberListType::PubAttribs());
@@ -5449,11 +5449,11 @@ static bool findGlobalMember(const Entry *root,
54495449
NamespaceDef *rnd = nullptr;
54505450
if (!namespaceName.isEmpty()) rnd = Doxygen::namespaceLinkedMap->find(namespaceName);
54515451

5452-
const ArgumentList &mdAl = const_cast<const MemberDef *>(md.get())->argumentList();
5452+
const ArgumentList &mdAl = md.get()->argumentList();
54535453
bool matching=
54545454
(mdAl.empty() && root->argList.empty()) ||
54555455
md->isVariable() || md->isTypedef() || /* in case of function pointers */
5456-
matchArguments2(md->getOuterScope(),const_cast<const MemberDef *>(md.get())->getFileDef(),&mdAl,
5456+
matchArguments2(md->getOuterScope(),md.get()->getFileDef(),&mdAl,
54575457
rnd ? rnd : Doxygen::globalScope,fd,&root->argList,
54585458
FALSE,root->lang);
54595459

src/groupdef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ void addMemberToGroups(const Entry *root,MemberDef *md)
16041604
// put member into group defined by this entry?
16051605
if (fgd)
16061606
{
1607-
GroupDef *mgd = const_cast<GroupDef*>(md->getGroupDef());
1607+
GroupDef *mgd = md->getGroupDef();
16081608
//printf("mgd=%p\n",mgd);
16091609
bool insertit = FALSE;
16101610
if (mgd==nullptr)

src/index.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3798,7 +3798,7 @@ static bool mainPageHasOwnTitle()
37983798
return !projectName.isEmpty() && mainPageHasTitle() && qstricmp(title,projectName)!=0;
37993799
}
38003800

3801-
static void writePages(const PageDef *pd,FTVHelp *ftv)
3801+
static void writePages(PageDef *pd,FTVHelp *ftv)
38023802
{
38033803
//printf("writePages()=%s pd=%p mainpage=%p\n",qPrint(pd->name()),(void*)pd,(void*)Doxygen::mainPage.get());
38043804
LayoutNavEntry *lne = LayoutDocManager::instance().rootNavEntry()->find(LayoutNavEntry::Pages);
@@ -3842,7 +3842,7 @@ static void writePages(const PageDef *pd,FTVHelp *ftv)
38423842
}
38433843
if (hasSections)
38443844
{
3845-
const_cast<PageDef*>(pd)->addSectionsToIndex();
3845+
pd->addSectionsToIndex();
38463846
}
38473847
for (const auto &subPage : pd->getSubPages())
38483848
{
@@ -4177,7 +4177,7 @@ static void writeGroupTreeNode(OutputList &ol, const GroupDef *gd, int level, FT
41774177
}
41784178
if (hasSections)
41794179
{
4180-
const_cast<PageDef*>(pd)->addSectionsToIndex();
4180+
pd->addSectionsToIndex();
41814181
}
41824182
writePages(pd,nullptr);
41834183
if (hasSections || hasSubPages)

0 commit comments

Comments
 (0)