Doxygen
TemplateNodeIf类 参考

Class representing an 'if' tag in a template 更多...

+ 类 TemplateNodeIf 继承关系图:
+ TemplateNodeIf 的协作图:

struct  GuardedNodes
 

Public 成员函数

 TemplateNodeIf (TemplateParser *parser, TemplateNode *parent, int line, const QCString &data)
 
 ~TemplateNodeIf ()
 
void render (TextStream &ts, TemplateContext *c)
 
- Public 成员函数 继承自 TemplateNodeCreator< TemplateNodeIf >
 TemplateNodeCreator (TemplateParser *parser, TemplateNode *parent, int line)
 
TemplateImplgetTemplate ()
 
- Public 成员函数 继承自 TemplateNode
 TemplateNode (TemplateNode *parent)
 
virtual ~TemplateNode ()
 
TemplateNodeparent ()
 

Private 属性

std::vector< std::unique_ptr< GuardedNodes > > m_ifGuardedNodes
 
TemplateNodeList m_falseNodes
 

额外继承的成员函数

- 静态 Public 成员函数 继承自 TemplateNodeCreator< TemplateNodeIf >
static TemplateNodePtr createInstance (TemplateParser *parser, TemplateNode *parent, int line, const QCString &data)
 
- Protected 成员函数 继承自 TemplateNodeCreator< TemplateNodeIf >
void mkpath (const TemplateContextImpl *ci, const std::string &fileName)
 
- Protected 属性 继承自 TemplateNodeCreator< TemplateNodeIf >
QCString m_templateName
 
int m_line
 

详细描述

Class representing an 'if' tag in a template

在文件 template.cpp3102 行定义.

构造及析构函数说明

◆ TemplateNodeIf()

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

在文件 template.cpp3105 行定义.

3105  :
3107  {
3108  TRACE(("{TemplateNodeIf(%s)\n",qPrint(data)));
3109  if (data.isEmpty())
3110  {
3111  parser->warn(m_templateName,line,"missing argument for if tag");
3112  }
3113  StringVector stopAt = { "endif", "elif", "else" };
3114 
3115  // if 'nodes'
3116  {
3117  m_ifGuardedNodes.push_back(std::make_unique<GuardedNodes>());
3118  auto &guardedNodes = m_ifGuardedNodes.back();
3119  ExpressionParser ex(parser,line);
3120  guardedNodes->line = line;
3121  guardedNodes->guardAst = ex.parse(data);
3122  parser->parse(this,line,stopAt,guardedNodes->trueNodes);
3123  }
3124  auto tok = parser->takeNextToken();
3125 
3126  // elif 'nodes'
3127  while (tok && tok->data.left(5)=="elif ")
3128  {
3129  m_ifGuardedNodes.push_back(std::make_unique<GuardedNodes>());
3130  auto &guardedNodes = m_ifGuardedNodes.back();
3131  ExpressionParser ex(parser,line);
3132  guardedNodes->line = tok->line;
3133  guardedNodes->guardAst = ex.parse(tok->data.mid(5));
3134  parser->parse(this,tok->line,stopAt,guardedNodes->trueNodes);
3135  // proceed to the next token
3136  tok = parser->takeNextToken();
3137  }
3138 
3139  // else 'nodes'
3140  if (tok && tok->data=="else")
3141  {
3142  stopAt.pop_back(); // remove "else"
3143  stopAt.pop_back(); // remove "elif"
3144  parser->parse(this,line,stopAt,m_falseNodes);
3145  parser->removeNextToken(); // skip over endif
3146  }
3147  TRACE(("}TemplateNodeIf(%s)\n",qPrint(data)));
3148  }

引用了 QCString::isEmpty(), m_falseNodes, m_ifGuardedNodes, TemplateNodeCreator< TemplateNodeIf >::m_templateName, TemplateParser::parse(), ExpressionParser::parse(), qPrint(), TemplateParser::removeNextToken(), TemplateParser::takeNextToken(), TRACE , 以及 TemplateParser::warn().

◆ ~TemplateNodeIf()

TemplateNodeIf::~TemplateNodeIf ( )
inline

在文件 template.cpp3149 行定义.

3150  {
3151  }

成员函数说明

◆ render()

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

