Doxygen
TemplateNodeRange类 参考

Class representing a 'range' tag in a template 更多...

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

Public 成员函数

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

Private 属性

bool m_down = false
 
ExprAstPtr m_startExpr
 
ExprAstPtr m_endExpr
 
QCString m_var
 
TemplateNodeList m_loopNodes
 

额外继承的成员函数

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

详细描述

Class representing a 'range' tag in a template

在文件 template.cpp3246 行定义.

构造及析构函数说明

◆ TemplateNodeRange()

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

在文件 template.cpp3249 行定义.

3251  {
3252  TRACE(("{TemplateNodeRange(%s)\n",qPrint(data)));
3253  QCString start,end;
3254  int i1 = data.find(" from ");
3255  int i2 = data.find(" to ");
3256  int i3 = data.find(" downto ");
3257  if (i1==-1)
3258  {
3259  if (data.endsWith(" from"))
3260  {
3261  parser->warn(m_templateName,line,"range missing after 'from' keyword");
3262  }
3263  else if (data=="from")
3264  {
3265  parser->warn(m_templateName,line,"range needs an iterator variable and a range");
3266  }
3267  else
3268  {
3269  parser->warn(m_templateName,line,"range is missing 'from' keyword");
3270  }
3271  }
3272  else if (i2==-1 && i3==-1)
3273  {
3274  if (data.endsWith(" to"))
3275  {
3276  parser->warn(m_templateName,line,"range is missing end value after 'to' keyword");
3277  }
3278  else if (data.endsWith(" downto"))
3279  {
3280  parser->warn(m_templateName,line,"range is missing end value after 'downto' keyword");
3281  }
3282  else
3283  {
3284  parser->warn(m_templateName,line,"range is missing 'to' or 'downto' keyword");
3285  }
3286  }
3287  else
3288  {
3289  m_var = data.left(i1).stripWhiteSpace();
3290  if (m_var.isEmpty())
3291  {
3292  parser->warn(m_templateName,line,"range needs an iterator variable");
3293  }
3294  start = data.mid(i1+6,i2-i1-6).stripWhiteSpace();
3295  if (i2!=-1)
3296  {
3297  end = data.right(data.length()-i2-4).stripWhiteSpace();
3298  m_down = FALSE;
3299  }
3300  else if (i3!=-1)
3301  {
3302  end = data.right(data.length()-i3-8).stripWhiteSpace();
3303  m_down = TRUE;
3304  }
3305  }
3306  ExpressionParser expParser(parser,line);
3307  m_startExpr = expParser.parse(start);
3308  m_endExpr = expParser.parse(end);
3309 
3310  StringVector stopAt = { "endrange" };
3311  parser->parse(this,line,stopAt,m_loopNodes);
3312  parser->removeNextToken(); // skip over endrange
3313  TRACE(("}TemplateNodeRange(%s)\n",qPrint(data)));
3314  }

引用了 end(), QCString::endsWith(), FALSE, QCString::find(), QCString::isEmpty(), QCString::left(), QCString::length(), m_down, m_endExpr, m_loopNodes, m_startExpr, TemplateNodeCreator< TemplateNodeRange >::m_templateName, m_var, QCString::mid(), TemplateParser::parse(), ExpressionParser::parse(), qPrint(), TemplateParser::removeNextToken(), QCString::right(), QCString::stripWhiteSpace(), TRACE, TRUE , 以及 TemplateParser::warn().

成员函数说明

◆ render()

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

实现了 TemplateNode.

在文件 template.cpp3316 行定义.

3317  {
3318  TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
3319  if (ci==0) return; // should not happen
3321  //printf("TemplateNodeRange::render #loopNodes=%d\n",
3322  // m_loopNodes.count());
3323  if (m_startExpr && m_endExpr)
3324  {
3325  TemplateVariant vs = m_startExpr->resolve(c);
3326  TemplateVariant ve = m_endExpr->resolve(c);
3327  if (vs.isInt() && ve.isInt())
3328  {
3329  int s = vs.toInt();
3330  int e = ve.toInt();
3331  int l = m_down ? s-e+1 : e-s+1;
3332  if (l>0)
3333  {
3334  c->push();
3335  //int index = m_reversed ? list.count() : 0;
3336  const TemplateVariant *parentLoop = c->getRef("forloop");
3337  uint index = 0;
3338  int i = m_down ? e : s;
3339  bool done=false;
3340  while (!done)
3341  {
3342  // set the forloop meta-data variable
3344  ls->set("counter0", (int)index);
3345  ls->set("counter", (int)(index+1));
3346  ls->set("revcounter", (int)(l-index));
3347  ls->set("revcounter0", (int)(l-index-1));
3348  ls->set("first",index==0);
3349  ls->set("last", (int)index==l-1);
3350  ls->set("parentloop",parentLoop ? *parentLoop : TemplateVariant());
3351  c->set("forloop",std::static_pointer_cast<TemplateStructIntf>(ls));
3352 
3353  // set the iterator variable
3354  c->set(m_var,i);
3355 
3356  // render all items for this iteration of the loop
3357  m_loopNodes.render(ts,c);
3358 
3359  index++;
3360  if (m_down)
3361  {
3362  i--;
3363  done = i<e;
3364  }
3365  else
3366  {
3367  i++;
3368  done = i>e;
3369  }
3370  }
3371  c->pop();
3372  }
3373  else
3374  {
3375  ci->warn(m_templateName,m_line,"range %d %s %d is empty!",
3376  s,m_down?"downto":"to",e);
3377  }
3378  }
3379  else if (!vs.isInt())
3380  {
3381  ci->warn(m_templateName,m_line,"range requires a start value of integer type!");
3382  }
3383  else if (!ve.isInt())
3384  {
3385  ci->warn(m_templateName,m_line,"range requires an end value of integer type!");
3386  }
3387  }
3388  else if (!m_startExpr)
3389  {
3390  ci->warn(m_templateName,m_line,"range has empty start value");
3391  }
3392  else if (!m_endExpr)
3393  {
3394  ci->warn(m_templateName,m_line,"range has empty end value");
3395  }
3396  }

