My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 3018 of file template.cpp.

Constructor & Destructor Documentation

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

Definition at line 3021 of file template.cpp.

References m_down, m_endExpr, m_loopNodes, m_startExpr, TemplateNodeCreator< TemplateNodeRange >::m_templateName, m_var, TemplateParser::parse(), ExpressionParser::parse(), TemplateParser::removeNextToken(), TRACE, and TemplateParser::warn().

{
TRACE(("{TemplateNodeRange(%s)\n",data.data()));
QCString start,end;
int i1 = data.find(" from ");
int i2 = data.find(" to ");
int i3 = data.find(" downto ");
if (i1==-1)
{
if (data.right(5)==" from")
{
parser->warn(m_templateName,line,"range missing after 'from' keyword");
}
else if (data=="from")
{
parser->warn(m_templateName,line,"range needs an iterator variable and a range");
}
else
{
parser->warn(m_templateName,line,"range is missing 'from' keyword");
}
}
else if (i2==-1 && i3==-1)
{
if (data.right(3)==" to")
{
parser->warn(m_templateName,line,"range is missing end value after 'to' keyword");
}
else if (data.right(7)==" downto")
{
parser->warn(m_templateName,line,"range is missing end value after 'downto' keyword");
}
else
{
parser->warn(m_templateName,line,"range is missing 'to' or 'downto' keyword");
}
}
else
{
m_var = data.left(i1).stripWhiteSpace();
if (m_var.isEmpty())
{
parser->warn(m_templateName,line,"range needs an iterator variable");
}
start = data.mid(i1+6,i2-i1-6).stripWhiteSpace();
if (i2!=-1)
{
end = data.right(data.length()-i2-4).stripWhiteSpace();
m_down = FALSE;
}
else if (i3!=-1)
{
end = data.right(data.length()-i3-8).stripWhiteSpace();
m_down = TRUE;
}
}
ExpressionParser expParser(parser,line);
m_startExpr = expParser.parse(start);
m_endExpr = expParser.parse(end);
QStrList stopAt;
stopAt.append("endrange");
parser->parse(this,line,stopAt,m_loopNodes);
parser->removeNextToken(); // skip over endrange
TRACE(("}TemplateNodeRange(%s)\n",data.data()));
}
TemplateNodeRange::~TemplateNodeRange ( )
inline

Definition at line 3089 of file template.cpp.

References m_endExpr, and m_startExpr.

{
delete m_startExpr;
delete m_endExpr;
}

Member Function Documentation

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

Implements TemplateNode.

Definition at line 3095 of file template.cpp.

References TemplateStruct::alloc(), TemplateAutoRef< T >::get(), TemplateContext::getRef(), TemplateVariant::Integer, m_down, m_endExpr, TemplateNodeCreator< TemplateNodeRange >::m_line, m_loopNodes, m_startExpr, TemplateNodeCreator< TemplateNodeRange >::m_templateName, m_var, TemplateContext::pop(), TemplateContext::push(), TemplateNodeList::render(), ExprAst::resolve(), TemplateStruct::set(), TemplateContext::set(), TemplateContextImpl::setLocation(), TemplateVariant::toInt(), TemplateVariant::type(), and TemplateContextImpl::warn().

{
TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
if (ci==0) return; // should not happen
//printf("TemplateNodeRange::render #loopNodes=%d\n",
// m_loopNodes.count());
{
{
int s = vs.toInt();
int e = ve.toInt();
int l = m_down ? s-e+1 : e-s+1;
if (l>0)
{
c->push();
//int index = m_reversed ? list.count() : 0;
const TemplateVariant *parentLoop = c->getRef("forloop");
uint index = 0;
int i = m_down ? e : s;
bool done=false;
while (!done)
{
// set the forloop meta-data variable
s->set("counter0", (int)index);
s->set("counter", (int)(index+1));
s->set("revcounter", (int)(l-index));
s->set("revcounter0", (int)(l-index-1));
s->set("first",index==0);
s->set("last", (int)index==l-1);
s->set("parentloop",parentLoop ? *parentLoop : TemplateVariant());
c->set("forloop",s.get());
// set the iterator variable
c->set(m_var,i);
// render all items for this iteration of the loop
index++;
if (m_down)
{
i--;
done = i<e;
}
else
{
i++;
done = i>e;
}
}
c->pop();
}
else
{
ci->warn(m_templateName,m_line,"range %d %s %d is empty!",
s,m_down?"downto":"to",e);
}
}
{
ci->warn(m_templateName,m_line,"range requires a start value of integer type!");
}
{
ci->warn(m_templateName,m_line,"range requires an end value of integer type!");
}
}
else if (!m_startExpr)
{
ci->warn(m_templateName,m_line,"range has empty start value");
}
else if (!m_endExpr)
{
ci->warn(m_templateName,m_line,"range has empty end value");
}
}

Member Data Documentation

bool TemplateNodeRange::m_down
private

Definition at line 3178 of file template.cpp.

Referenced by render(), and TemplateNodeRange().

ExprAst* TemplateNodeRange::m_endExpr
private

Definition at line 3180 of file template.cpp.

Referenced by render(), TemplateNodeRange(), and ~TemplateNodeRange().

TemplateNodeList TemplateNodeRange::m_loopNodes
private

Definition at line 3182 of file template.cpp.

Referenced by render(), and TemplateNodeRange().

ExprAst* TemplateNodeRange::m_startExpr
private

Definition at line 3179 of file template.cpp.

Referenced by render(), TemplateNodeRange(), and ~TemplateNodeRange().

QCString TemplateNodeRange::m_var
private

Definition at line 3181 of file template.cpp.

Referenced by render(), and TemplateNodeRange().


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