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

Constructor & Destructor Documentation

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

Definition at line 4217 of file template.cpp.

References m_listExpr, m_nodes, m_patternExpr, TemplateNodeCreator< TemplateNodeMarkers >::m_templateName, m_var, TemplateParser::parse(), ExpressionParser::parse(), TemplateParser::removeNextToken(), TRACE, and TemplateParser::warn().

{
TRACE(("{TemplateNodeMarkers(%s)\n",data.data()));
int i = data.find(" in ");
int w = data.find(" with ");
if (i==-1 || w==-1 || w<i)
{
parser->warn(m_templateName,line,"markers tag as wrong format. Expected: markers <var> in <list> with <string_with_markers>");
}
else
{
ExpressionParser expParser(parser,line);
m_var = data.left(i);
m_listExpr = expParser.parse(data.mid(i+4,w-i-4));
m_patternExpr = expParser.parse(data.right(data.length()-w-6));
}
QStrList stopAt;
stopAt.append("endmarkers");
parser->parse(this,line,stopAt,m_nodes);
parser->removeNextToken(); // skip over endmarkers
TRACE(("}TemplateNodeMarkers(%s)\n",data.data()));
}
TemplateNodeMarkers::~TemplateNodeMarkers ( )
inline

Definition at line 4240 of file template.cpp.

References m_listExpr, and m_patternExpr.

{
delete m_listExpr;
delete m_patternExpr;
}

Member Function Documentation

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

Implements TemplateNode.

Definition at line 4245 of file template.cpp.

References TemplateStruct::alloc(), TemplateListIntf::createIterator(), TemplateListIntf::ConstIterator::current(), TemplateContextImpl::enableSpaceless(), TemplateAutoRef< T >::get(), TemplateNodeCreator< TemplateNodeMarkers >::m_line, m_listExpr, m_nodes, m_patternExpr, TemplateNodeCreator< TemplateNodeMarkers >::m_templateName, m_var, TemplateContextImpl::needsRecoding(), TemplateContext::pop(), TemplateContext::push(), TemplateContextImpl::recode(), TemplateNodeList::render(), ExprAst::resolve(), TemplateStruct::set(), TemplateContext::set(), TemplateContextImpl::setLocation(), TemplateContextImpl::spacelessEnabled(), TemplateVariant::String, TemplateListIntf::ConstIterator::toFirst(), TemplateVariant::toList(), TemplateVariant::toString(), TemplateVariant::type(), and TemplateContextImpl::warn().

{
TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c);
if (ci==0) return; // should not happen
if (!m_var.isEmpty() && m_listExpr && m_patternExpr)
{
const TemplateListIntf *list = v.toList();
if (list)
{
if (patternStr.type()==TemplateVariant::String)
{
c->push();
QCString str = patternStr.toString();
QRegExp marker("@[0-9]+"); // pattern for a marker, i.e. @0, @1 ... @12, etc
int index=0,newIndex,matchLen;
while ((newIndex=marker.match(str,index,&matchLen))!=-1)
{
if (ci->needsRecoding())
{
ts << ci->recode(str.mid(index,newIndex-index)); // write text before marker
}
else
{
ts << str.mid(index,newIndex-index); // write text before marker
}
bool ok;
uint entryIndex = str.mid(newIndex+1,matchLen-1).toUInt(&ok); // get marker id
uint i=0;
// search for list element at position id
for (it->toFirst(); (it->current(var)) && i<entryIndex; it->toNext(),i++) {}
if (ok && i==entryIndex) // found element
{
s->set("id",(int)i);
c->set("markers",s.get());
c->set(m_var,var); // define local variable to hold element of list type
bool wasSpaceless = ci->spacelessEnabled();
ci->enableSpaceless(TRUE);
m_nodes.render(ts,c);
ci->enableSpaceless(wasSpaceless);
}
else if (!ok)
{
ci->warn(m_templateName,m_line,"markers pattern string has invalid markers '%s'",str.data());
}
else if (i<entryIndex)
{
ci->warn(m_templateName,m_line,"markers list does not an element for marker position %d",i);
}
index=newIndex+matchLen; // set index just after marker
}
if (ci->needsRecoding())
{
ts << ci->recode(str.right(str.length()-index)); // write text after last marker
}
else
{
ts << str.right(str.length()-index); // write text after last marker
}
c->pop();
delete it;
}
else
{
ci->warn(m_templateName,m_line,"markers requires a parameter of string type after 'with'!");
}
}
else
{
ci->warn(m_templateName,m_line,"markers requires a parameter of list type after 'in'!");
}
}
}

Member Data Documentation

ExprAst* TemplateNodeMarkers::m_listExpr
private

Definition at line 4326 of file template.cpp.

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

TemplateNodeList TemplateNodeMarkers::m_nodes
private

Definition at line 4324 of file template.cpp.

Referenced by render(), and TemplateNodeMarkers().

ExprAst* TemplateNodeMarkers::m_patternExpr
private

Definition at line 4327 of file template.cpp.

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

QCString TemplateNodeMarkers::m_var
private

Definition at line 4325 of file template.cpp.

Referenced by render(), and TemplateNodeMarkers().


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