Public Member Functions | Private Attributes | List of all members
TemplateNodeRange Class Reference

Class representing a 'range' tag in a template. More...

Inheritance diagram for TemplateNodeRange:
TemplateNodeCreator< TemplateNodeRange > TemplateNode

Public Member Functions

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

Private Attributes

bool m_down
 
ExprAstm_startExpr
 
ExprAstm_endExpr
 
QCString m_var
 
TemplateNodeList m_loopNodes
 

Additional Inherited Members

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

Detailed Description

Class representing a 'range' tag in a template.

Definition at line 2878 of file template.cpp.

Constructor & Destructor Documentation

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

Definition at line 2881 of file template.cpp.

2883  {
2884  TRACE(("{TemplateNodeRange(%s)\n",data.data()));
2885  QCString start,end;
2886  int i1 = data.find(" from ");
2887  int i2 = data.find(" to ");
2888  int i3 = data.find(" downto ");
2889  if (i1==-1)
2890  {
2891  if (data.right(5)==" from")
2892  {
2893  parser->warn(m_templateName,line,"range missing after 'from' keyword");
2894  }
2895  else if (data=="from")
2896  {
2897  parser->warn(m_templateName,line,"range needs an iterator variable and a range");
2898  }
2899  else
2900  {
2901  parser->warn(m_templateName,line,"range is missing 'from' keyword");
2902  }
2903  }
2904  else if (i2==-1 && i3==-1)
2905  {
2906  if (data.right(3)==" to")
2907  {
2908  parser->warn(m_templateName,line,"range is missing end value after 'to' keyword");
2909  }
2910  else if (data.right(7)==" downto")
2911  {
2912  parser->warn(m_templateName,line,"range is missing end value after 'downto' keyword");
2913  }
2914  else
2915  {
2916  parser->warn(m_templateName,line,"range is missing 'to' or 'downto' keyword");
2917  }
2918  }
2919  else
2920  {
2921  m_var = data.left(i1).stripWhiteSpace();
2922  if (m_var.isEmpty())
2923  {
2924  parser->warn(m_templateName,line,"range needs an iterator variable");
2925  }
2926  start = data.mid(i1+6,i2-i1-6).stripWhiteSpace();
2927  if (i2!=-1)
2928  {
2929  end = data.right(data.length()-i2-4).stripWhiteSpace();
2930  m_down = FALSE;
2931  }
2932  else if (i3!=-1)
2933  {
2934  end = data.right(data.length()-i3-8).stripWhiteSpace();
2935  m_down = TRUE;
2936  }
2937  }
2938  ExpressionParser expParser(parser,line);
2939  m_startExpr = expParser.parse(start);
2940  m_endExpr = expParser.parse(end);
2941 
2942  QStrList stopAt;
2943  stopAt.append("endrange");
2944  parser->parse(this,line,stopAt,m_loopNodes);
2945  parser->removeNextToken(); // skip over endrange
2946  TRACE(("}TemplateNodeRange(%s)\n",data.data()));
2947  }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
QCString stripWhiteSpace() const
Definition: qcstring.cpp:295
bool isEmpty() const
Definition: qcstring.h:189
ExprAst * m_endExpr
Definition: template.cpp:3040
uint length() const
Definition: qcstring.h:195
const bool FALSE
Definition: qglobal.h:370
QCString left(uint len) const
Definition: qcstring.cpp:213
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:41
TemplateNode * parent()
Definition: template.cpp:1647
QCString right(uint len) const
Definition: qcstring.cpp:231
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
ExprAst * m_startExpr
Definition: template.cpp:3039
void line(double t, double *p, double &x, double &y, double &z)
TemplateNodeList m_loopNodes
Definition: template.cpp:3042
Recursive decent parser for Django style template expressions.
Definition: template.cpp:1680
#define TRACE(x)
Definition: template.cpp:43
const bool TRUE
Definition: qglobal.h:371
TemplateNodeRange::~TemplateNodeRange ( )
inline

Definition at line 2949 of file template.cpp.

2950  {
2951  delete m_startExpr;
2952  delete m_endExpr;
2953  }
ExprAst * m_endExpr
Definition: template.cpp:3040
ExprAst * m_startExpr
Definition: template.cpp:3039