引用了 TemplateStruct::alloc(), TemplateContext::getRef(), TemplateVariant::isInt(), m_down, m_endExpr, TemplateNodeCreator< TemplateNodeRange >::m_line, m_loopNodes, m_startExpr, TemplateNodeCreator< TemplateNodeRange >::m_templateName, m_var, TemplateContext::pop(), TemplateContext::push(), TemplateNodeList::render(), TemplateContext::set(), TemplateContextImpl::setLocation(), TemplateVariant::toInt() , 以及 TemplateContextImpl::warn().

类成员变量说明

◆ m_down

bool TemplateNodeRange::m_down = false
private

在文件 template.cpp3399 行定义.

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

◆ m_endExpr

ExprAstPtr TemplateNodeRange::m_endExpr
private

在文件 template.cpp3401 行定义.

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

◆ m_loopNodes

TemplateNodeList TemplateNodeRange::m_loopNodes
private

在文件 template.cpp3403 行定义.

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

◆ m_startExpr

ExprAstPtr TemplateNodeRange::m_startExpr
private

在文件 template.cpp3400 行定义.

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

◆ m_var

QCString TemplateNodeRange::m_var
private

在文件 template.cpp3402 行定义.

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


该类的文档由以下文件生成:
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
TemplateNodeRange::m_loopNodes
TemplateNodeList m_loopNodes
Definition: template.cpp:3403
TemplateNodeRange::m_startExpr
ExprAstPtr m_startExpr
Definition: template.cpp:3400
QCString::length
uint length() const
Returns the length of the string, not counting the 0-terminator.
Definition: qcstring.h:147
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< TemplateNodeRange >
QCString::find
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:38
end
DirIterator end(const DirIterator &) noexcept
Definition: dir.cpp:128
ExpressionParser
Recursive decent parser for Django style template expressions.
Definition: template.cpp:2010
TemplateParser::removeNextToken
void removeNextToken()
Definition: template.cpp:5153
uint
unsigned uint
Definition: qcstring.h:40
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
QCString::stripWhiteSpace
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition: qcstring.h:243
QCString::left
QCString left(size_t len) const
Definition: qcstring.h:212
TemplateVariant::isInt
constexpr bool isInt() const
Returns TRUE if the variant holds an integer value
Definition: template.h:207
TemplateNodeRange::m_endExpr
ExprAstPtr m_endExpr
Definition: template.cpp:3401
TemplateNodeRange::m_var
QCString m_var
Definition: template.cpp:3402
TemplateNodeRange::m_down
bool m_down
Definition: template.cpp:3399
TRACE
#define TRACE(x)
Definition: template.cpp:40
TemplateContext::set
virtual void set(const QCString &name, const TemplateVariant &v)=0
Sets a value in the current scope.
TRUE
#define TRUE
Definition: qcstring.h:36
TemplateNodeList::render
void render(TextStream &ts, TemplateContext *c)
Definition: template.cpp:1971
TemplateNodeCreator< TemplateNodeRange >::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
QCString::mid
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition: qcstring.h:224
QCString::endsWith
bool endsWith(const char *s) const
Definition: qcstring.h:420
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
TemplateVariant::toInt
int toInt() const
Returns the variant as an integer.
Definition: template.cpp:383
TemplateContext::push
virtual void push()=0
Push a new scope on the stack.
TemplateContextImpl
Internal class representing the implementation of a template context
Definition: template.cpp:640
TemplateNodeCreator< TemplateNodeRange >::m_line
int m_line
Definition: template.cpp:3096
TemplateContext::getRef
virtual const TemplateVariant * getRef(const QCString &name) const =0
Returns a pointer to the value corresponding to a given key.
TemplateContext::pop
virtual void pop()=0
Pop the current scope from the stack.
QCString::right
QCString right(size_t len) const
Definition: qcstring.h:217
FALSE
#define FALSE
Definition: qcstring.h:33
TemplateStructPtr
std::shared_ptr< TemplateStruct > TemplateStructPtr
Definition: template.cpp:147
TemplateStruct::alloc
static TemplateStructPtr alloc()
Creates an instance and returns a shared pointer to it
Definition: template.cpp:218
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108