Commit 064992b0 authored by Dimitri van Heesch's avatar Dimitri van Heesch

Added groupby filter and some more context info

parent 57eee177
...@@ -173,7 +173,7 @@ QHP_SECT_FILTER_ATTRS = ...@@ -173,7 +173,7 @@ QHP_SECT_FILTER_ATTRS =
QHG_LOCATION = QHG_LOCATION =
GENERATE_ECLIPSEHELP = NO GENERATE_ECLIPSEHELP = NO
ECLIPSE_DOC_ID = org.doxygen.Project ECLIPSE_DOC_ID = org.doxygen.Project
DISABLE_INDEX = YES DISABLE_INDEX = NO
GENERATE_TREEVIEW = YES GENERATE_TREEVIEW = YES
ENUM_VALUES_PER_LINE = 4 ENUM_VALUES_PER_LINE = 4
TREEVIEW_WIDTH = 250 TREEVIEW_WIDTH = 250
......
...@@ -804,6 +804,46 @@ class TranslateContext::Private : public PropertyMapper ...@@ -804,6 +804,46 @@ class TranslateContext::Private : public PropertyMapper
{ {
return theTranslator->trDirectories(); return theTranslator->trDirectories();
} }
TemplateVariant all() const
{
return theTranslator->trAll();
}
TemplateVariant functions() const
{
static bool fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN");
static bool vhdlOpt = Config_getBool("OPTIMIZE_OUTPUT_VHDL");
return fortranOpt ? theTranslator->trSubprograms() :
vhdlOpt ? VhdlDocGen::trFunctionAndProc() :
theTranslator->trFunctions();
}
TemplateVariant variables() const
{
return theTranslator->trVariables();
}
TemplateVariant typedefs() const
{
return theTranslator->trTypedefs();
}
TemplateVariant enums() const
{
return theTranslator->trEnumerations();
}
TemplateVariant properties() const
{
return theTranslator->trProperties();
}
TemplateVariant events() const
{
return theTranslator->trEvents();
}
TemplateVariant related() const
{
return theTranslator->trRelatedFunctions();
}
TemplateVariant macros() const
{
return theTranslator->trDefines();
}
Private() Private()
{ {
//%% string generatedBy //%% string generatedBy
...@@ -878,8 +918,6 @@ class TranslateContext::Private : public PropertyMapper ...@@ -878,8 +918,6 @@ class TranslateContext::Private : public PropertyMapper
addProperty("defineValue", this,&Private::defineValue); addProperty("defineValue", this,&Private::defineValue);
//%% string initialValue //%% string initialValue
addProperty("initialValue", this,&Private::initialValue); addProperty("initialValue", this,&Private::initialValue);
//%% string enumerationValues
addProperty("enumerationValues", this,&Private::enumerationValues);
//%% markerstring implements //%% markerstring implements
addProperty("implements", this,&Private::implements); addProperty("implements", this,&Private::implements);
//%% markerstring reimplements //%% markerstring reimplements
...@@ -922,6 +960,26 @@ class TranslateContext::Private : public PropertyMapper ...@@ -922,6 +960,26 @@ class TranslateContext::Private : public PropertyMapper
addProperty("directories", this,&Private::directories); addProperty("directories", this,&Private::directories);
//%% string moduleDescript //%% string moduleDescript
addProperty("modulesDescription", this,&Private::modulesDescription); addProperty("modulesDescription", this,&Private::modulesDescription);
//%% string all
addProperty("all", this,&Private::all);
//%% string functions
addProperty("functions", this,&Private::functions);
//%% string variables
addProperty("variables", this,&Private::variables);
//%% string typedefs
addProperty("typedefs", this,&Private::typedefs);
//%% string enums
addProperty("enums", this,&Private::enums);
//%% string enumValues
addProperty("enumValues", this,&Private::enumerationValues);
//%% string properties
addProperty("properties", this,&Private::properties);
//%% string events
addProperty("events", this,&Private::events);
//%% string related
addProperty("related", this,&Private::related);
//%% string macros
addProperty("macros", this,&Private::macros);
m_javaOpt = Config_getBool("OPTIMIZE_OUTPUT_JAVA"); m_javaOpt = Config_getBool("OPTIMIZE_OUTPUT_JAVA");
m_fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN"); m_fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN");
...@@ -3072,6 +3130,7 @@ class MemberContext::Private : public DefinitionContext<MemberContext::Private> ...@@ -3072,6 +3130,7 @@ class MemberContext::Private : public DefinitionContext<MemberContext::Private>
addProperty("propertyAttrs", this,&Private::propertyAttrs); addProperty("propertyAttrs", this,&Private::propertyAttrs);
addProperty("eventAttrs", this,&Private::eventAttrs); addProperty("eventAttrs", this,&Private::eventAttrs);
addProperty("class", this,&Private::getClass); addProperty("class", this,&Private::getClass);
addProperty("file", this,&Private::getFile);
addProperty("definition", this,&Private::definition); addProperty("definition", this,&Private::definition);
addProperty("parameters", this,&Private::parameters); addProperty("parameters", this,&Private::parameters);
addProperty("hasParameterList", this,&Private::hasParameterList); addProperty("hasParameterList", this,&Private::hasParameterList);
...@@ -3536,6 +3595,21 @@ class MemberContext::Private : public DefinitionContext<MemberContext::Private> ...@@ -3536,6 +3595,21 @@ class MemberContext::Private : public DefinitionContext<MemberContext::Private>
return TemplateVariant(FALSE); return TemplateVariant(FALSE);
} }
} }
TemplateVariant getFile() const
{
if (!m_cache.fileDef && m_memberDef->getFileDef())
{
m_cache.fileDef.reset(FileContext::alloc(m_memberDef->getFileDef()));
}
if (m_cache.fileDef)
{
return m_cache.fileDef.get();
}
else
{
return TemplateVariant(FALSE);
}
}
TemplateVariant definition() const TemplateVariant definition() const
{ {
return createLinkedText(m_memberDef,relPathAsString(), return createLinkedText(m_memberDef,relPathAsString(),
...@@ -3966,6 +4040,7 @@ class MemberContext::Private : public DefinitionContext<MemberContext::Private> ...@@ -3966,6 +4040,7 @@ class MemberContext::Private : public DefinitionContext<MemberContext::Private>
SharedPtr<ArgumentListContext> templateArgs; SharedPtr<ArgumentListContext> templateArgs;
SharedPtr<ArgumentListContext> arguments; SharedPtr<ArgumentListContext> arguments;
SharedPtr<MemberListContext> enumValues; SharedPtr<MemberListContext> enumValues;
SharedPtr<FileContext> fileDef;
SharedPtr<ClassContext> classDef; SharedPtr<ClassContext> classDef;
SharedPtr<ClassContext> anonymousType; SharedPtr<ClassContext> anonymousType;
SharedPtr<TemplateList> templateDecls; SharedPtr<TemplateList> templateDecls;
...@@ -6521,7 +6596,7 @@ class GlobalsIndexContext::Private : public PropertyMapper ...@@ -6521,7 +6596,7 @@ class GlobalsIndexContext::Private : public PropertyMapper
} }
TemplateVariant subhighlight() const TemplateVariant subhighlight() const
{ {
return "globals"; return "filemembers";
} }
TemplateVariant title() const TemplateVariant title() const
{ {
...@@ -7826,7 +7901,13 @@ class HtmlEscaper : public TemplateEscapeIntf ...@@ -7826,7 +7901,13 @@ class HtmlEscaper : public TemplateEscapeIntf
class HtmlSpaceless : public TemplateSpacelessIntf class HtmlSpaceless : public TemplateSpacelessIntf
{ {
public: public:
HtmlSpaceless() : m_insideTag(FALSE), m_insideString('\0'), m_removeSpaces(TRUE) {} HtmlSpaceless() { reset(); }
void reset()
{
m_insideTag = FALSE;
m_insideString = '\0';
m_removeSpaces = TRUE;
}
QCString remove(const QCString &s) QCString remove(const QCString &s)
{ {
QGString result; QGString result;
...@@ -7880,7 +7961,7 @@ class HtmlSpaceless : public TemplateSpacelessIntf ...@@ -7880,7 +7961,7 @@ class HtmlSpaceless : public TemplateSpacelessIntf
} }
} }
result+='\0'; result+='\0';
//printf("HtmlSpaceless::remove('%s')='%s' m_insideTag=%d m_insideString=%d removeSpaces=%d\n",s.data(),result.data(), //printf("HtmlSpaceless::remove({%s})={%s} m_insideTag=%d m_insideString=%d removeSpaces=%d\n",s.data(),result.data(),
// m_insideTag,m_insideString,m_removeSpaces); // m_insideTag,m_insideString,m_removeSpaces);
return result.data(); return result.data();
} }
......
...@@ -702,7 +702,9 @@ class TemplateContextImpl : public TemplateContext ...@@ -702,7 +702,9 @@ class TemplateContextImpl : public TemplateContext
QCString outputDirectory() const { return m_outputDir; } QCString outputDirectory() const { return m_outputDir; }
TemplateEscapeIntf *escapeIntf() const { return m_activeEscapeIntf; } TemplateEscapeIntf *escapeIntf() const { return m_activeEscapeIntf; }
TemplateSpacelessIntf *spacelessIntf() const { return m_spacelessIntf; } TemplateSpacelessIntf *spacelessIntf() const { return m_spacelessIntf; }
void enableSpaceless(bool b) { m_spacelessEnabled=b; } void enableSpaceless(bool b) { if (b && !m_spacelessEnabled) m_spacelessIntf->reset();
m_spacelessEnabled=b;
}
bool spacelessEnabled() const { return m_spacelessEnabled && m_spacelessIntf; } bool spacelessEnabled() const { return m_spacelessEnabled && m_spacelessIntf; }
void warn(const char *fileName,int line,const char *fmt,...) const; void warn(const char *fileName,int line,const char *fmt,...) const;
...@@ -993,6 +995,83 @@ class FilterListSort ...@@ -993,6 +995,83 @@ class FilterListSort
//-------------------------------------------------------------------- //--------------------------------------------------------------------
/** @brief The implementation of the "groupBy" filter */
class FilterGroupBy
{
struct ListElem
{
ListElem(const QCString &k,const TemplateVariant &v) : key(k), value(v) {}
QCString key;
TemplateVariant value;
};
class SortList : public QList<ListElem>
{
public:
SortList() { setAutoDelete(TRUE); }
private:
int compareValues(const ListElem *item1,const ListElem *item2) const
{
return qstrcmp(item1->key,item2->key);
}
};
public:
static TemplateVariant apply(const TemplateVariant &v,const TemplateVariant &args)
{
if (v.type()==TemplateVariant::List && args.type()==TemplateVariant::String)
{
//printf("FilterListSort::apply: v=%s args=%s\n",v.toString().data(),args.toString().data());
TemplateListIntf::ConstIterator *it = v.toList()->createIterator();
TemplateVariant item;
TemplateList *result = TemplateList::alloc();
// 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())
{
TemplateStructIntf *s = item.toStruct();
if (s)
{
QCString sortKey = determineSortKey(s,args.toString());
sortList.append(new ListElem(sortKey,item));
//printf("sortKey=%s\n",sortKey.data());
}
}
delete it;
// sort the list
sortList.sort();
// add sorted items to the result list
QListIterator<ListElem> sit(sortList);
ListElem *elem;
TemplateList *groupList=0;
QCString prevKey;
for (sit.toFirst();(elem=sit.current());++sit)
{
if (groupList==0 || elem->key!=prevKey)
{
groupList = TemplateList::alloc();
result->append(groupList);
prevKey = elem->key;
}
groupList->append(elem->value);
}
return result;
}
return v;
}
private:
static QCString determineSortKey(TemplateStructIntf *s,const QCString &attribName)
{
TemplateVariant v = s->get(attribName);
return v.toString();
}
};
//--------------------------------------------------------------------
/** @brief The implementation of the "paginate" filter */ /** @brief The implementation of the "paginate" filter */
class FilterPaginate class FilterPaginate
{ {
...@@ -1053,7 +1132,7 @@ class FilterAlphaIndex ...@@ -1053,7 +1132,7 @@ class FilterAlphaIndex
private: private:
int compareValues(const ListElem *item1,const ListElem *item2) const int compareValues(const ListElem *item1,const ListElem *item2) const
{ {
return item2->key-item1->key; return item1->key-item2->key;
} }
}; };
static QCString keyToLetter(uint startLetter) static QCString keyToLetter(uint startLetter)
...@@ -1065,7 +1144,7 @@ class FilterAlphaIndex ...@@ -1065,7 +1144,7 @@ class FilterAlphaIndex
char s[10]; char s[10];
if (startLetter>0x20 && startLetter<=0x7f) // printable ASCII character if (startLetter>0x20 && startLetter<=0x7f) // printable ASCII character
{ {
s[0]=(char)startLetter; s[0]=tolower((char)startLetter);
s[1]=0; s[1]=0;
} }
else else
...@@ -1283,6 +1362,7 @@ static TemplateFilterFactory::AutoRegister<FilterNoWrap> fNoWrap("nowrap"); ...@@ -1283,6 +1362,7 @@ static TemplateFilterFactory::AutoRegister<FilterNoWrap> fNoWrap("nowrap");
static TemplateFilterFactory::AutoRegister<FilterFlatten> fFlatten("flatten"); static TemplateFilterFactory::AutoRegister<FilterFlatten> fFlatten("flatten");
static TemplateFilterFactory::AutoRegister<FilterDefault> fDefault("default"); static TemplateFilterFactory::AutoRegister<FilterDefault> fDefault("default");
static TemplateFilterFactory::AutoRegister<FilterPrepend> fPrepend("prepend"); static TemplateFilterFactory::AutoRegister<FilterPrepend> fPrepend("prepend");
static TemplateFilterFactory::AutoRegister<FilterGroupBy> fGroupBy("groupBy");
static TemplateFilterFactory::AutoRegister<FilterListSort> fListSort("listsort"); static TemplateFilterFactory::AutoRegister<FilterListSort> fListSort("listsort");
static TemplateFilterFactory::AutoRegister<FilterPaginate> fPaginate("paginate"); static TemplateFilterFactory::AutoRegister<FilterPaginate> fPaginate("paginate");
static TemplateFilterFactory::AutoRegister<FilterStripPath> fStripPath("stripPath"); static TemplateFilterFactory::AutoRegister<FilterStripPath> fStripPath("stripPath");
...@@ -3706,7 +3786,7 @@ class TemplateNodeWith : public TemplateNodeCreator<TemplateNodeWith> ...@@ -3706,7 +3786,7 @@ class TemplateNodeWith : public TemplateNodeCreator<TemplateNodeWith>
} }
else else
{ {
parser->warn(parser->templateName(),line,"invalid argument '%s' for with tag",arg.data()); parser->warn(parser->templateName(),line,"invalid argument '%s' for 'with' tag",arg.data());
} }
++it; ++it;
} }
...@@ -3813,47 +3893,35 @@ class TemplateNodeSet : public TemplateNodeCreator<TemplateNodeSet> ...@@ -3813,47 +3893,35 @@ class TemplateNodeSet : public TemplateNodeCreator<TemplateNodeSet>
}; };
public: public:
TemplateNodeSet(TemplateParser *parser,TemplateNode *parent,int line,const QCString &data) TemplateNodeSet(TemplateParser *parser,TemplateNode *parent,int line,const QCString &data)
: TemplateNodeCreator<TemplateNodeSet>(parser,parent,line) : TemplateNodeCreator<TemplateNodeSet>(parser,parent,line), m_mapping(0)
{ {
TRACE(("{TemplateNodeSet(%s)\n",data.data())); TRACE(("{TemplateNodeSet(%s)\n",data.data()));
m_args.setAutoDelete(TRUE);
ExpressionParser expParser(parser,line); ExpressionParser expParser(parser,line);
QValueList<QCString> args = split(data," "); // data format: name=expression
QValueListIterator<QCString> it = args.begin(); int j=data.find('=');
while (it!=args.end()) ExprAst *expr = 0;
{ if (j>0 && (expr = expParser.parse(data.mid(j+1))))
QCString arg = *it;
int j=arg.find('=');
if (j>0)
{ {
ExprAst *expr = expParser.parse(arg.mid(j+1)); m_mapping = new Mapping(data.left(j),expr);
if (expr)
{
m_args.append(new Mapping(arg.left(j),expr));
} }
TRACE(("}TemplateNodeSet(%s)\n",data.data()));
} }
else ~TemplateNodeSet()
{ {
parser->warn(parser->templateName(),line,"invalid argument '%s' for with tag",arg.data()); delete m_mapping;
}
++it;
}
TRACE(("}TemplateNodeSet(%s)\n",data.data()));
} }
void render(FTextStream &, TemplateContext *c) void render(FTextStream &, TemplateContext *c)
{ {
TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c); TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c);
ci->setLocation(m_templateName,m_line); ci->setLocation(m_templateName,m_line);
QListIterator<Mapping> it(m_args); if (m_mapping)
Mapping *mapping;
for (it.toFirst();(mapping=it.current());++it)
{ {
TemplateVariant value = mapping->value->resolve(c); TemplateVariant value = m_mapping->value->resolve(c);
ci->set(mapping->name,value); ci->set(m_mapping->name,value);
} }
} }
private: private:
QList<Mapping> m_args; Mapping *m_mapping;
}; };
//---------------------------------------------------------- //----------------------------------------------------------
......
...@@ -406,6 +406,8 @@ class TemplateSpacelessIntf ...@@ -406,6 +406,8 @@ class TemplateSpacelessIntf
public: public:
/** Returns the \a input after removing redundant whitespace */ /** Returns the \a input after removing redundant whitespace */
virtual QCString remove(const QCString &input) = 0; virtual QCString remove(const QCString &input) = 0;
/** Reset filter state */
virtual void reset() = 0;
}; };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment