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 1089 of file template.cpp.

Member Function Documentation

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

Definition at line 1159 of file template.cpp.

1160  {
1162  {
1163  //printf("FilterListSort::apply: v=%s args=%s\n",v.toString().data(),args.toString().data());
1165 
1166  TemplateVariant item;
1168 
1169  // create list of items based on v using the data in args as a sort key
1170  SortList sortList;
1171  for (it->toFirst();(it->current(item));it->toNext())
1172  {
1173  TemplateStructIntf *s = item.toStruct();
1174  if (s)
1175  {
1176  uint sortKey = determineSortKey(s,args.toString());
1177  sortList.append(new ListElem(sortKey,item));
1178  //printf("sortKey=%s\n",sortKey.data());
1179  }
1180  }
1181  delete it;
1182 
1183  // sort the list
1184  sortList.sort();
1185 
1186  // create an index from the sorted list
1187  uint letter=0;
1188  QListIterator<ListElem> sit(sortList);
1189  ListElem *elem;
1190  TemplateStruct *indexNode = 0;
1191  TemplateList *indexList = 0;
1192  for (sit.toFirst();(elem=sit.current());++sit)
1193  {
1194  if (letter!=elem->key || indexNode==0)
1195  {
1196  // create new indexNode
1197  indexNode = TemplateStruct::alloc();
1198  indexList = TemplateList::alloc();
1199  indexNode->set("letter", keyToLetter(elem->key));
1200  indexNode->set("label", keyToLabel(elem->key));
1201  indexNode->set("items",indexList);
1202  result->append(indexNode);
1203  letter=elem->key;
1204  }
1205  indexList->append(elem->value);
1206  }
1207  return result;
1208  }
1209  return v;
1210  }
static TemplateList * alloc()
Definition: template.cpp:420
virtual void set(const char *name, const TemplateVariant &v)
Definition: template.cpp:275
static QCString result
virtual bool current(TemplateVariant &v) const =0
TemplateListIntf * toList() const
Definition: template.h:256
Default implementation of a context value of type list.
Definition: template.h:376
Abstract interface for a context value of type struct.
Definition: template.h:406
virtual void append(const TemplateVariant &v)
Definition: template.cpp:343
static uint determineSortKey(TemplateStructIntf *s, const QCString &attribName)
Definition: template.cpp:1151
QCString toString() const
Definition: template.h:232
static QCString keyToLabel(uint startLetter)
Definition: template.cpp:1112
static QCString keyToLetter(uint startLetter)
Definition: template.cpp:1108
Abstract interface for a iterator of a list.
Definition: template.h:333
virtual TemplateListIntf::ConstIterator * createIterator() const =0
Variant type which can hold one value of a fixed set of types.
Definition: template.h:90
TemplateStructIntf * toStruct() const
Definition: template.h:264
Type type() const
Definition: template.h:142
Default implementation of a context value of type struct.
Definition: template.h:426
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
static TemplateStruct * alloc()
Definition: template.cpp:294
static uint FilterAlphaIndex::determineSortKey ( TemplateStructIntf s,
const QCString attribName 
)
inlinestaticprivate

Definition at line 1151 of file template.cpp.

1152  {
1153  TemplateVariant v = s->get(attribName);
1154  int index = getPrefixIndex(v.toString());
1155  return getUtf8CodeToUpper(v.toString(),index);
1156  }
virtual TemplateVariant get(const char *name) const =0
uint getUtf8CodeToUpper(const QCString &s, int idx)
Returns one unicode character as ian unsigned interger from utf-8 string, making the character upper ...
Definition: util.cpp:8291
QCString toString() const
Definition: template.h:232
int getPrefixIndex(const QCString &name)
Definition: util.cpp:5144
Variant type which can hold one value of a fixed set of types.
Definition: template.h:90
static QCString FilterAlphaIndex::keyToLabel ( uint  startLetter)
inlinestaticprivate

Definition at line 1112 of file template.cpp.

1113  {
1114  char s[11]; // 0x12345678 + '\0'
1115  if ((startLetter>='0' && startLetter<='9') ||
1116  (startLetter>='a' && startLetter<='z') ||
1117  (startLetter>='A' && startLetter<='Z'))
1118  {
1119  int i=0;
1120  if (startLetter>='0' && startLetter<='9') s[i++] = 'x';
1121  s[i++]=tolower((char)startLetter);
1122  s[i++]=0;
1123  }
1124  else
1125  {
1126  const char hex[]="0123456789abcdef";
1127  int i=0;
1128  s[i++]='x';
1129  if (startLetter>(1<<24)) // 4 byte character
1130  {
1131  s[i++]=hex[(startLetter>>28)&0xf];
1132  s[i++]=hex[(startLetter>>24)&0xf];
1133  }
1134  if (startLetter>(1<<16)) // 3 byte character
1135  {
1136  s[i++]=hex[(startLetter>>20)&0xf];
1137  s[i++]=hex[(startLetter>>16)&0xf];
1138  }
1139  if (startLetter>(1<<8)) // 2 byte character
1140  {
1141  s[i++]=hex[(startLetter>>12)&0xf];
1142  s[i++]=hex[(startLetter>>8)&0xf];
1143  }
1144  // one byte character
1145  s[i++]=hex[(startLetter>>4)&0xf];
1146  s[i++]=hex[(startLetter>>0)&0xf];
1147  s[i++]=0;
1148  }
1149  return s;
1150  }
QTextStream & hex(QTextStream &s)
static QCString * s
Definition: config.cpp:1042
static QCString FilterAlphaIndex::keyToLetter ( uint  startLetter)
inlinestaticprivate

Definition at line 1108 of file template.cpp.

1109  {
1110  return QString(QChar(startLetter)).utf8();
1111  }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
QCString utf8() const
Definition: qstring.cpp:14507

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