Doxygen
FilterAlphaIndex类 参考

The implementation of the "alphaIndex" filter 更多...

struct  ListElem
 

静态 Public 成员函数

static TemplateVariant apply (const TemplateVariant &v, const TemplateVariant &args)
 

静态 Private 成员函数

static QCString keyToLabel (const char *startLetter)
 
static std::string determineSortKey (const TemplateStructIntfPtr s, const QCString &attribName)
 

详细描述

The implementation of the "alphaIndex" filter

在文件 template.cpp1281 行定义.

成员函数说明

◆ apply()

static TemplateVariant FilterAlphaIndex::apply ( const TemplateVariant v,
const TemplateVariant args 
)
inlinestatic

在文件 template.cpp1321 行定义.

1322  {
1323  if (v.isList() && args.isString())
1324  {
1325  TemplateListIntfPtr list = v.toList();
1326  if (list)
1327  {
1328  //printf("FilterListSort::apply: v=%s args=%s\n",qPrint(v.toString()),qPrint(args.toString()));
1329  TemplateListIntf::ConstIteratorPtr it = list->createIterator();
1330 
1331  TemplateVariant item;
1333 
1334  // create list of items based on v using the data in args as a sort key
1335  using SortList = std::vector<ListElem>;
1336  SortList sortList;
1337  sortList.reserve(v.toList()->count());
1338  for (it->toFirst();(it->current(item));it->toNext())
1339  {
1340  TemplateStructIntfPtr s = item.toStruct();
1341  if (s)
1342  {
1343  std::string sortKey = determineSortKey(s,args.toString());
1344  sortList.emplace_back(sortKey,item);
1345  //printf("sortKey=%s\n",qPrint(sortKey));
1346  }
1347  }
1348 
1349  // sort the list
1350  std::sort(sortList.begin(),
1351  sortList.end(),
1352  [](const auto &lhs,const auto &rhs) { return lhs.key < rhs.key; });
1353 
1354  // create an index from the sorted list
1355  std::string letter;
1356  TemplateStructPtr indexNode;
1357  TemplateListPtr indexList;
1358  for (const auto &elem : sortList)
1359  {
1360  if (letter!=elem.key || indexNode==0)
1361  {
1362  // create new indexNode
1363  indexNode = TemplateStruct::alloc();
1364  indexList = TemplateList::alloc();
1365  indexNode->set("letter", elem.key);
1366  indexNode->set("label", keyToLabel(elem.key.c_str()));
1367  indexNode->set("items",std::static_pointer_cast<TemplateListIntf>(indexList));
1368  result->append(std::static_pointer_cast<TemplateStructIntf>(indexNode));
1369  letter=elem.key;
1370  }
1371  indexList->append(elem.value);
1372  }
1373  return TemplateVariant(std::static_pointer_cast<TemplateListIntf>(result));
1374  }
1375  }
1376  return v;
1377  }

引用了 TemplateStruct::alloc(), TemplateList::alloc(), determineSortKey(), TemplateVariant::isList(), TemplateVariant::isString(), keyToLabel(), TemplateVariant::toList(), TemplateVariant::toString() , 以及 TemplateVariant::toStruct().

◆ determineSortKey()

static std::string FilterAlphaIndex::determineSortKey ( const TemplateStructIntfPtr  s,
const QCString attribName 
)
inlinestaticprivate

在文件 template.cpp1313 行定义.

1314  {
1315  TemplateVariant v = s->get(attribName);
1316  int index = getPrefixIndex(v.toString());
1317  return convertUTF8ToUpper(getUTF8CharAt(v.toString().str(),index));
1318  }

引用了 convertUTF8ToUpper(), getPrefixIndex(), getUTF8CharAt(), QCString::str() , 以及 TemplateVariant::toString().

被这些函数引用 apply().

◆ keyToLabel()

static QCString FilterAlphaIndex::keyToLabel ( const char *  startLetter)
inlinestaticprivate

在文件 template.cpp1290 行定义.

1291  {
1292  //printf(">keyToLabel(%s)\n",qPrint(startLetter));
1293  const char *p = startLetter;
1294  char c = *p;
1295  QCString result;
1296  if (c<127 && c>31) // printable ASCII character
1297  {
1298  result+=c;
1299  }
1300  else
1301  {
1302  result="0x";
1303  const char hex[]="0123456789abcdef";
1304  while ((c=*p++))
1305  {
1306  result+=hex[((unsigned char)c)>>4];
1307  result+=hex[((unsigned char)c)&0xf];
1308  }
1309  }
1310  //printf("<keyToLabel(%s)\n",qPrint(result));
1311  return result;
1312  }

引用了 hex.

被这些函数引用 apply().


该类的文档由以下文件生成:
TemplateVariant::toStruct
TemplateStructIntfPtr toStruct()
Returns the pointer to struct referenced by this variant or 0 if this variant does not have struct ty...
Definition: template.cpp:441
FilterAlphaIndex::keyToLabel
static QCString keyToLabel(const char *startLetter)
Definition: template.cpp:1290
TemplateVariant::isList
constexpr bool isList() const
Returns TRUE if the variant holds a list value
Definition: template.h:213
TemplateListPtr
std::shared_ptr< TemplateList > TemplateListPtr
Definition: template.cpp:224
QCString::str
std::string str() const
Definition: qcstring.h:442
TemplateStructIntfPtr
std::shared_ptr< TemplateStructIntf > TemplateStructIntfPtr
Definition: template.h:33
TemplateListIntf::ConstIteratorPtr
std::unique_ptr< ConstIterator > ConstIteratorPtr
Definition: template.h:292
TemplateVariant
Variant type which can hold one value of a fixed set of types.
Definition: template.h:98
FilterAlphaIndex::determineSortKey
static std::string determineSortKey(const TemplateStructIntfPtr s, const QCString &attribName)
Definition: template.cpp:1313
getUTF8CharAt
std::string getUTF8CharAt(const std::string &input, size_t pos)
Returns the UTF8 character found at byte position pos in the input string.
Definition: utf8.cpp:127
TemplateList::alloc
static TemplateListPtr alloc()
Creates an instance and returns a shared pointer to it
Definition: template.cpp:291
getPrefixIndex
int getPrefixIndex(const QCString &name)
Definition: util.cpp:3357
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
hex
static const char * hex
Definition: htmldocvisitor.cpp:65
convertUTF8ToUpper
std::string convertUTF8ToUpper(const std::string &input)
Converts the input string into a upper case version, also taking into account non-ASCII characters th...
Definition: utf8.cpp:192
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
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