summaryrefslogtreecommitdiffstats
path: root/src/template.cpp
diff options
context:
space:
mode:
authorDimitri van Heesch <doxygen@gmail.com>2021-05-15 17:29:42 (GMT)
committerDimitri van Heesch <doxygen@gmail.com>2021-05-15 17:29:42 (GMT)
commite6f54449c5b688cdc6647f80558d67dcaa03b30d (patch)
treed2ee863521a7e62707eb8e7482eb5d410b6c4e22 /src/template.cpp
parent378be4c7f3150e6440993e0bf07235b65fe44870 (diff)
downloadDoxygen-e6f54449c5b688cdc6647f80558d67dcaa03b30d.zip
Doxygen-e6f54449c5b688cdc6647f80558d67dcaa03b30d.tar.gz
Doxygen-e6f54449c5b688cdc6647f80558d67dcaa03b30d.tar.bz2
Template engine: allow listing list and struct variables as strings
For easier debugging one can do e.g. `{% msg %}value={{ variable }}{% endmsg %}` to list the value of a variable also when it is a list or struct.
Diffstat (limited to 'src/template.cpp')
-rwxr-xr-xsrc/template.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/template.cpp b/src/template.cpp
index a9c5421..86780be 100755
--- a/src/template.cpp
+++ b/src/template.cpp
@@ -291,6 +291,17 @@ TemplateVariant TemplateStruct::get(const QCString &name) const
return it!=p->fields.end() ? it->second : TemplateVariant();
}
+StringVector TemplateStruct::fields() const
+{
+ StringVector result;
+ for (const auto &kv : p->fields)
+ {
+ result.push_back(kv.first);
+ }
+ std::sort(result.begin(),result.end());
+ return result;
+}
+
TemplateStruct *TemplateStruct::alloc()
{
return new TemplateStruct;
@@ -2360,6 +2371,7 @@ class TemplateStructWeakRef : public TemplateStructIntf
public:
TemplateStructWeakRef(TemplateStructIntf *ref) : m_ref(ref), m_refCount(0) {}
virtual TemplateVariant get(const QCString &name) const { return m_ref->get(name); }
+ virtual StringVector fields() const { return m_ref->fields(); }
virtual int addRef() { return ++m_refCount; }
virtual int release() { int count=--m_refCount; if (count<=0) { delete this; } return count; }
private:
@@ -5301,4 +5313,50 @@ void TemplateEngine::setTemplateDir(const QCString &dirName)
p->setTemplateDir(dirName);
}
+//-----------------------------------------------------------------------------------------
+
+QCString TemplateVariant::listToString() const
+{
+ QCString result="[";
+ TemplateListIntf *list = toList();
+ if (list)
+ {
+ bool first=true;
+ TemplateVariant ve;
+ TemplateListIntf::ConstIterator *it = list->createIterator();
+ for (it->toFirst();it->current(ve);it->toNext())
+ {
+ if (!first) result+=",\n";
+ result+="'"+ve.toString()+"'";
+ first=false;
+ }
+ delete it;
+ }
+ result+="]";
+ return result;
+}
+
+QCString TemplateVariant::structToString() const
+{
+ QCString result="{";
+ TemplateStructIntf *strukt = toStruct();
+ if (strukt)
+ {
+ bool first=true;
+ for (const auto &s : strukt->fields())
+ {
+ if (!first) result+=",";
+ result+=s;
+ if (dynamic_cast<TemplateStructWeakRef*>(strukt)==0) // avoid endless recursion
+ {
+ result+=":'";
+ result+=strukt->get(QCString(s)).toString();
+ result+="'";
+ }
+ first=false;
+ }
+ }
+ result+="}";
+ return result;
+}