My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Attributes | List of all members
TemplateNodeIf Class Reference

Class representing an 'if' tag in a template. More...

Inheritance diagram for TemplateNodeIf:
TemplateNodeCreator< TemplateNodeIf > TemplateNode

Classes

struct  GuardedNodes
 

Public Member Functions

 TemplateNodeIf (TemplateParser *parser, TemplateNode *parent, int line, const QCString &data)
 
 ~TemplateNodeIf ()
 
void render (FTextStream &ts, TemplateContext *c)
 
- Public Member Functions inherited from TemplateNodeCreator< TemplateNodeIf >
 TemplateNodeCreator (TemplateParser *parser, TemplateNode *parent, int line)
 
TemplateImplgetTemplate ()
 
- Public Member Functions inherited from TemplateNode
 TemplateNode (TemplateNode *parent)
 
virtual ~TemplateNode ()
 
TemplateNodeparent ()
 

Private Attributes

QList< GuardedNodesm_ifGuardedNodes
 
TemplateNodeList m_falseNodes
 

Additional Inherited Members

- Static Public Member Functions inherited from TemplateNodeCreator< TemplateNodeIf >
static TemplateNodecreateInstance (TemplateParser *parser, TemplateNode *parent, int line, const QCString &data)
 
- Protected Member Functions inherited from TemplateNodeCreator< TemplateNodeIf >
void mkpath (TemplateContextImpl *ci, const QCString &fileName)
 
- Protected Attributes inherited from TemplateNodeCreator< TemplateNodeIf >
QCString m_templateName
 
int m_line
 

Detailed Description

Class representing an 'if' tag in a template.

Definition at line 2862 of file template.cpp.

Constructor & Destructor Documentation

TemplateNodeIf::TemplateNodeIf ( TemplateParser parser,
TemplateNode parent,
int  line,
const QCString &  data 
)
inline

Definition at line 2865 of file template.cpp.

References TemplateToken::data, TemplateNodeIf::GuardedNodes::guardAst, TemplateToken::line, TemplateNodeIf::GuardedNodes::line, m_falseNodes, m_ifGuardedNodes, TemplateNodeCreator< TemplateNodeIf >::m_templateName, TemplateParser::parse(), ExpressionParser::parse(), TemplateParser::removeNextToken(), TemplateParser::takeNextToken(), TRACE, TemplateNodeIf::GuardedNodes::trueNodes, and TemplateParser::warn().

:
{
m_ifGuardedNodes.setAutoDelete(TRUE);
TRACE(("{TemplateNodeIf(%s)\n",data.data()));
if (data.isEmpty())
{
parser->warn(m_templateName,line,"missing argument for if tag");
}
QStrList stopAt;
stopAt.append("endif");
stopAt.append("elif");
stopAt.append("else");
// if 'nodes'
GuardedNodes *guardedNodes = new GuardedNodes;
ExpressionParser ex(parser,line);
guardedNodes->line = line;
guardedNodes->guardAst = ex.parse(data);
parser->parse(this,line,stopAt,guardedNodes->trueNodes);
m_ifGuardedNodes.append(guardedNodes);
TemplateToken *tok = parser->takeNextToken();
// elif 'nodes'
while (tok && tok->data.left(5)=="elif ")
{
ExpressionParser ex(parser,line);
guardedNodes = new GuardedNodes;
guardedNodes->line = tok->line;
guardedNodes->guardAst = ex.parse(tok->data.mid(5));
parser->parse(this,tok->line,stopAt,guardedNodes->trueNodes);
m_ifGuardedNodes.append(guardedNodes);
// proceed to the next token
delete tok;
tok = parser->takeNextToken();
}
// else 'nodes'
if (tok && tok->data=="else")
{
stopAt.removeLast(); // remove "else"
stopAt.removeLast(); // remove "elif"
parser->parse(this,line,stopAt,m_falseNodes);
parser->removeNextToken(); // skip over endif
}
delete tok;
TRACE(("}TemplateNodeIf(%s)\n",data.data()));
}
TemplateNodeIf::~TemplateNodeIf ( )
inline

Definition at line 2913 of file template.cpp.

{
}

Member Function Documentation

void TemplateNodeIf::render ( FTextStream ts,
TemplateContext c 
)
inlinevirtual

Implements TemplateNode.

Definition at line 2917 of file template.cpp.

References TemplateNodeIf::GuardedNodes::guardAst, TemplateNodeIf::GuardedNodes::line, m_falseNodes, m_ifGuardedNodes, TemplateNodeCreator< TemplateNodeIf >::m_line, TemplateNodeCreator< TemplateNodeIf >::m_templateName, TemplateNodeList::render(), ExprAst::resolve(), TemplateContextImpl::setLocation(), TemplateVariant::toBool(), TemplateNodeIf::GuardedNodes::trueNodes, and TemplateContextImpl::warn().

{
TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
if (ci==0) return; // should not happen
//printf("TemplateNodeIf::render #trueNodes=%d #falseNodes=%d\n",m_trueNodes.count(),m_falseNodes.count());
bool processed=FALSE;
QListIterator<GuardedNodes> li(m_ifGuardedNodes);
GuardedNodes *nodes;
for (li.toFirst();(nodes=li.current()) && !processed;++li)
{
if (nodes->guardAst)
{
TemplateVariant guardValue = nodes->guardAst->resolve(c);
if (guardValue.toBool()) // render nodes for the first guard that evaluated to 'true'
{
nodes->trueNodes.render(ts,c);
processed=TRUE;
}
}
else
{
ci->warn(m_templateName,nodes->line,"invalid expression for if/elif");
}
}
if (!processed)
{
// all guards are false, render 'else' nodes
}
}

Member Data Documentation

TemplateNodeList TemplateNodeIf::m_falseNodes
private

Definition at line 2958 of file template.cpp.

Referenced by render(), and TemplateNodeIf().

QList<GuardedNodes> TemplateNodeIf::m_ifGuardedNodes
private

Definition at line 2957 of file template.cpp.

Referenced by render(), and TemplateNodeIf().


The documentation for this class was generated from the following file: