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

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

Inheritance diagram for TemplateNodeMarkers:
TemplateNodeCreator< TemplateNodeMarkers > TemplateNode

Public Member Functions

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

Private Attributes

TemplateNodeList m_nodes
 
QCString m_var
 
ExprAstm_listExpr
 
ExprAstm_patternExpr
 

Additional Inherited Members

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

Detailed Description

Class representing an 'markers' tag in a template.

Definition at line 4060 of file template.cpp.

Constructor & Destructor Documentation

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

Definition at line 4063 of file template.cpp.

4065  {
4066  TRACE(("{TemplateNodeMarkers(%s)\n",data.data()));
4067  int i = data.find(" in ");
4068  int w = data.find(" with ");
4069  if (i==-1 || w==-1 || w<i)
4070  {
4071  parser->warn(m_templateName,line,"markers tag as wrong format. Expected: markers <var> in <list> with <string_with_markers>");
4072  }
4073  else
4074  {
4075  ExpressionParser expParser(parser,line);
4076  m_var = data.left(i);
4077  m_listExpr = expParser.parse(data.mid(i+4,w-i-4));
4078  m_patternExpr = expParser.parse(data.right(data.length()-w-6));
4079  }
4080  QStrList stopAt;
4081  stopAt.append("endmarkers");
4082  parser->parse(this,line,stopAt,m_nodes);
4083  parser->removeNextToken(); // skip over endmarkers
4084  TRACE(("}TemplateNodeMarkers(%s)\n",data.data()));
4085  }
uint length() const
Definition: qcstring.h:195
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
TemplateNodeList m_nodes
Definition: template.cpp:4156
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
void line(double t, double *p, double &x, double &y, double &z)
ExprAst * m_listExpr
Definition: template.cpp:4158
ExprAst * m_patternExpr
Definition: template.cpp:4159
Recursive decent parser for Django style template expressions.
Definition: template.cpp:1680
#define TRACE(x)
Definition: template.cpp:43
TemplateNodeMarkers::~TemplateNodeMarkers ( )
inline

Definition at line 4086 of file template.cpp.

4087  {
4088  delete m_listExpr;
4089  delete m_patternExpr;
4090  }
ExprAst * m_listExpr
Definition: template.cpp:4158
ExprAst * m_patternExpr
Definition: template.cpp:4159

Member Function Documentation

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

Implements TemplateNode.

Definition at line 4091 of file template.cpp.

4092  {
4093  TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c);
4094  if (ci==0) return; // should not happen
4096  if (!m_var.isEmpty() && m_listExpr && m_patternExpr)
4097  {
4099  const TemplateListIntf *list = v.toList();
4100  TemplateVariant patternStr = m_patternExpr->resolve(c);
4101  if (list)
4102  {
4103  if (patternStr.type()==TemplateVariant::String)
4104  {
4106  c->push();
4107  QCString str = patternStr.toString();
4108  QRegExp marker("@[0-9]+"); // pattern for a marker, i.e. @0, @1 ... @12, etc
4109  int index=0,newIndex,matchLen;
4110  while ((newIndex=marker.match(str,index,&matchLen))!=-1)
4111  {
4112  ts << str.mid(index,newIndex-index); // write text before marker
4113  bool ok;
4114  uint entryIndex = str.mid(newIndex+1,matchLen-1).toUInt(&ok); // get marker id
4116  uint i=0;
4117  // search for list element at position id
4118  for (it->toFirst(); (it->current(var)) && i<entryIndex; it->toNext(),i++) {}
4119  if (ok && i==entryIndex) // found element
4120  {
4122  s->set("id",(int)i);
4123  c->set("markers",s.get());
4124  c->set(m_var,var); // define local variable to hold element of list type
4125  bool wasSpaceless = ci->spacelessEnabled();
4126  ci->enableSpaceless(TRUE);
4127  m_nodes.render(ts,c);
4128  ci->enableSpaceless(wasSpaceless);
4129  }
4130  else if (!ok)
4131  {
4132  ci->warn(m_templateName,m_line,"markers pattern string has invalid markers '%s'",str.data());
4133  }
4134  else if (i<entryIndex)
4135  {
4136  ci->warn(m_templateName,m_line,"markers list does not an element for marker position %d",i);
4137  }
4138  index=newIndex+matchLen; // set index just after marker
4139  }
4140  ts << str.right(str.length()-index); // write text after last marker
4141  c->pop();
4142  delete it;
4143  }
4144  else
4145  {
4146  ci->warn(m_templateName,m_line,"markers requires a parameter of string type after 'with'!");
4147  }
4148  }
4149  else
4150  {
4151  ci->warn(m_templateName,m_line,"markers requires a parameter of list type after 'in'!");
4152  }
4153  }
4154  }
void render(FTextStream &ts, TemplateContext *c)
Definition: template.cpp:2246
void enableSpaceless(bool b)
Definition: template.cpp:547
virtual void pop()=0
virtual void push()=0
bool spacelessEnabled() const
Definition: template.cpp:550
bool isEmpty() const
Definition: qcstring.h:189
The QRegExp class provides pattern matching using regular expressions or wildcards.
Definition: qregexp.h:46
Internal class representing the implementation of a template context.
Definition: template.cpp:511
uint length() const
Definition: qcstring.h:195
virtual bool current(TemplateVariant &v) const =0
TemplateListIntf * toList() const
Definition: template.h:256
virtual void set(const char *name, const TemplateVariant &v)=0
QCString toString() const
Definition: template.h:232
virtual TemplateVariant resolve(TemplateContext *)
Definition: template.cpp:1368
QCString right(uint len) const
Definition: qcstring.cpp:231
Abstract interface for a iterator of a list.
Definition: template.h:333
const char * data() const
Definition: qcstring.h:207
virtual TemplateListIntf::ConstIterator * createIterator() const =0
TemplateNodeList m_nodes
Definition: template.cpp:4156
Variant type which can hold one value of a fixed set of types.
Definition: template.h:90
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
int var
Definition: 018_def.c:9
void warn(const char *fileName, int line, const char *fmt,...) const
Definition: template.cpp:2431
uint toUInt(bool *ok=0) const
Definition: qcstring.cpp:445
ExprAst * m_listExpr
Definition: template.cpp:4158
ExprAst * m_patternExpr
Definition: template.cpp:4159
Type type() const
Definition: template.h:142
void setLocation(const QCString &templateName, int line)
Definition: template.cpp:540
Abstract read-only interface for a context value of type list.
Definition: template.h:329
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
const bool TRUE
Definition: qglobal.h:371
static QCString str
static TemplateStruct * alloc()
Definition: template.cpp:294

Member Data Documentation

ExprAst* TemplateNodeMarkers::m_listExpr
private

Definition at line 4158 of file template.cpp.

TemplateNodeList TemplateNodeMarkers::m_nodes
private

Definition at line 4156 of file template.cpp.

ExprAst* TemplateNodeMarkers::m_patternExpr
private

Definition at line 4159 of file template.cpp.

QCString TemplateNodeMarkers::m_var
private

Definition at line 4157 of file template.cpp.


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