Commit 6dbf32d5 authored by Dimitri van Heesch's avatar Dimitri van Heesch

More template and context enhancements

parent 4d5ddf77
This diff is collapsed.
...@@ -25,6 +25,7 @@ class GroupDef; ...@@ -25,6 +25,7 @@ class GroupDef;
class GroupList; class GroupList;
struct IncludeInfo; struct IncludeInfo;
class MemberList; class MemberList;
class MemberSDict;
class MemberDef; class MemberDef;
struct Argument; struct Argument;
class ArgumentList; class ArgumentList;
...@@ -650,6 +651,7 @@ class MemberListContext : public TemplateListIntf ...@@ -650,6 +651,7 @@ class MemberListContext : public TemplateListIntf
{ {
public: public:
MemberListContext(const MemberList *ml); MemberListContext(const MemberList *ml);
MemberListContext(MemberSDict *ml,bool doSort);
~MemberListContext(); ~MemberListContext();
// TemplateListIntf // TemplateListIntf
......
...@@ -1050,6 +1050,13 @@ void Definition::setBodyDef(FileDef *fd) ...@@ -1050,6 +1050,13 @@ void Definition::setBodyDef(FileDef *fd)
m_impl->body->fileDef=fd; m_impl->body->fileDef=fd;
} }
bool Definition::hasSources() const
{
return m_impl->body && m_impl->body->startLine!=-1 &&
m_impl->body->endLine>=m_impl->body->startLine &&
m_impl->body->fileDef;
}
/*! Write code of this definition into the documentation */ /*! Write code of this definition into the documentation */
void Definition::writeInlineCode(OutputList &ol,const char *scopeName) void Definition::writeInlineCode(OutputList &ol,const char *scopeName)
{ {
...@@ -1057,9 +1064,7 @@ void Definition::writeInlineCode(OutputList &ol,const char *scopeName) ...@@ -1057,9 +1064,7 @@ void Definition::writeInlineCode(OutputList &ol,const char *scopeName)
ol.pushGeneratorState(); ol.pushGeneratorState();
//printf("Source Fragment %s: %d-%d bodyDef=%p\n",name().data(), //printf("Source Fragment %s: %d-%d bodyDef=%p\n",name().data(),
// m_startBodyLine,m_endBodyLine,m_bodyDef); // m_startBodyLine,m_endBodyLine,m_bodyDef);
if (inlineSources && if (inlineSources && hasSources())
m_impl->body && m_impl->body->startLine!=-1 &&
m_impl->body->endLine>=m_impl->body->startLine && m_impl->body->fileDef)
{ {
QCString codeFragment; QCString codeFragment;
int actualStart=m_impl->body->startLine,actualEnd=m_impl->body->endLine; int actualStart=m_impl->body->startLine,actualEnd=m_impl->body->endLine;
......
...@@ -137,18 +137,18 @@ class Definition : public DefinitionIntf ...@@ -137,18 +137,18 @@ class Definition : public DefinitionIntf
virtual QCString getSourceAnchor() const; virtual QCString getSourceAnchor() const;
/*! Returns the detailed description of this definition */ /*! Returns the detailed description of this definition */
QCString documentation() const; virtual QCString documentation() const;
/*! Returns the line number at which the detailed documentation was found. */ /*! Returns the line number at which the detailed documentation was found. */
int docLine() const; int docLine() const;
/*! Returns the file in which the detailed documentation block was found. /*! Returns the file in which the detailed documentation block was found.
* This can differ from getDefFileName(). * This can differ from getDefFileName().
*/ */
QCString docFile() const; QCString docFile() const;
/*! Returns the brief description of this definition. This can include commands. */ /*! Returns the brief description of this definition. This can include commands. */
QCString briefDescription(bool abbreviate=FALSE) const; virtual QCString briefDescription(bool abbreviate=FALSE) const;
/*! Returns a plain text version of the brief description suitable for use /*! Returns a plain text version of the brief description suitable for use
* as a tool tip. * as a tool tip.
...@@ -259,6 +259,7 @@ class Definition : public DefinitionIntf ...@@ -259,6 +259,7 @@ class Definition : public DefinitionIntf
MemberSDict *getReferencedByMembers() const; MemberSDict *getReferencedByMembers() const;
bool hasSections() const; bool hasSections() const;
bool hasSources() const;
/** returns TRUE if this class has a brief description */ /** returns TRUE if this class has a brief description */
bool hasBriefDescription() const; bool hasBriefDescription() const;
......
...@@ -282,7 +282,7 @@ class HtmlGenerator : public OutputGenerator ...@@ -282,7 +282,7 @@ class HtmlGenerator : public OutputGenerator
//{ t << "<tr><td valign=\"top\"><em>"; } //{ t << "<tr><td valign=\"top\"><em>"; }
{ t << "<tr><td class=\"fieldname\"><em>"; } { t << "<tr><td class=\"fieldname\"><em>"; }
void endDescTableTitle() void endDescTableTitle()
{ t << "</em>&nbsp;</td>"; } { t << "</em>&#160;</td>"; }
void startDescTableData() void startDescTableData()
//{ t << "<td>" << endl; } //{ t << "<td>" << endl; }
{ t << "<td class=\"fielddoc\">" << endl; } { t << "<td class=\"fielddoc\">" << endl; }
......
...@@ -449,27 +449,6 @@ static void writeTemplatePrefix(OutputList &ol,ArgumentList *al) ...@@ -449,27 +449,6 @@ static void writeTemplatePrefix(OutputList &ol,ArgumentList *al)
ol.docify("> "); ol.docify("> ");
} }
QCString extractDirection(QCString &docs)
{
QRegExp re("\\[[^\\]]+\\]"); // [...]
int l=0;
if (re.match(docs,0,&l)==0)
{
int inPos = docs.find("in", 1,FALSE);
int outPos = docs.find("out",1,FALSE);
bool input = inPos!=-1 && inPos<l;
bool output = outPos!=-1 && outPos<l;
if (input || output) // in,out attributes
{
docs = docs.mid(l); // strip attributes
if (input && output) return "[in,out]";
else if (input) return "[in]";
else if (output) return "[out]";
}
}
return QCString();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -4985,3 +4964,33 @@ void combineDeclarationAndDefinition(MemberDef *mdec,MemberDef *mdef) ...@@ -4985,3 +4964,33 @@ void combineDeclarationAndDefinition(MemberDef *mdec,MemberDef *mdef)
} }
} }
QCString MemberDef::briefDescription(bool abbr) const
{
if (m_impl->templateMaster)
{
return m_impl->templateMaster->briefDescription(abbr);
}
else
{
return Definition::briefDescription(abbr);
}
}
QCString MemberDef::documentation() const
{
if (m_impl->templateMaster)
{
return m_impl->templateMaster->documentation();
}
else
{
return Definition::documentation();
}
}
const ArgumentList *MemberDef::typeConstraints() const
{
return m_impl->typeConstraints;
}
...@@ -245,6 +245,14 @@ class MemberDef : public Definition ...@@ -245,6 +245,14 @@ class MemberDef : public Definition
QCString getDeclType() const; QCString getDeclType() const;
void getLabels(QStrList &sl,Definition *container) const; void getLabels(QStrList &sl,Definition *container) const;
const ArgumentList *typeConstraints() const;
// overrules
QCString documentation() const;
QCString briefDescription(bool abbr=FALSE) const;
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
// ---- setters ----- // ---- setters -----
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
......
...@@ -104,8 +104,7 @@ class TemplateVariant::Private ...@@ -104,8 +104,7 @@ class TemplateVariant::Private
bool boolVal; bool boolVal;
const TemplateStructIntf *strukt; const TemplateStructIntf *strukt;
const TemplateListIntf *list; const TemplateListIntf *list;
FuncType func; Delegate delegate;
const void *obj;
bool raw; bool raw;
}; };
...@@ -158,12 +157,11 @@ TemplateVariant::TemplateVariant(const TemplateListIntf *l) ...@@ -158,12 +157,11 @@ TemplateVariant::TemplateVariant(const TemplateListIntf *l)
p->list = l; p->list = l;
} }
TemplateVariant::TemplateVariant(const void *obj,FuncType f) TemplateVariant::TemplateVariant(const TemplateVariant::Delegate &delegate)
{ {
p = new Private; p = new Private;
p->type = Function; p->type = Function;
p->func = f; p->delegate = delegate;
p->obj = obj;
} }
TemplateVariant::~TemplateVariant() TemplateVariant::~TemplateVariant()
...@@ -184,8 +182,7 @@ TemplateVariant::TemplateVariant(const TemplateVariant &v) ...@@ -184,8 +182,7 @@ TemplateVariant::TemplateVariant(const TemplateVariant &v)
case String: p->strVal = v.p->strVal; break; case String: p->strVal = v.p->strVal; break;
case Struct: p->strukt = v.p->strukt; break; case Struct: p->strukt = v.p->strukt; break;
case List: p->list = v.p->list; break; case List: p->list = v.p->list; break;
case Function: p->func = v.p->func; case Function: p->delegate= v.p->delegate;break;
p->obj = v.p->obj; break;
} }
} }
...@@ -201,8 +198,7 @@ TemplateVariant &TemplateVariant::operator=(const TemplateVariant &v) ...@@ -201,8 +198,7 @@ TemplateVariant &TemplateVariant::operator=(const TemplateVariant &v)
case String: p->strVal = v.p->strVal; break; case String: p->strVal = v.p->strVal; break;
case Struct: p->strukt = v.p->strukt; break; case Struct: p->strukt = v.p->strukt; break;
case List: p->list = v.p->list; break; case List: p->list = v.p->list; break;
case Function: p->func = v.p->func; case Function: p->delegate= v.p->delegate;break;
p->obj = v.p->obj; break;
} }
return *this; return *this;
} }
...@@ -305,7 +301,7 @@ const TemplateListIntf *TemplateVariant::toList() const ...@@ -305,7 +301,7 @@ const TemplateListIntf *TemplateVariant::toList() const
TemplateVariant TemplateVariant::call(const QValueList<TemplateVariant> &args) TemplateVariant TemplateVariant::call(const QValueList<TemplateVariant> &args)
{ {
if (p->type==Function) return p->func(p->obj,args); if (p->type==Function) return p->delegate(args);
return TemplateVariant(); return TemplateVariant();
} }
...@@ -766,14 +762,12 @@ class FilterDivisibleBy ...@@ -766,14 +762,12 @@ class FilterDivisibleBy
public: public:
static TemplateVariant apply(const TemplateVariant &v,const TemplateVariant &n) static TemplateVariant apply(const TemplateVariant &v,const TemplateVariant &n)
{ {
printf("FilterDivisibleBy::apply()\n");
if (!v.isValid() || !n.isValid()) if (!v.isValid() || !n.isValid())
{ {
return TemplateVariant(); return TemplateVariant();
} }
if (v.type()==TemplateVariant::Integer && n.type()==TemplateVariant::Integer) if (v.type()==TemplateVariant::Integer && n.type()==TemplateVariant::Integer)
{ {
printf("FilterDivisibleBy(%d,%d)=%d",v.toInt(),n.toInt(),(v.toInt()%n.toInt())==0);
return TemplateVariant((v.toInt()%n.toInt())==0); return TemplateVariant((v.toInt()%n.toInt())==0);
} }
else else
...@@ -2045,10 +2039,13 @@ class TemplateNodeMsg : public TemplateNodeCreator<TemplateNodeMsg> ...@@ -2045,10 +2039,13 @@ class TemplateNodeMsg : public TemplateNodeCreator<TemplateNodeMsg>
TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c); TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
TemplateEscapeIntf *escIntf = ci->escapeIntf(); TemplateEscapeIntf *escIntf = ci->escapeIntf();
ci->setEscapeIntf(0); // avoid escaping things we send to standard out ci->setEscapeIntf(0); // avoid escaping things we send to standard out
bool enable = ci->spacelessEnabled();
ci->enableSpaceless(FALSE);
FTextStream ts(stdout); FTextStream ts(stdout);
m_nodes.render(ts,c); m_nodes.render(ts,c);
ts << endl; ts << endl;
ci->setEscapeIntf(escIntf); ci->setEscapeIntf(escIntf);
ci->enableSpaceless(enable);
} }
private: private:
TemplateNodeList m_nodes; TemplateNodeList m_nodes;
...@@ -2423,7 +2420,8 @@ class TemplateNodeTree : public TemplateNodeCreator<TemplateNodeTree> ...@@ -2423,7 +2420,8 @@ class TemplateNodeTree : public TemplateNodeCreator<TemplateNodeTree>
if (list && list->count()>0) // non-empty list if (list && list->count()>0) // non-empty list
{ {
TreeContext childCtx(this,list,ctx->templateCtx); TreeContext childCtx(this,list,ctx->templateCtx);
TemplateVariant children(&childCtx,renderChildrenStub); // TemplateVariant children(&childCtx,renderChildrenStub);
TemplateVariant children(TemplateVariant::Delegate::fromFunction(&childCtx,renderChildrenStub));
children.setRaw(TRUE); children.setRaw(TRUE);
c->set("children",children); c->set("children",children);
m_treeNodes.render(ss,c); m_treeNodes.render(ss,c);
......
...@@ -26,7 +26,7 @@ class TemplateEngine; ...@@ -26,7 +26,7 @@ class TemplateEngine;
* When the template engine encounters a variable, it evaluates that variable and * When the template engine encounters a variable, it evaluates that variable and
* replaces it with the result. Variable names consist of any combination of * replaces it with the result. Variable names consist of any combination of
* alphanumeric characters and the underscore ("_"). * alphanumeric characters and the underscore ("_").
* Use a dot (.) to access attributes of a variable. * Use a dot (.) to access attributes of a structured variable.
* *
* One can modify variables for display by using \b filters, for example: * One can modify variables for display by using \b filters, for example:
* `{{ value|default:"nothing" }}` * `{{ value|default:"nothing" }}`
...@@ -40,28 +40,33 @@ class TemplateEngine; ...@@ -40,28 +40,33 @@ class TemplateEngine;
* *
* Supported Django tags: * Supported Django tags:
* - `for ... empty ... endfor` * - `for ... empty ... endfor`
* - `if ... else ... endif` * - `if ... else ... endif`
* - `block ... endblock` * - `block ... endblock`
* - `extend` * - `extend`
* - `include` * - `include`
* - `with ... endwith` * - `with ... endwith`
* - `spaceless ... endspaceless` * - `spaceless ... endspaceless`
* - `cycle`
*
* Extension tags:
* - `create` which instantiates a template and writes the result to a file.
* The syntax is `{% create 'filename' from 'template' %}`.
* - `recursetree`
* - `markers`
* - `msg` ... `endmsg`
* - `set`
* *
* Supported Django filters: * Supported Django filters:
* - `default` * - `default`
* - `length` * - `length`
* - `add` * - `add`
* * - `divisibleby`
* Extension tags:
* - `create` which instantiates a template and writes the result to a file.
* The syntax is `{% create 'filename' from 'template' %}`.
* - `recursetree`
* - `markers`
* *
* Extension filters: * Extension filters:
* - `stripPath` * - `stripPath`
* - `nowrap` * - `nowrap`
* - `prepend` * - `prepend`
* - `append`
* *
* @{ * @{
*/ */
...@@ -70,8 +75,50 @@ class TemplateEngine; ...@@ -70,8 +75,50 @@ class TemplateEngine;
class TemplateVariant class TemplateVariant
{ {
public: public:
/** Signature of the callback function, used for function type variants */ /** @brief Helper class to create a delegate that can store a function/method call. */
typedef TemplateVariant (*FuncType)(const void *obj, const QValueList<TemplateVariant> &args); class Delegate
{
public:
/** Callback type to use when creating a delegate from a function. */
typedef TemplateVariant (*StubType)(const void *obj, const QValueList<TemplateVariant> &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 <class T, TemplateVariant (T::*TMethod)(const QValueList<TemplateVariant> &) const>
static Delegate fromMethod(const T* objectPtr)
{
Delegate d;
d.m_objectPtr = objectPtr;
d.m_stubPtr = &methodStub<T, TMethod>;
return d;
}
/** Creates a delegate given an object, and a plain function. */
static Delegate fromFunction(const void *obj,StubType func)
{
Delegate d;
d.m_objectPtr = obj;
d.m_stubPtr = func;
return d;
}
/** Invokes the function/method stored in the delegate */
TemplateVariant operator()(const QValueList<TemplateVariant> &args) const
{
return (*m_stubPtr)(m_objectPtr, args);
}
private:
const void* m_objectPtr;
StubType m_stubPtr;
template <class T, TemplateVariant (T::*TMethod)(const QValueList<TemplateVariant> &) const>
static TemplateVariant methodStub(const void* objectPtr, const QValueList<TemplateVariant> &args)
{
T* p = (T*)(objectPtr);
return (p->*TMethod)(args);
}
};
/** Types of data that can be stored in a TemplateVariant */ /** Types of data that can be stored in a TemplateVariant */
enum Type { None, Bool, Integer, String, Struct, List, Function }; enum Type { None, Bool, Integer, String, Struct, List, Function };
...@@ -109,13 +156,14 @@ class TemplateVariant ...@@ -109,13 +156,14 @@ class TemplateVariant
*/ */
TemplateVariant(const TemplateListIntf *l); TemplateVariant(const TemplateListIntf *l);
/** Constructs a new variant which represents a function /** Constructs a new variant which represents a method call
* @param[in] obj Opaque user defined pointer, which * @param[in] delegate Delegate object to invoke when
* is passed back when call() is invoked.
* @param[in] func Callback function to invoke when
* calling call() on this variant. * calling call() on this variant.
* @note Use TemplateVariant::Delegate::fromMethod() and
* TemplateVariant::Delegate::fromFunction() to create
* Delegate objects.
*/ */
TemplateVariant(const void *obj,FuncType func); TemplateVariant(const Delegate &delegate);
/** Destroys the Variant object */ /** Destroys the Variant object */
~TemplateVariant(); ~TemplateVariant();
...@@ -167,7 +215,7 @@ class TemplateVariant ...@@ -167,7 +215,7 @@ class TemplateVariant
* @see setRaw() * @see setRaw()
*/ */
bool raw() const; bool raw() const;
private: private:
class Private; class Private;
Private *p; Private *p;
......
...@@ -8057,3 +8057,26 @@ bool classVisibleInIndex(ClassDef *cd) ...@@ -8057,3 +8057,26 @@ bool classVisibleInIndex(ClassDef *cd)
return (allExternals && cd->isLinkable()) || cd->isLinkableInProject(); return (allExternals && cd->isLinkable()) || cd->isLinkableInProject();
} }
//----------------------------------------------------------------------------
QCString extractDirection(QCString &docs)
{
QRegExp re("\\[[^\\]]+\\]"); // [...]
int l=0;
if (re.match(docs,0,&l)==0)
{
int inPos = docs.find("in", 1,FALSE);
int outPos = docs.find("out",1,FALSE);
bool input = inPos!=-1 && inPos<l;
bool output = outPos!=-1 && outPos<l;
if (input || output) // in,out attributes
{
docs = docs.mid(l); // strip attributes
if (input && output) return "[in,out]";
else if (input) return "[in]";
else if (output) return "[out]";
}
}
return QCString();
}
...@@ -446,7 +446,7 @@ uint getUtf8Code( const QCString& s, int idx ); ...@@ -446,7 +446,7 @@ uint getUtf8Code( const QCString& s, int idx );
uint getUtf8CodeToLower( const QCString& s, int idx ); uint getUtf8CodeToLower( const QCString& s, int idx );
uint getUtf8CodeToUpper( const QCString& s, int idx ); uint getUtf8CodeToUpper( const QCString& s, int idx );
QCString extractDirection(QCString &docs);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment