From 84084bebe0544650513dbcd75e71a50b2119360d Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Thu, 6 Aug 2020 21:06:46 +0200 Subject: Refactoring: changed QValueList to std::vector for template engine --- src/context.cpp | 86 ++++++++++++++++++++-------------------- src/template.cpp | 119 +++++++++++++++++++++++++++---------------------------- src/template.h | 14 +++---- src/util.cpp | 3 +- 4 files changed, 111 insertions(+), 111 deletions(-) diff --git a/src/context.cpp b/src/context.cpp index 83e8e7a..3bdead3 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -443,147 +443,147 @@ class TranslateContext::Private { public: - TemplateVariant handleGeneratedAt(const QValueList &args) const + TemplateVariant handleGeneratedAt(const std::vector &args) const { - if (args.count()==2) + if (args.size()==2) { return theTranslator->trGeneratedAt(args[0].toString(),args[1].toString()); } else { - err("tr.generateAt should take two arguments, got %d!\n",args.count()); + err("tr.generateAt should take two arguments, got %zu!\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleInheritanceDiagramFor(const QValueList &args) const + TemplateVariant handleInheritanceDiagramFor(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trClassDiagram(args[0].toString()); } else { - err("tr.inheritanceDiagramFor should take one argument, got %d!\n",args.count()); + err("tr.inheritanceDiagramFor should take one argument, got %zu!\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleCollaborationDiagramFor(const QValueList &args) const + TemplateVariant handleCollaborationDiagramFor(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trCollaborationDiagram(args[0].toString()); } else { - err("tr.collaborationDiagramFor should take one argument, got %d!\n",args.count()); + err("tr.collaborationDiagramFor should take one argument, got %zu!\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleDirDependencyGraphFor(const QValueList &args) const + TemplateVariant handleDirDependencyGraphFor(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trDirDepGraph(args[0].toString()); } else { - err("tr.dirDependencyGraphFor should take one argument, got %d!\n",args.count()); + err("tr.dirDependencyGraphFor should take one argument, got %zu!\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleInheritsList(const QValueList &args) const + TemplateVariant handleInheritsList(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trInheritsList(args[0].toInt()); } else { - err("tr.inheritsList should take one integer argument, got %d!\n",args.count()); + err("tr.inheritsList should take one integer argument, got %zu!\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleInheritedByList(const QValueList &args) const + TemplateVariant handleInheritedByList(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trInheritedByList(args[0].toInt()); } else { - err("tr.inheritedByList should take one integer argument, got %d!\n",args.count()); + err("tr.inheritedByList should take one integer argument, got %zu!\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleWriteList(const QValueList &args) const + TemplateVariant handleWriteList(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trWriteList(args[0].toInt()); } else { - err("tr.*List should take one integer argument, got %d!\n",args.count()); + err("tr.*List should take one integer argument, got %zu!\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleImplementedBy(const QValueList &args) const + TemplateVariant handleImplementedBy(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trImplementedInList(args[0].toInt()); } else { - err("tr.implementedBy should take one integer argument, got %d!\n",args.count()); + err("tr.implementedBy should take one integer argument, got %zu!\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleReimplementedBy(const QValueList &args) const + TemplateVariant handleReimplementedBy(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trReimplementedInList(args[0].toInt()); } else { - err("tr.reimplementedBy should take one integer argument, got %d!\n",args.count()); + err("tr.reimplementedBy should take one integer argument, got %zu!\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleSourceRefs(const QValueList &args) const + TemplateVariant handleSourceRefs(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trReferences()+" "+theTranslator->trWriteList(args[0].toInt())+"."; } else { - err("tr.sourceRefs should take one integer argument, got %d\n",args.count()); + err("tr.sourceRefs should take one integer argument, got %zu\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleSourceRefBys(const QValueList &args) const + TemplateVariant handleSourceRefBys(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trReferencedBy()+" "+theTranslator->trWriteList(args[0].toInt())+"."; } else { - err("tr.sourceRefBys should take one integer argument, got %d\n",args.count()); + err("tr.sourceRefBys should take one integer argument, got %zu\n",args.size()); } return TemplateVariant(); } - TemplateVariant handleIncludeDependencyGraph(const QValueList &args) const + TemplateVariant handleIncludeDependencyGraph(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return theTranslator->trInclDepGraph(args[0].toString()); } else { - err("tr.includeDependencyGraph should take one string argument, got %d\n",args.count()); + err("tr.includeDependencyGraph should take one string argument, got %zu\n",args.size()); } return TemplateVariant(); } @@ -5126,15 +5126,15 @@ class MemberContext::Private : public DefinitionContext { return m_memberDef->typeString(); } - TemplateVariant handleDetailsVisibleFor(const QValueList &args) const + TemplateVariant handleDetailsVisibleFor(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { return m_memberDef->isDetailedSectionVisible(args[0].toString()=="module",args[0].toString()=="file"); } else { - err(".detailsVisibleFor should take one string argument, got %d\n",args.count()); + err(".detailsVisibleFor should take one string argument, got %zu\n",args.size()); } return TemplateVariant(); } @@ -5142,9 +5142,9 @@ class MemberContext::Private : public DefinitionContext { return TemplateVariant::Delegate::fromMethod(this); } - TemplateVariant handleNameWithContextFor(const QValueList &args) const + TemplateVariant handleNameWithContextFor(const std::vector &args) const { - if (args.count()==1) + if (args.size()==1) { SrcLangExt lang = m_memberDef->getLanguage(); QCString n = m_memberDef->name(); @@ -5166,7 +5166,7 @@ class MemberContext::Private : public DefinitionContext } else { - err(".nameWithContextFor should take one string argument, got %d\n",args.count()); + err(".nameWithContextFor should take one string argument, got %zu\n",args.size()); } return TemplateVariant(); } @@ -9418,7 +9418,7 @@ class ArgumentContext::Private return result; } private: - const Argument &m_argument; + Argument m_argument; const Definition *m_def; QCString m_relPath; struct Cachable diff --git a/src/template.cpp b/src/template.cpp index c836c6b..80962e8 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -48,10 +48,10 @@ class TemplateToken; //------------------------------------------------------------------- -static QValueList split(const QCString &str,const QCString &sep, +static std::vector split(const QCString &str,const QCString &sep, bool allowEmptyEntries=FALSE,bool cleanup=TRUE) { - QValueList lst; + std::vector lst; int j = 0; int i = str.find( sep, j ); @@ -62,16 +62,16 @@ static QValueList split(const QCString &str,const QCString &sep, { if (cleanup) { - lst.append(str.mid(j,i-j).stripWhiteSpace()); + lst.push_back(str.mid(j,i-j).stripWhiteSpace()); } else { - lst.append(str.mid(j,i-j)); + lst.push_back(str.mid(j,i-j)); } } else if (allowEmptyEntries) { - lst.append(""); + lst.push_back(""); } j = i + sep.length(); i = str.find(sep,j); @@ -82,16 +82,16 @@ static QValueList split(const QCString &str,const QCString &sep, { if (cleanup) { - lst.append(str.mid(j,l-j+1).stripWhiteSpace()); + lst.push_back(str.mid(j,l-j+1).stripWhiteSpace()); } else { - lst.append(str.mid(j,l-j+1)); + lst.push_back(str.mid(j,l-j+1)); } } else if (allowEmptyEntries) { - lst.append(""); + lst.push_back(""); } return lst; @@ -305,7 +305,7 @@ class TemplateList::Private { public: Private() : index(-1), refCount(0) {} - QValueList elems; + std::vector elems; int index = -1; int refCount = 0; }; @@ -338,67 +338,65 @@ int TemplateList::release() uint TemplateList::count() const { - return p->elems.count(); + return p->elems.size(); } void TemplateList::append(const TemplateVariant &v) { - p->elems.append(v); + p->elems.push_back(v); } // iterator support class TemplateListConstIterator : public TemplateListIntf::ConstIterator { public: - TemplateListConstIterator(const TemplateList &l) : m_list(l) { m_index=-1; } + TemplateListConstIterator(const TemplateList &l) : m_list(l) { m_index=0; } virtual ~TemplateListConstIterator() {} virtual void toFirst() { - m_it = m_list.p->elems.begin(); m_index=0; } virtual void toLast() { - m_it = m_list.p->elems.fromLast(); - m_index=m_list.count()-1; + if (m_list.p->elems.size()>0) + { + m_index=m_list.p->elems.size()-1; + } + else + { + m_index=0; + } } virtual void toNext() { - if (m_it!=m_list.p->elems.end()) + if (m_indexelems.size()) { - ++m_it; - ++m_index; + m_index++; } } virtual void toPrev() { if (m_index>0) { - --m_it; --m_index; } - else - { - m_index=-1; - } } virtual bool current(TemplateVariant &v) const { - if (m_index<0 || m_it==m_list.p->elems.end()) + if (m_index>=0 && m_indexelems.size()) { - v = TemplateVariant(); - return FALSE; + v = m_list.p->elems[m_index]; + return TRUE; } else { - v = *m_it; - return TRUE; + v = TemplateVariant(); + return FALSE; } } private: const TemplateList &m_list; - QValueList::ConstIterator m_it; - int m_index = 0; + size_t m_index = 0; }; TemplateListIntf::ConstIterator *TemplateList::createIterator() const @@ -408,7 +406,7 @@ TemplateListIntf::ConstIterator *TemplateList::createIterator() const TemplateVariant TemplateList::at(uint index) const { - if (indexelems.count()) + if (indexelems.size()) { return p->elems[index]; } @@ -545,7 +543,7 @@ class TemplateContextImpl : public TemplateContext QCString outputDirectory() const { return m_outputDir; } TemplateEscapeIntf *escapeIntf() const { return m_activeEscapeIntf; } TemplateSpacelessIntf *spacelessIntf() const { return m_spacelessIntf; } - void enableSpaceless(bool b) { if (b && !m_spacelessEnabled) m_spacelessIntf->reset(); + void enableSpaceless(bool b) { if (b && !m_spacelessEnabled) m_spacelessIntf->reset(); m_spacelessEnabled=b; } bool spacelessEnabled() const { return m_spacelessEnabled && m_spacelessIntf; } @@ -562,7 +560,7 @@ class TemplateContextImpl : public TemplateContext // index related functions void openSubIndex(const QCString &indexName); void closeSubIndex(const QCString &indexName); - void addIndexEntry(const QCString &indexName,const QValueList &arguments); + void addIndexEntry(const QCString &indexName,const std::vector &arguments); private: const TemplateEngine *m_engine = 0; @@ -1483,11 +1481,11 @@ class ExprAstFunctionVariable : public ExprAst } virtual TemplateVariant resolve(TemplateContext *c) { - QValueList args; + std::vector args; for (uint i=0;iresolve(c); - args.append(v); + args.push_back(v); } TemplateVariant v = m_var->resolve(c); if (v.type()==TemplateVariant::Function) @@ -2607,7 +2605,7 @@ static void getPathListFunc(TemplateStructIntf *entry,TemplateList *list) list->append(entry); } -static TemplateVariant getPathFunc(const void *ctx, const QValueList &) +static TemplateVariant getPathFunc(const void *ctx, const std::vector &) { TemplateStruct *entry = (TemplateStruct*)ctx; TemplateList *result = TemplateList::alloc(); @@ -2615,9 +2613,9 @@ static TemplateVariant getPathFunc(const void *ctx, const QValueList &arguments) +void TemplateContextImpl::addIndexEntry(const QCString &indexName,const std::vector &arguments) { - QValueListConstIterator it = arguments.begin(); + auto it = arguments.begin(); //printf("TemplateContextImpl::addIndexEntry(%s)\n",indexName.data()); //while (it!=arguments.end()) //{ @@ -2759,7 +2757,7 @@ class TemplateNodeVariable : public TemplateNode TemplateVariant v = m_var->resolve(c); if (v.type()==TemplateVariant::Function) { - v = v.call(QValueList()); + v = v.call(std::vector()); } if (ci->escapeIntf() && !v.raw()) { @@ -2843,7 +2841,7 @@ template class TemplateNodeCreator : public TemplateNode if (d.exists()) { bool ok = d.mkdir(fileName.mid(j,i-j)); - if (!ok) + if (!ok) { err("Failed to create directory '%s'\n",(fileName.mid(j,i-j)).data()); break; @@ -3217,7 +3215,7 @@ class TemplateNodeFor : public TemplateNodeCreator else { m_vars = split(data.left(i),","); - if (m_vars.count()==0) + if (m_vars.size()==0) { parser->warn(m_templateName,line,"for needs at least one iterator variable"); } @@ -3270,7 +3268,7 @@ class TemplateNodeFor : public TemplateNodeCreator TemplateVariant v = m_expr->resolve(c); if (v.type()==TemplateVariant::Function) { - v = v.call(QValueList()); + v = v.call(std::vector()); } const TemplateListIntf *list = v.toList(); if (list) @@ -3287,8 +3285,9 @@ class TemplateNodeFor : public TemplateNodeCreator const TemplateVariant *parentLoop = c->getRef("forloop"); uint index = m_reversed ? listSize-1 : 0; TemplateListIntf::ConstIterator *it = list->createIterator(); + TemplateVariant ve; for (m_reversed ? it->toLast() : it->toFirst(); - (it->current(v)); + (it->current(ve)); m_reversed ? it->toPrev() : it->toNext()) { TemplateAutoRef s(TemplateStruct::alloc()); @@ -3304,19 +3303,19 @@ class TemplateNodeFor : public TemplateNodeCreator // add variables for this loop to the context //obj->addVariableToContext(index,m_vars,c); uint vi=0; - if (m_vars.count()==1) // loop variable represents an item + if (m_vars.size()==1) // loop variable represents an item { - c->set(m_vars[vi++],v); + c->set(m_vars[vi++],ve); } - else if (m_vars.count()>1 && v.type()==TemplateVariant::Struct) + else if (m_vars.size()>1 && ve.type()==TemplateVariant::Struct) // loop variables represent elements in a list item { - for (uint i=0;iset(m_vars[vi],v.toStruct()->get(m_vars[vi])); + c->set(m_vars[vi],ve.toStruct()->get(m_vars[vi])); } } - for (;viset(m_vars[vi],TemplateVariant()); } @@ -3339,7 +3338,7 @@ class TemplateNodeFor : public TemplateNodeCreator private: bool m_reversed = false; ExprAst *m_expr = 0; - QValueList m_vars; + std::vector m_vars; TemplateNodeList m_loopNodes; TemplateNodeList m_emptyNodes; }; @@ -3766,7 +3765,7 @@ class TemplateNodeTree : public TemplateNodeCreator { delete m_treeExpr; } - static TemplateVariant renderChildrenStub(const void *ctx, const QValueList &) + static TemplateVariant renderChildrenStub(const void *ctx, const std::vector &) { return TemplateVariant(((TreeContext*)ctx)->object-> renderChildren((const TreeContext*)ctx),TRUE); @@ -3866,8 +3865,8 @@ class TemplateNodeIndexEntry : public TemplateNodeCreator args = split(data," "); - QValueListIterator it = args.begin(); + std::vector args = split(data," "); + auto it = args.begin(); if (it==args.end() || (*it).find('=')!=-1) { parser->warn(parser->templateName(),line,"Missing name for indexentry tag"); @@ -3906,10 +3905,10 @@ class TemplateNodeIndexEntry : public TemplateNodeCreatorsetLocation(m_templateName,m_line); QListIterator it(m_args); Mapping *mapping; - QValueList list; + std::vector list; for (it.toFirst();(mapping=it.current());++it) { - list.append(TemplateKeyValue(mapping->name,mapping->value->resolve(c))); + list.push_back(TemplateKeyValue(mapping->name,mapping->value->resolve(c))); } ci->addIndexEntry(m_name,list); } @@ -4012,8 +4011,8 @@ class TemplateNodeWith : public TemplateNodeCreator m_args.setAutoDelete(TRUE); ExpressionParser expParser(parser,line); QCString filteredData = removeSpacesAroundEquals(data); - QValueList args = split(filteredData," "); - QValueListIterator it = args.begin(); + std::vector args = split(filteredData," "); + auto it = args.begin(); while (it!=args.end()) { QCString arg = *it; @@ -4075,8 +4074,8 @@ class TemplateNodeCycle : public TemplateNodeCreator m_args.setAutoDelete(TRUE); m_index=0; ExpressionParser expParser(parser,line); - QValueList args = split(data," "); - QValueListIterator it = args.begin(); + std::vector args = split(data," "); + auto it = args.begin(); while (it!=args.end()) { ExprAst *expr = expParser.parse(*it); @@ -4101,7 +4100,7 @@ class TemplateNodeCycle : public TemplateNodeCreator TemplateVariant v = m_args.at(m_index)->resolve(c); if (v.type()==TemplateVariant::Function) { - v = v.call(QValueList()); + v = v.call(std::vector()); } if (ci->escapeIntf() && !v.raw()) { diff --git a/src/template.h b/src/template.h index 40bd43f..c9e9041 100644 --- a/src/template.h +++ b/src/template.h @@ -17,7 +17,7 @@ #define TEMPLATE_H #include -#include +#include class FTextStream; @@ -95,12 +95,12 @@ class TemplateVariant { public: /** Callback type to use when creating a delegate from a function. */ - typedef TemplateVariant (*StubType)(const void *obj, const QValueList &args); + typedef TemplateVariant (*StubType)(const void *obj, const std::vector &args); Delegate() : m_objectPtr(0) , m_stubPtr(0) {} /** Creates a delegate given an object. The method to call is passed as a template parameter */ - template &) const> + template &) const> static Delegate fromMethod(const T* objectPtr) { Delegate d; @@ -118,7 +118,7 @@ class TemplateVariant } /** Invokes the function/method stored in the delegate */ - TemplateVariant operator()(const QValueList &args) const + TemplateVariant operator()(const std::vector &args) const { return (*m_stubPtr)(m_objectPtr, args); } @@ -127,8 +127,8 @@ class TemplateVariant const void* m_objectPtr; StubType m_stubPtr; - template &) const> - static TemplateVariant methodStub(const void* objectPtr, const QValueList &args) + template &) const> + static TemplateVariant methodStub(const void* objectPtr, const std::vector &args) { T* p = (T*)(objectPtr); return (p->*TMethod)(args); @@ -269,7 +269,7 @@ class TemplateVariant /** Return the result of apply this function with \a args. * Returns an empty string if the variant type is not a function. */ - TemplateVariant call(const QValueList &args) + TemplateVariant call(const std::vector &args) { if (m_type==Function) return m_delegate(args); return TemplateVariant(); diff --git a/src/util.cpp b/src/util.cpp index 90b4af1..3075d1b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1982,8 +1982,10 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope, //printf("linkify='%s'\n",text); static QRegExp regExp("[a-z_A-Z\\x80-\\xFF][~!a-z_A-Z0-9$\\\\.:\\x80-\\xFF]*"); static QRegExp regExpSplit("(?!:),"); + if (text==0) return; QCString txtStr=text; int strLen = txtStr.length(); + if (strLen==0) return; //printf("linkifyText scope=%s fileScope=%s strtxt=%s strlen=%d external=%d\n", // scope?scope->name().data():"", // fileScope?fileScope->name().data():"", @@ -1993,7 +1995,6 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope, int newIndex; int skipIndex=0; int floatingIndex=0; - if (strLen==0) return; // read a word from the text string while ((newIndex=regExp.match(txtStr,index,&matchLen))!=-1) { -- cgit v0.12