Doxygen
TemplateNodeMarkers类 参考

Class representing an 'markers' tag in a template 更多...

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

Public 成员函数

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

Private 属性

TemplateNodeList m_nodes
 
QCString m_var
 
ExprAstPtr m_listExpr
 
ExprAstPtr m_patternExpr
 

额外继承的成员函数

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

详细描述

Class representing an 'markers' tag in a template

在文件 template.cpp4395 行定义.

构造及析构函数说明

◆ TemplateNodeMarkers()

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

在文件 template.cpp4398 行定义.

4400  {
4401  TRACE(("{TemplateNodeMarkers(%s)\n",qPrint(data)));
4402  int i = data.find(" in ");
4403  int w = data.find(" with ");
4404  if (i==-1 || w==-1 || w<i)
4405  {
4406  parser->warn(m_templateName,line,"markers tag as wrong format. Expected: markers <var> in <list> with <string_with_markers>");
4407  }
4408  else
4409  {
4410  ExpressionParser expParser(parser,line);
4411  m_var = data.left(i);
4412  m_listExpr = expParser.parse(data.mid(i+4,w-i-4));
4413  m_patternExpr = expParser.parse(data.right(data.length()-w-6));
4414  }
4415  StringVector stopAt = { "endmarkers" };
4416  parser->parse(this,line,stopAt,m_nodes);
4417  parser->removeNextToken(); // skip over endmarkers
4418  TRACE(("}TemplateNodeMarkers(%s)\n",qPrint(data)));
4419  }

引用了 QCString::find(), QCString::left(), QCString::length(), m_listExpr, m_nodes, m_patternExpr, TemplateNodeCreator< TemplateNodeMarkers >::m_templateName, m_var, QCString::mid(), TemplateParser::parse(), ExpressionParser::parse(), qPrint(), TemplateParser::removeNextToken(), QCString::right(), TRACE , 以及 TemplateParser::warn().

成员函数说明

◆ render()

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

实现了 TemplateNode.

在文件 template.cpp4420 行定义.

4421  {
4422  TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c);
4423  if (ci==0) return; // should not happen
4425  if (!m_var.isEmpty() && m_listExpr && m_patternExpr)
4426  {
4427  TemplateVariant v = m_listExpr->resolve(c);
4428  const TemplateListIntfPtr list = v.toList();
4429  TemplateVariant patternStr = m_patternExpr->resolve(c);
4430  if (list)
4431  {
4432  if (patternStr.isString())
4433  {
4434  TemplateListIntf::ConstIteratorPtr it = list->createIterator();
4435  c->push();
4436  std::string str = patternStr.toString().str();
4437 
4438  static const reg::Ex marker(R"(@\d+)");
4439  reg::Iterator re_it(str,marker);
4441  size_t index=0;
4442  for ( ; re_it!=end ; ++re_it)
4443  {
4444  const auto &match = *re_it;
4445  size_t newIndex = match.position();
4446  size_t matchLen = match.length();
4447  std::string part = str.substr(index,newIndex-index);
4448  if (ci->needsRecoding())
4449  {
4450  ts << ci->recode(QCString(part)); // write text before marker
4451  }
4452  else
4453  {
4454  ts << part; // write text before marker
4455  }
4456  unsigned long entryIndex = std::stoul(match.str().substr(1));
4457  TemplateVariant var;
4458  size_t i=0;
4459  // search for list element at position id
4460  for (it->toFirst(); (it->current(var)) && i<entryIndex; it->toNext(),i++) {}
4461  if (i==entryIndex) // found element
4462  {
4464  s->set("id",(int)i);
4465  c->set("markers",std::static_pointer_cast<TemplateStructIntf>(s));
4466  c->set(m_var,var); // define local variable to hold element of list type
4467  bool wasSpaceless = ci->spacelessEnabled();
4468  ci->enableSpaceless(TRUE);
4469  m_nodes.render(ts,c);
4470  ci->enableSpaceless(wasSpaceless);
4471  }
4472  else if (i<entryIndex)
4473  {
4474  ci->warn(m_templateName,m_line,"markers list does not an element for marker position %d",i);
4475  }
4476  index=newIndex+matchLen; // set index just after marker
4477  }
4478  if (ci->needsRecoding())
4479  {
4480  ts << ci->recode(str.substr(index)); // write text after last marker
4481  }
4482  else
4483  {
4484  ts << str.substr(index); // write text after last marker
4485  }
4486  c->pop();
4487  }
4488  else
4489  {
4490  ci->warn(m_templateName,m_line,"markers requires a parameter of string type after 'with'!");
4491  }
4492  }
4493  else
4494  {
4495  ci->warn(m_templateName,m_line,"markers requires a parameter of list type after 'in'!");
4496  }
4497  }
4498  }