Member Function Documentation

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

Implements TemplateNode.

Definition at line 2955 of file template.cpp.

2956  {
2957  TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
2958  if (ci==0) return; // should not happen
2960  //printf("TemplateNodeRange::render #loopNodes=%d\n",
2961  // m_loopNodes.count());
2962  if (m_startExpr && m_endExpr)
2963  {
2967  {
2968  int s = vs.toInt();
2969  int e = ve.toInt();
2970  int l = m_down ? s-e+1 : e-s+1;
2971  if (l>0)
2972  {
2973  c->push();
2974  //int index = m_reversed ? list.count() : 0;
2975  const TemplateVariant *parentLoop = c->getRef("forloop");
2976  uint index = 0;
2977  int i = m_down ? e : s;
2978  bool done=false;
2979  while (!done)
2980  {
2981  // set the forloop meta-data variable
2983  s->set("counter0", (int)index);
2984  s->set("counter", (int)(index+1));
2985  s->set("revcounter", (int)(l-index));
2986  s->set("revcounter0", (int)(l-index-1));
2987  s->set("first",index==0);
2988  s->set("last", (int)index==l-1);
2989  s->set("parentloop",parentLoop ? *parentLoop : TemplateVariant());
2990  c->set("forloop",s.get());
2991 
2992  // set the iterator variable
2993  c->set(m_var,i);
2994 
2995  // render all items for this iteration of the loop
2996  m_loopNodes.render(ts,c);
2997 
2998  index++;
2999  if (m_down)
3000  {
3001  i--;
3002  done = i<e;
3003  }
3004  else
3005  {
3006  i++;
3007  done = i>e;
3008  }
3009  }
3010  c->pop();
3011  }
3012  else
3013  {
3014  ci->warn(m_templateName,m_line,"range %d %s %d is empty!",
3015  s,m_down?"downto":"to",e);
3016  }
3017  }
3018  else if (vs.type()!=TemplateVariant::Integer)
3019  {
3020  ci->warn(m_templateName,m_line,"range requires a start value of integer type!");
3021  }
3022  else if (ve.type()!=TemplateVariant::Integer)
3023  {
3024  ci->warn(m_templateName,m_line,"range requires an end value of integer type!");
3025  }
3026  }
3027  else if (!m_startExpr)
3028  {
3029  ci->warn(m_templateName,m_line,"range has empty start value");
3030  }
3031  else if (!m_endExpr)
3032  {
3033  ci->warn(m_templateName,m_line,"range has empty end value");
3034  }
3035  }
void render(FTextStream &ts, TemplateContext *c)
Definition: template.cpp:2246
virtual void pop()=0
virtual void push()=0
ExprAst * m_endExpr
Definition: template.cpp:3040
Internal class representing the implementation of a template context.
Definition: template.cpp:511
virtual const TemplateVariant * getRef(const QCString &name) const =0
static QStrList * l
Definition: config.cpp:1044
int toInt() const
Definition: template.cpp:222
virtual void set(const char *name, const TemplateVariant &v)=0
const double e
virtual TemplateVariant resolve(TemplateContext *)
Definition: template.cpp:1368
Variant type which can hold one value of a fixed set of types.
Definition: template.h:90
ExprAst * m_startExpr
Definition: template.cpp:3039
void warn(const char *fileName, int line, const char *fmt,...) const
Definition: template.cpp:2431
TemplateNodeList m_loopNodes
Definition: template.cpp:3042
Type type() const
Definition: template.h:142
void setLocation(const QCString &templateName, int line)
Definition: template.cpp:540
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
static TemplateStruct * alloc()
Definition: template.cpp:294

Member Data Documentation

bool TemplateNodeRange::m_down
private

Definition at line 3038 of file template.cpp.

ExprAst* TemplateNodeRange::m_endExpr
private

Definition at line 3040 of file template.cpp.

TemplateNodeList TemplateNodeRange::m_loopNodes
private

Definition at line 3042 of file template.cpp.

ExprAst* TemplateNodeRange::m_startExpr
private

Definition at line 3039 of file template.cpp.

QCString TemplateNodeRange::m_var
private

Definition at line 3041 of file template.cpp.


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