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 2722 of file template.cpp.

Constructor & Destructor Documentation

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

Definition at line 2725 of file template.cpp.

2725  :
2727  {
2728  m_ifGuardedNodes.setAutoDelete(TRUE);
2729  TRACE(("{TemplateNodeIf(%s)\n",data.data()));
2730  if (data.isEmpty())
2731  {
2732  parser->warn(m_templateName,line,"missing argument for if tag");
2733  }
2734  QStrList stopAt;
2735  stopAt.append("endif");
2736  stopAt.append("elif");
2737  stopAt.append("else");
2738 
2739  // if 'nodes'
2740  GuardedNodes *guardedNodes = new GuardedNodes;
2741  ExpressionParser ex(parser,line);
2742  guardedNodes->line = line;
2743  guardedNodes->guardAst = ex.parse(data);
2744  parser->parse(this,line,stopAt,guardedNodes->trueNodes);
2745  m_ifGuardedNodes.append(guardedNodes);
2746  TemplateToken *tok = parser->takeNextToken();
2747 
2748  // elif 'nodes'
2749  while (tok && tok->data.left(5)=="elif ")
2750  {
2751  ExpressionParser ex(parser,line);
2752  guardedNodes = new GuardedNodes;
2753  guardedNodes->line = tok->line;
2754  guardedNodes->guardAst = ex.parse(tok->data.mid(5));
2755  parser->parse(this,tok->line,stopAt,guardedNodes->trueNodes);
2756  m_ifGuardedNodes.append(guardedNodes);
2757  // proceed to the next token
2758  delete tok;
2759  tok = parser->takeNextToken();
2760  }
2761 
2762  // else 'nodes'
2763  if (tok && tok->data=="else")
2764  {
2765  stopAt.removeLast(); // remove "else"
2766  stopAt.removeLast(); // remove "elif"
2767  parser->parse(this,line,stopAt,m_falseNodes);
2768  parser->removeNextToken(); // skip over endif
2769  }
2770  delete tok;
2771  TRACE(("}TemplateNodeIf(%s)\n",data.data()));
2772  }
bool isEmpty() const
Definition: qcstring.h:189
QCString left(uint len) const
Definition: qcstring.cpp:213
Class representing a lexical token in a template.
Definition: template.cpp:2226
QCString data
Definition: template.cpp:2232
TemplateNode * parent()
Definition: template.cpp:1647
TemplateNodeList m_falseNodes
Definition: template.cpp:2818
QList< GuardedNodes > m_ifGuardedNodes
Definition: template.cpp:2817
void append(const type *d)
Definition: qinternallist.h:61
const char * data() const
Definition: qcstring.h:207
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
void line(double t, double *p, double &x, double &y, double &z)
Recursive decent parser for Django style template expressions.
Definition: template.cpp:1680
#define TRACE(x)
Definition: template.cpp:43
bool removeLast()
Definition: qinternallist.h:68
const bool TRUE
Definition: qglobal.h:371
TemplateNodeIf::~TemplateNodeIf ( )
inline

Definition at line 2773 of file template.cpp.

2774  {
2775  }

Member Function Documentation

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

Implements TemplateNode.

Definition at line 2777 of file template.cpp.

2778  {
2779  TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
2780  if (ci==0) return; // should not happen
2782  //printf("TemplateNodeIf::render #trueNodes=%d #falseNodes=%d\n",m_trueNodes.count(),m_falseNodes.count());
2783  bool processed=FALSE;
2785  GuardedNodes *nodes;
2786  for (li.toFirst();(nodes=li.current()) && !processed;++li)
2787  {
2788  if (nodes->guardAst)
2789  {
2790  TemplateVariant guardValue = nodes->guardAst->resolve(c);
2791  if (guardValue.toBool()) // render nodes for the first guard that evaluated to 'true'
2792  {
2793  nodes->trueNodes.render(ts,c);
2794  processed=TRUE;
2795  }
2796  }
2797  else
2798  {
2799  ci->warn(m_templateName,nodes->line,"invalid expression for if/elif");
2800  }
2801  }
2802  if (!processed)
2803  {
2804  // all guards are false, render 'else' nodes
2805  m_falseNodes.render(ts,c);
2806  }
2807  }
void render(FTextStream &ts, TemplateContext *c)
Definition: template.cpp:2246
Internal class representing the implementation of a template context.
Definition: template.cpp:511
const bool FALSE
Definition: qglobal.h:370
bool toBool() const
Definition: template.cpp:207
#define nodes
TemplateNodeList m_falseNodes
Definition: template.cpp:2818
QList< GuardedNodes > m_ifGuardedNodes
Definition: template.cpp:2817
Variant type which can hold one value of a fixed set of types.
Definition: template.h:90
void warn(const char *fileName, int line, const char *fmt,...) const
Definition: template.cpp:2431
void setLocation(const QCString &templateName, int line)
Definition: template.cpp:540
const bool TRUE
Definition: qglobal.h:371

Member Data Documentation

TemplateNodeList TemplateNodeIf::m_falseNodes
private

Definition at line 2818 of file template.cpp.

QList<GuardedNodes> TemplateNodeIf::m_ifGuardedNodes
private

Definition at line 2817 of file template.cpp.


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