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;
class GroupList;
struct IncludeInfo;
class MemberList;
class MemberSDict;
class MemberDef;
struct Argument;
class ArgumentList;
......@@ -650,6 +651,7 @@ class MemberListContext : public TemplateListIntf
{
public:
MemberListContext(const MemberList *ml);
MemberListContext(MemberSDict *ml,bool doSort);
~MemberListContext();
// TemplateListIntf
......
......@@ -1050,6 +1050,13 @@ void Definition::setBodyDef(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 */
void Definition::writeInlineCode(OutputList &ol,const char *scopeName)
{
......@@ -1057,9 +1064,7 @@ void Definition::writeInlineCode(OutputList &ol,const char *scopeName)
ol.pushGeneratorState();
//printf("Source Fragment %s: %d-%d bodyDef=%p\n",name().data(),
// m_startBodyLine,m_endBodyLine,m_bodyDef);
if (inlineSources &&
m_impl->body && m_impl->body->startLine!=-1 &&
m_impl->body->endLine>=m_impl->body->startLine && m_impl->body->fileDef)
if (inlineSources && hasSources())
{
QCString codeFragment;
int actualStart=m_impl->body->startLine,actualEnd=m_impl->body->endLine;
......
......@@ -137,7 +137,7 @@ class Definition : public DefinitionIntf
virtual QCString getSourceAnchor() const;
/*! 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. */
int docLine() const;
......@@ -148,7 +148,7 @@ class Definition : public DefinitionIntf
QCString docFile() const;
/*! 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
* as a tool tip.
......@@ -259,6 +259,7 @@ class Definition : public DefinitionIntf
MemberSDict *getReferencedByMembers() const;
bool hasSections() const;
bool hasSources() const;
/** returns TRUE if this class has a brief description */
bool hasBriefDescription() const;
......
......@@ -282,7 +282,7 @@ class HtmlGenerator : public OutputGenerator
//{ t << "<tr><td valign=\"top\"><em>"; }
{ t << "<tr><td class=\"fieldname\"><em>"; }
void endDescTableTitle()
{ t << "</em>&nbsp;</td>"; }
{ t << "</em>&#160;</td>"; }
void startDescTableData()
//{ t << "<td>" << endl; }
{ t << "<td class=\"fielddoc\">" << endl; }
......
......@@ -449,27 +449,6 @@ static void writeTemplatePrefix(OutputList &ol,ArgumentList *al)
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)
}
}
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
QCString getDeclType() const;
void getLabels(QStrList &sl,Definition *container) const;
const ArgumentList *typeConstraints() const;
// overrules
QCString documentation() const;
QCString briefDescription(bool abbr=FALSE) const;
//-----------------------------------------------------------------------------------
// ---- setters -----
//-----------------------------------------------------------------------------------
......
......@@ -104,8 +104,7 @@ class TemplateVariant::Private
bool boolVal;
const TemplateStructIntf *strukt;
const TemplateListIntf *list;
FuncType func;
const void *obj;
Delegate delegate;
bool raw;
};
......@@ -158,12 +157,11 @@ TemplateVariant::TemplateVariant(const TemplateListIntf *l)
p->list = l;
}
TemplateVariant::TemplateVariant(const void *obj,FuncType f)
TemplateVariant::TemplateVariant(const TemplateVariant::Delegate &delegate)
{
p = new Private;
p->type = Function;
p->func = f;
p->obj = obj;
p->delegate = delegate;
}
TemplateVariant::~TemplateVariant()
......@@ -184,8 +182,7 @@ TemplateVariant::TemplateVariant(const TemplateVariant &v)
case String: p->strVal = v.p->strVal; break;
case Struct: p->strukt = v.p->strukt; break;
case List: p->list = v.p->list; break;
case Function: p->func = v.p->func;
p->obj = v.p->obj; break;
case Function: p->delegate= v.p->delegate;break;
}
}
......@@ -201,8 +198,7 @@ TemplateVariant &TemplateVariant::operator=(const TemplateVariant &v)
case String: p->strVal = v.p->strVal; break;
case Struct: p->strukt = v.p->strukt; break;
case List: p->list = v.p->list; break;
case Function: p->func = v.p->func;
p->obj = v.p->obj; break;
case Function: p->delegate= v.p->delegate;break;
}
return *this;
}
......@@ -305,7 +301,7 @@ const TemplateListIntf *TemplateVariant::toList() const
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();
}
......@@ -766,14 +762,12 @@ class FilterDivisibleBy
public:
static TemplateVariant apply(const TemplateVariant &v,const TemplateVariant &n)
{
printf("FilterDivisibleBy::apply()\n");
if (!v.isValid() || !n.isValid())
{
return TemplateVariant();
}
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);
}
else
......@@ -2045,10 +2039,13 @@ class TemplateNodeMsg : public TemplateNodeCreator<TemplateNodeMsg>
TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
TemplateEscapeIntf *escIntf = ci->escapeIntf();
ci->setEscapeIntf(0); // avoid escaping things we send to standard out
bool enable = ci->spacelessEnabled();
ci->enableSpaceless(FALSE);
FTextStream ts(stdout);
m_nodes.render(ts,c);
ts << endl;
ci->setEscapeIntf(escIntf);
ci->enableSpaceless(enable);
}
private:
TemplateNodeList m_nodes;
......@@ -2423,7 +2420,8 @@ class TemplateNodeTree : public TemplateNodeCreator<TemplateNodeTree>
if (list && list->count()>0) // non-empty list
{
TreeContext childCtx(this,list,ctx->templateCtx);
TemplateVariant children(&childCtx,renderChildrenStub);
// TemplateVariant children(&childCtx,renderChildrenStub);
TemplateVariant children(TemplateVariant::Delegate::fromFunction(&childCtx,renderChildrenStub));
children.setRaw(TRUE);
c->set("children",children);
m_treeNodes.render(ss,c);
......
......@@ -26,7 +26,7 @@ class TemplateEngine;
* When the template engine encounters a variable, it evaluates that variable and
* replaces it with the result. Variable names consist of any combination of
* 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:
* `{{ value|default:"nothing" }}`
......@@ -46,22 +46,27 @@ class TemplateEngine;
* - `include`
* - `with ... endwith`
* - `spaceless ... endspaceless`
*
* Supported Django filters:
* - `default`
* - `length`
* - `add`
* - `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:
* - `default`
* - `length`
* - `add`
* - `divisibleby`
*
* Extension filters:
* - `stripPath`
* - `nowrap`
* - `prepend`
* - `append`
*
* @{
*/
......@@ -70,8 +75,50 @@ class TemplateEngine;
class TemplateVariant
{
public:
/** Signature of the callback function, used for function type variants */
typedef TemplateVariant (*FuncType)(const void *obj, const QValueList<TemplateVariant> &args);
/** @brief Helper class to create a delegate that can store a function/method call. */
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 */
enum Type { None, Bool, Integer, String, Struct, List, Function };
......@@ -109,13 +156,14 @@ class TemplateVariant
*/
TemplateVariant(const TemplateListIntf *l);
/** Constructs a new variant which represents a function
* @param[in] obj Opaque user defined pointer, which
* is passed back when call() is invoked.
* @param[in] func Callback function to invoke when
/** Constructs a new variant which represents a method call
* @param[in] delegate Delegate object to invoke when
* 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 */
~TemplateVariant();
......
......@@ -8057,3 +8057,26 @@ bool classVisibleInIndex(ClassDef *cd)
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 );
uint getUtf8CodeToLower( const QCString& s, int idx );
uint getUtf8CodeToUpper( const QCString& s, int idx );
QCString extractDirection(QCString &docs);
#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