Skip to content

Commit

Permalink
Refactoring: replace ExampleSDict by ExampleList
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Jan 1, 2021
1 parent bde1780 commit 75e9674
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 106 deletions.
44 changes: 11 additions & 33 deletions src/classdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class ClassDefImpl : public DefinitionMixin<ClassDefMutable>
virtual QCString generatedFromFiles() const;
virtual const FileList &usedFiles() const;
virtual const ArgumentList &typeConstraints() const;
virtual const ExampleSDict *exampleList() const;
virtual const ExampleList &getExamples() const;
virtual bool hasExamples() const;
virtual QCString getMemberListFileName() const;
virtual bool subGrouping() const;
Expand Down Expand Up @@ -523,8 +523,8 @@ class ClassDefAliasImpl : public DefinitionAliasMixin<ClassDef>
{ return getCdAlias()->usedFiles(); }
virtual const ArgumentList &typeConstraints() const
{ return getCdAlias()->typeConstraints(); }
virtual const ExampleSDict *exampleList() const
{ return getCdAlias()->exampleList(); }
virtual const ExampleList &getExamples() const
{ return getCdAlias()->getExamples(); }
virtual bool hasExamples() const
{ return getCdAlias()->hasExamples(); }
virtual QCString getMemberListFileName() const
Expand Down Expand Up @@ -627,7 +627,7 @@ class ClassDefImpl::IMPL
FileList files;

/*! Examples that use this class */
ExampleSDict *exampleSDict = 0;
ExampleList examples;