引用了 TemplateStruct::alloc(), TemplateContextImpl::enableSpaceless(), end(), QCString::isEmpty(), TemplateVariant::isString(), TemplateNodeCreator< TemplateNodeMarkers >::m_line, m_listExpr, m_nodes, m_patternExpr, TemplateNodeCreator< TemplateNodeMarkers >::m_templateName, m_var, reg::match(), TemplateContextImpl::needsRecoding(), TemplateContext::pop(), TemplateContext::push(), TemplateContextImpl::recode(), TemplateNodeList::render(), TemplateContext::set(), TemplateContextImpl::setLocation(), TemplateContextImpl::spacelessEnabled(), QCString::str(), TemplateVariant::toList(), TemplateVariant::toString(), TRUE , 以及 TemplateContextImpl::warn().

类成员变量说明

◆ m_listExpr

ExprAstPtr TemplateNodeMarkers::m_listExpr
private

在文件 template.cpp4502 行定义.

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

◆ m_nodes

TemplateNodeList TemplateNodeMarkers::m_nodes
private

在文件 template.cpp4500 行定义.

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

◆ m_patternExpr

ExprAstPtr TemplateNodeMarkers::m_patternExpr
private

在文件 template.cpp4503 行定义.

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

◆ m_var

QCString TemplateNodeMarkers::m_var
private

在文件 template.cpp4501 行定义.

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


该类的文档由以下文件生成:
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
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
reg::match
bool match(const std::string &str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition: regex.cpp:729
TemplateNodeCreator< TemplateNodeMarkers >
QCString::str
std::string str() const
Definition: qcstring.h:442
TemplateNodeMarkers::m_listExpr
ExprAstPtr m_listExpr
Definition: template.cpp:4502
TemplateNodeMarkers::m_patternExpr
ExprAstPtr m_patternExpr
Definition: template.cpp:4503
QCString::find
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:38
reg::Iterator
Iterator class to iterator through matches.
Definition: regex.h:242
end
DirIterator end(const DirIterator &) noexcept
Definition: dir.cpp:128
TemplateListIntf::ConstIteratorPtr
std::unique_ptr< ConstIterator > ConstIteratorPtr
Definition: template.h:292
ExpressionParser
Recursive decent parser for Django style template expressions.
Definition: template.cpp:2010
TemplateParser::removeNextToken
void removeNextToken()
Definition: template.cpp:5153
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::left
QCString left(size_t len) const
Definition: qcstring.h:212
TRACE
#define TRACE(x)
Definition: template.cpp:40
TemplateContextImpl::enableSpaceless
void enableSpaceless(bool b)
Definition: template.cpp:689
TemplateContext::set
virtual void set(const QCString &name, const TemplateVariant &v)=0
Sets a value in the current scope.
TemplateContextImpl::recode
QCString recode(const QCString &s)
Definition: template.cpp:2609
TRUE
#define TRUE
Definition: qcstring.h:36
TemplateNodeList::render
void render(TextStream &ts, TemplateContext *c)
Definition: template.cpp:1971
TemplateNodeCreator< TemplateNodeMarkers >::m_templateName
QCString m_templateName
Definition: template.cpp:3095
TemplateNode::parent
TemplateNode * parent()
Definition: template.cpp:1941
TemplateNodeMarkers::m_nodes
TemplateNodeList m_nodes
Definition: template.cpp:4500
TemplateParser::parse
void parse(TemplateNode *parent, int line, const StringVector &stopAt, TemplateNodeList &nodes)
Definition: template.cpp:5057
TemplateContextImpl::needsRecoding
bool needsRecoding() const
Definition: template.cpp:697
QCString::mid
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition: qcstring.h:224
TemplateListIntfPtr
std::shared_ptr< TemplateListIntf > TemplateListIntfPtr
Definition: template.h:32
TemplateVariant::toString
QCString toString() const
Returns the variant as a string.
Definition: template.cpp:399
reg::Ex
Class representing a regular expression.
Definition: regex.h:48
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
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
TemplateNodeMarkers::m_var
QCString m_var
Definition: template.cpp:4501
TemplateNodeCreator< TemplateNodeMarkers >::m_line
int m_line
Definition: template.cpp:3096
TemplateContextImpl::spacelessEnabled
bool spacelessEnabled() const
Definition: template.cpp:692
TemplateVariant::toList
TemplateListIntfPtr toList()
Returns the pointer to list referenced by this variant or 0 if this variant does not have list type.
Definition: template.cpp:432
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
TemplateVariant::isString
constexpr bool isString() const
Returns TRUE if the variant holds a string value
Definition: template.h:209
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