My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Static Public Member Functions | Static Private Member Functions | List of all members
FilterAlphaIndex Class Reference

The implementation of the "alphaIndex" filter. More...

Classes

struct  ListElem
 
class  SortList
 

Static Public Member Functions

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

Static Private Member Functions

static QCString keyToLetter (uint startLetter)
 
static QCString keyToLabel (uint startLetter)
 
static uint determineSortKey (TemplateStructIntf *s, const QCString &attribName)
 

Detailed Description

The implementation of the "alphaIndex" filter.

Definition at line 1096 of file template.cpp.

Member Function Documentation

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

Definition at line 1166 of file template.cpp.

References TemplateList::alloc(), TemplateStruct::alloc(), TemplateList::append(), TemplateListIntf::createIterator(), TemplateListIntf::ConstIterator::current(), determineSortKey(), FilterAlphaIndex::ListElem::key, keyToLabel(), keyToLetter(), TemplateVariant::List, TemplateStruct::set(), TemplateVariant::String, TemplateListIntf::ConstIterator::toFirst(), TemplateVariant::toList(), TemplateListIntf::ConstIterator::toNext(), TemplateVariant::toString(), TemplateVariant::toStruct(), TemplateVariant::type(), and FilterAlphaIndex::ListElem::value.

{
{
//printf("FilterListSort::apply: v=%s args=%s\n",v.toString().data(),args.toString().data());
// create list of items based on v using the data in args as a sort key
SortList sortList;
for (it->toFirst();(it->current(item));it->toNext())
{
if (s)
{
uint sortKey = determineSortKey(s,args.toString());
sortList.append(new ListElem(sortKey,item));
//printf("sortKey=%s\n",sortKey.data());
}
}
delete it;
// sort the list
sortList.sort();
// create an index from the sorted list
uint letter=0;
QListIterator<ListElem> sit(sortList);
ListElem *elem;
TemplateStruct *indexNode = 0;
TemplateList *indexList = 0;
for (sit.toFirst();(elem=sit.current());++sit)
{
if (letter!=elem->key || indexNode==0)
{
// create new indexNode
indexNode = TemplateStruct::alloc();
indexList = TemplateList::alloc();
indexNode->set("letter", keyToLetter(elem->key));
indexNode->set("label", keyToLabel(elem->key));
indexNode->set("items",indexList);
result->append(indexNode);
letter=elem->key;
}
indexList->append(elem->value);
}
return result;
}
return v;
}
static uint FilterAlphaIndex::determineSortKey ( TemplateStructIntf s,
const QCString &  attribName 
)
inlinestaticprivate

Definition at line 1158 of file template.cpp.

References TemplateStructIntf::get(), getPrefixIndex(), getUtf8CodeToUpper(), and TemplateVariant::toString().

Referenced by apply().

{
TemplateVariant v = s->get(attribName);
int index = getPrefixIndex(v.toString());
return getUtf8CodeToUpper(v.toString(),index);
}
static QCString FilterAlphaIndex::keyToLabel ( uint  startLetter)
inlinestaticprivate

Definition at line 1119 of file template.cpp.

Referenced by apply().

{
char s[11]; // 0x12345678 + '\0'
if ((startLetter>='0' && startLetter<='9') ||
(startLetter>='a' && startLetter<='z') ||
(startLetter>='A' && startLetter<='Z'))
{
int i=0;
if (startLetter>='0' && startLetter<='9') s[i++] = 'x';
s[i++]=tolower((char)startLetter);
s[i++]=0;
}
else
{
const char hex[]="0123456789abcdef";
int i=0;
s[i++]='x';
if (startLetter>(1<<24)) // 4 byte character
{
s[i++]=hex[(startLetter>>28)&0xf];
s[i++]=hex[(startLetter>>24)&0xf];
}
if (startLetter>(1<<16)) // 3 byte character
{
s[i++]=hex[(startLetter>>20)&0xf];
s[i++]=hex[(startLetter>>16)&0xf];
}
if (startLetter>(1<<8)) // 2 byte character
{
s[i++]=hex[(startLetter>>12)&0xf];
s[i++]=hex[(startLetter>>8)&0xf];
}
// one byte character
s[i++]=hex[(startLetter>>4)&0xf];
s[i++]=hex[(startLetter>>0)&0xf];
s[i++]=0;
}
return s;
}
static QCString FilterAlphaIndex::keyToLetter ( uint  startLetter)
inlinestaticprivate

Definition at line 1115 of file template.cpp.

Referenced by apply().

{
return QString(QChar(startLetter)).utf8();
}

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