/*! Holds the kind of "class" this is. */
ClassDef::CompoundType compType;
Expand Down Expand Up @@ -732,7 +732,6 @@ void ClassDefImpl::IMPL::init(const char *defFileName, const char *name,
{
fileName=ctStr+name;
}
exampleSDict = 0;
incInfo=0;
prot=Public;
nspace=0;
Expand Down Expand Up @@ -780,7 +779,6 @@ ClassDefImpl::IMPL::IMPL() : vhdlSummaryTitles(17)

ClassDefImpl::IMPL::~IMPL()
{
delete exampleSDict;
delete usesImplClassDict;
delete usedByImplClassDict;
delete usesIntfClassDict;
Expand Down Expand Up @@ -1439,12 +1437,12 @@ void ClassDefImpl::writeDetailedDocumentationBody(OutputList &ol) const
writeTypeConstraints(ol,this,m_impl->typeConstraints);

// write examples
if (hasExamples() && m_impl->exampleSDict)
if (hasExamples())
{
ol.startExamples();
ol.startDescForItem();
//ol.startParagraph();
writeExample(ol,m_impl->exampleSDict);
writeExamples(ol,m_impl->examples);
//ol.endParagraph();
ol.endDescForItem();
ol.endExamples();
Expand Down Expand Up @@ -3137,35 +3135,15 @@ void ClassDefImpl::writeMemberList(OutputList &ol) const
}

// add a reference to an example
bool ClassDefImpl::addExample(const char *anchor,const char *nameStr,
const char *file)
bool ClassDefImpl::addExample(const char *anchor,const char *nameStr, const char *file)
{
if (m_impl->exampleSDict==0)
{
m_impl->exampleSDict = new ExampleSDict;
m_impl->exampleSDict->setAutoDelete(TRUE);
}
if (!m_impl->exampleSDict->find(nameStr))
{
Example *e=new Example;
e->anchor=anchor;
e->name=nameStr;
e->file=file;
m_impl->exampleSDict->inSort(nameStr,e);
return TRUE;
}
return FALSE;
return m_impl->examples.inSort(Example(anchor,nameStr,file));
}

// returns TRUE if this class is used in an example
bool ClassDefImpl::hasExamples() const
{
bool result=FALSE;
if (m_impl->exampleSDict)
{
result = m_impl->exampleSDict->count()>0;
}
return result;
return !m_impl->examples.empty();
}

void ClassDefImpl::addTypeConstraint(const QCString &typeConstraint,const QCString &type)
Expand Down Expand Up @@ -5004,9 +4982,9 @@ const ArgumentList &ClassDefImpl::typeConstraints() const
return m_impl->typeConstraints;
}

const ExampleSDict *ClassDefImpl::exampleList() const
const ExampleList &ClassDefImpl::getExamples() const
{
return m_impl->exampleSDict;
return m_impl->examples;
}

bool ClassDefImpl::subGrouping() const
Expand Down
4 changes: 2 additions & 2 deletions src/classdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FileDef;
class FileList;
class NamespaceDef;
class MemberDef;
class ExampleSDict;
class ExampleList;
class MemberNameInfoLinkedMap;
class UsesClassDict;
class ConstraintClassDict;
Expand Down Expand Up @@ -346,7 +346,7 @@ class ClassDef : public Definition
virtual const FileList &usedFiles() const = 0;

virtual const ArgumentList &typeConstraints() const = 0;
virtual const ExampleSDict *exampleList() const = 0;
virtual const ExampleList &getExamples() const = 0;
virtual bool hasExamples() const = 0;
virtual QCString getMemberListFileName() const = 0;
virtual bool subGrouping() const = 0;
Expand Down
20 changes: 8 additions & 12 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2376,15 +2376,13 @@ class ClassContext::Private : public DefinitionContext<ClassContext::Private>
{
if (m_classDef->hasExamples())
{
ExampleSDict::Iterator it(*m_classDef->exampleList());
Example *ex;
for (it.toFirst();(ex=it.current());++it)
for (const auto &ex : m_classDef->getExamples())
{
TemplateStruct *s = TemplateStruct::alloc();
s->set("text",ex->name);
s->set("text",ex.name);
s->set("isLinkable",TRUE);
s->set("anchor",ex->anchor);
s->set("fileName",ex->file);
s->set("anchor",ex.anchor);
s->set("fileName",ex.file);
s->set("isReference",FALSE);
s->set("externalReference","");
list->append(s);
Expand Down Expand Up @@ -4845,15 +4843,13 @@ class MemberContext::Private : public DefinitionContext<MemberContext::Private>
{
if (m_memberDef->hasExamples())
{
ExampleSDict::Iterator it(*m_memberDef->getExamples());
Example *ex;
for (it.toFirst();(ex=it.current());++it)
for (const auto &ex : m_memberDef->getExamples())
{
TemplateStruct *s = TemplateStruct::alloc();
s->set("text",ex->name);
s->set("text",ex.name);
s->set("isLinkable",TRUE);
s->set("anchor",ex->anchor);
s->set("fileName",ex->file);
s->set("anchor",ex.anchor);
s->set("fileName",ex.file);
s->set("isReference",FALSE);
s->set("externalReference","");
list->append(s);
Expand Down
32 changes: 19 additions & 13 deletions src/example.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/******************************************************************************
*
*
*
* Copyright (C) 1997-2015 by Dimitri van Heesch.
* Copyright (C) 1997-2021 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
Expand All @@ -18,30 +16,38 @@
#ifndef EXAMPLE_H
#define EXAMPLE_H

#include <algorithm>
#include <vector>

#include <qcstring.h>
#include "sortdict.h"

class ClassDef;
class MemberName;

/** Data associated with an example. */
struct Example
{
Example(const QCString &a,const QCString &n,const QCString &f) : anchor(a), name(n), file(f) {}
QCString anchor;
QCString name;
QCString file;
};

/** A sorted dictionary of Example objects. */
class ExampleSDict : public SDict<Example>
class ExampleList : public std::vector<Example>
{
public:
ExampleSDict(uint size=17) : SDict<Example>(size) { setAutoDelete(TRUE); }
~ExampleSDict() {}
private:
int compareValues(const Example *item1,const Example *item2) const
bool inSort( const Example& ex )
{
return qstricmp(item1->name,item2->name);
auto it = std::find_if(begin(),end(),[&ex](const Example &e) { return e.name==ex.name; });
if (it==end())
{
insert( std::upper_bound( begin(), end(), ex,
[](const auto &e1,const auto &e2) { return e1.name < e2.name; }
), ex
);
return true;
}
return false;
}
};

Expand Down
46 changes: 9 additions & 37 deletions src/memberdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class MemberDefImpl : public DefinitionMixin<MemberDefMutable>
virtual void setEnumBaseType(const QCString &type);
virtual QCString enumBaseType() const;
virtual bool hasExamples() const;
virtual ExampleSDict *getExamples() const;
virtual const ExampleList &getExamples() const;
virtual bool isPrototype() const;
virtual const ArgumentList &argumentList() const;
virtual ArgumentList &argumentList();
Expand Down Expand Up @@ -655,7 +655,7 @@ class MemberDefAliasImpl : public DefinitionAliasMixin<MemberDef>
{ return getMdAlias()->enumBaseType(); }
virtual bool hasExamples() const
{ return getMdAlias()->hasExamples(); }
virtual ExampleSDict *getExamples() const
virtual const ExampleList &getExamples() const
{ return getMdAlias()->getExamples(); }
virtual bool isPrototype() const
{ return getMdAlias()->isPrototype(); }
Expand Down Expand Up @@ -1198,7 +1198,7 @@ class MemberDefImpl::IMPL
MemberDef *memDec = 0; // member declaration for this definition
ClassDef *relatedAlso = 0; // points to class marked by relatedAlso

ExampleSDict *exampleSDict = 0; // a dictionary of all examples for quick access
ExampleList examples; // a dictionary of all examples for quick access

QCString type; // return actual type
QCString accessorType; // return type that tell how to get to this member
Expand Down Expand Up @@ -1302,7 +1302,6 @@ class MemberDefImpl::IMPL
MemberDefImpl::IMPL::IMPL() :
enumFields(0),
redefinedBy(0),
exampleSDict(0),
classSectionSDict(0),
category(0),
categoryRelation(0),
Expand All @@ -1315,7 +1314,6 @@ MemberDefImpl::IMPL::IMPL() :
MemberDefImpl::IMPL::~IMPL()
{
delete redefinedBy;
delete exampleSDict;
delete enumFields;
delete classSectionSDict;
}
Expand All @@ -1338,7 +1336,6 @@ void MemberDefImpl::IMPL::init(Definition *d,
memDec=0;
group=0;
grpId=-1;
exampleSDict=0;
enumFields=0;
enumScope=0;
livesInsideEnum=FALSE;
Expand Down Expand Up @@ -1462,7 +1459,6 @@ MemberDef *MemberDefImpl::deepCopy() const
*result->m_impl = *m_impl;
// clear pointers owned by object
result->m_impl->redefinedBy= 0;
result->m_impl->exampleSDict=0;
result->m_impl->enumFields=0;
result->m_impl->classSectionSDict=0;
// replace pointers owned by the object by deep copies
Expand All @@ -1475,15 +1471,6 @@ MemberDef *MemberDefImpl::deepCopy() const
result->insertReimplementedBy(md);
}
}
if (m_impl->exampleSDict)
{
ExampleSDict::Iterator it(*m_impl->exampleSDict);
Example *e;
for (it.toFirst();(e=it.current());++it)
{
result->addExample(e->anchor,e->name,e->file);
}
}
if (m_impl->enumFields)
{
MemberListIterator mli(*m_impl->enumFields);
Expand Down Expand Up @@ -1598,30 +1585,15 @@ void MemberDefImpl::insertEnumField(MemberDef *md)
m_impl->enumFields->append(md);
}

bool MemberDefImpl::addExample(const char *anchor,const char *nameStr,
const char *file)
bool MemberDefImpl::addExample(const char *anchor,const char *nameStr, const char *file)
{
//printf("%s::addExample(%s,%s,%s)\n",name().data(),anchor,nameStr,file);
if (m_impl->exampleSDict==0) m_impl->exampleSDict = new ExampleSDict;
if (m_impl->exampleSDict->find(nameStr)==0)
{
//printf("Add reference to example %s to member %s\n",nameStr,name.data());
Example *e=new Example;
e->anchor=anchor;
e->name=nameStr;
e->file=file;
m_impl->exampleSDict->inSort(nameStr,e);
return TRUE;
}
return FALSE;
return m_impl->examples.inSort(Example(anchor,nameStr,file));
}

bool MemberDefImpl::hasExamples() const
{
if (m_impl->exampleSDict==0)
return FALSE;
else
return m_impl->exampleSDict->count()>0;
return !m_impl->examples.empty();
}

QCString MemberDefImpl::getOutputFileBase() const
Expand Down Expand Up @@ -3001,7 +2973,7 @@ void MemberDefImpl::_writeExamples(OutputList &ol) const
{
ol.startExamples();
ol.startDescForItem();
writeExample(ol,m_impl->exampleSDict);
writeExamples(ol,m_impl->examples);
ol.endDescForItem();
ol.endExamples();
}
Expand Down Expand Up @@ -5353,9 +5325,9 @@ const MemberList *MemberDefImpl::enumFieldList() const
return m_impl->enumFields;
}

ExampleSDict *MemberDefImpl::getExamples() const
const ExampleList &MemberDefImpl::getExamples() const
{
return m_impl->exampleSDict;
return m_impl->examples;
}

bool MemberDefImpl::isPrototype() const
Expand Down
4 changes: 2 additions & 2 deletions src/memberdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GroupDef;
class FileDef;
class MemberList;
class MemberGroup;
class ExampleSDict;
class ExampleList;
class OutputList;
class GroupDef;
class QTextStream;
Expand Down Expand Up @@ -214,7 +214,7 @@ class MemberDef : public Definition
virtual QCString enumBaseType() const = 0;

virtual bool hasExamples() const = 0;
virtual ExampleSDict *getExamples() const = 0;
virtual const ExampleList &getExamples() const = 0;
virtual bool isPrototype() const = 0;

// argument related members
Expand Down
Loading

0 comments on commit 75e9674

Please sign in to comment.