实现了 TemplateNode.

在文件 template.cpp3153 行定义.

3154  {
3155  TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
3156  if (ci==0) return; // should not happen
3158  //printf("TemplateNodeIf::render #trueNodes=%d #falseNodes=%d\n",m_trueNodes.count(),m_falseNodes.count());
3159  bool processed=FALSE;
3160  for (auto &nodes : m_ifGuardedNodes)
3161  {
3162  if (nodes->guardAst)
3163  {
3164  TemplateVariant guardValue = nodes->guardAst->resolve(c);
3165  if (guardValue.toBool()) // render nodes for the first guard that evaluated to 'true'
3166  {
3167  nodes->trueNodes.render(ts,c);
3168  processed=TRUE;
3169  break;
3170  }
3171  }
3172  else
3173  {
3174  ci->warn(m_templateName,nodes->line,"invalid expression for if/elif");
3175  }
3176  }
3177  if (!processed)
3178  {
3179  // all guards are false, render 'else' nodes
3180  m_falseNodes.render(ts,c);
3181  }
3182  }

引用了 FALSE, m_falseNodes, m_ifGuardedNodes, TemplateNodeCreator< TemplateNodeIf >::m_line, TemplateNodeCreator< TemplateNodeIf >::m_templateName, TemplateNodeList::render(), TemplateContextImpl::setLocation(), TemplateVariant::toBool(), TRUE , 以及 TemplateContextImpl::warn().

类成员变量说明

◆ m_falseNodes

TemplateNodeList TemplateNodeIf::m_falseNodes
private

在文件 template.cpp3191 行定义.

被这些函数引用 render() , 以及 TemplateNodeIf().

◆ m_ifGuardedNodes

std::vector< std::unique_ptr<GuardedNodes> > TemplateNodeIf::m_ifGuardedNodes
private

在文件 template.cpp3190 行定义.

被这些函数引用 render() , 以及 TemplateNodeIf().


该类的文档由以下文件生成:
StringVector
std::vector< std::string > StringVector
Definition: containers.h:32
TemplateContextImpl::warn
void warn(const QCString &fileName, int line, const char *fmt,...) const
Definition: template.cpp:2773
TemplateContextImpl::setLocation
void setLocation(const QCString &templateName, int line)
Definition: template.cpp:682
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty
Definition: qcstring.h:144
TemplateNodeCreator< TemplateNodeIf >
TemplateNodeIf::m_ifGuardedNodes
std::vector< std::unique_ptr< GuardedNodes > > m_ifGuardedNodes
Definition: template.cpp:3190
ExpressionParser
Recursive decent parser for Django style template expressions.
Definition: template.cpp:2010
TemplateParser::removeNextToken
void removeNextToken()
Definition: template.cpp:5153
TemplateParser::warn
void warn(const QCString &fileName, int line, const char *fmt,...) const
Definition: template.cpp:5163
TemplateVariant
Variant type which can hold one value of a fixed set of types.
Definition: template.h:98
TRACE
#define TRACE(x)
Definition: template.cpp:40
TemplateNodeIf::m_falseNodes
TemplateNodeList m_falseNodes
Definition: template.cpp:3191
TRUE
#define TRUE
Definition: qcstring.h:36
TemplateNodeList::render
void render(TextStream &ts, TemplateContext *c)
Definition: template.cpp:1971
TemplateNodeCreator< TemplateNodeIf >::m_templateName
QCString m_templateName
Definition: template.cpp:3095
TemplateNode::parent
TemplateNode * parent()
Definition: template.cpp:1941
TemplateParser::parse
void parse(TemplateNode *parent, int line, const StringVector &stopAt, TemplateNodeList &nodes)
Definition: template.cpp:5057
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
TemplateVariant::toBool
bool toBool() const
Returns the variant as a boolean.
Definition: template.cpp:367
TemplateParser::takeNextToken
TemplateTokenPtr takeNextToken()
Definition: template.cpp:5140
TemplateContextImpl
Internal class representing the implementation of a template context
Definition: template.cpp:640
TemplateNodeCreator< TemplateNodeIf >::m_line
int m_line
Definition: template.cpp:3096
FALSE
#define FALSE
Definition: qcstring.h:33