/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set et sw=2 ts=2: */ /*************************************************************************** * generate.cc * * Thu Mar 24 12:09:33 CET 2011 * Copyright 2011 Bent Bisballe Nyeng * deva@aasimon.org ****************************************************************************/ /* * This file is part of Pracro. * * Pracro is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Pracro is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Pracro; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "generate.h" #include #include #include #include "genimage.h" static QString function(QString f) { QString out; if(f.indexOf(" ") > f.indexOf("(") || f.indexOf(" ") == -1) { printf("MISSING return type in \"%s\".\n", f.toStdString().c_str()); return f; } QString ret = f.left(f.indexOf(" ")); QString name = f.mid(f.indexOf(" ") + 1, f.indexOf("(") - f.indexOf(" ") - 1); QString ps = f.mid(f.indexOf("(") + 1, f.indexOf(")") - f.indexOf("(") - 1); QStringList parms = ps.split(","); out += "" + ret + " "; out += "" + name + ""; out += "("; for(int i = 0; i < parms.size(); i++) { QStringList l = parms.at(i).split(" ", QString::SkipEmptyParts); if(l.length() != 2) { out += parms.at(i); continue; } QString type = l.at(0); QString name = l.at(1); if(i != 0) out += ", "; out += "" + type + ""; out += " " + name + ""; } out += ")"; return out; } static QString generateMethods(QVector meths) { QString out; foreach(Method meth, meths) { out += "
\n"; out += "
" + function(meth.name) + "
\n"; out += "
" + meth.description + "
\n"; if(meth.parameters.size()) { out += "
\n"; foreach(Parameter parm, meth.parameters) { out += "
\n"; out += "
" + parm.name + "
\n"; out += "
" + parm.description + "
\n"; out += "
\n"; } out += "
\n"; } if(meth.returns != "") { out += "
Returns " + meth.returns + "
\n"; } out += "
\n"; } return out; } static QString generateAttributes(QVector attrs) { QString out; foreach(Attribute attr, attrs) { out += "
\n"; out += "
" + attr.name + "
\n"; out += "
" + attr.description + "
\n"; out += "
\n"; } return out; } static QString generateMethodOverview(Doc &doc, QMap > &imeths) { QString out; out += "

Method overview

\n"; QVector meths; meths += doc.methods; QMap >::iterator j = imeths.begin(); while(j != imeths.end()) { meths += j.value(); j++; } // sort for(int i = 0; i < meths.size(); i++) { for(int j = 0; j < meths.size(); j++) { if(meths[i].name < meths[j].name) { Method tmp = meths[i]; meths[i] = meths[j]; meths[j] = tmp; } } } out += "
    \n"; foreach(Method meth, meths) { out += "
  • "+meth.name+" " + meth.description.left(meth.description.indexOf(".") + 1) + "
  • \n"; } out += "
\n"; return out; } QString generate(Doc &doc, QMap > &meths, QMap > &atts) { QString out; out += " \n"; out += "
\n"; out += "

" + doc.title + "

\n"; if(doc.tag != "" ){ out += "
<" + doc.tag + " />
\n"; } if(doc.container) { out += "
Widget is a container.
\n"; } if(doc.extends != "") { out += " \n"; } if(doc.screenshot) { genImage(doc.tag); out += "
\n"; out += " \n"; out += "
\n"; } out += "
\n"; out += doc.description; out += "
\n"; out += "

Attributes

\n"; out += "
\n"; if(doc.attributes.size()) { out += generateAttributes(doc.attributes); } QMap >::iterator i = atts.begin(); while(i != atts.end()) { out += "

Attributes inherited from "+i.key()+":

\n"; out += generateAttributes(i.value()); i++; } out += "
\n"; out += generateMethodOverview(doc, meths); out += "

Methods

\n"; out += "
\n"; if(doc.methods.size()) { out += generateMethods(doc.methods); } QMap >::iterator j = meths.begin(); while(j != meths.end()) { out += "

Methods inherited from "+j.key()+":

\n"; out += generateMethods(j.value()); j++; } out += "
\n"; out += "
\n"; out += "
This documentation is generated for" " Pracro" " version "VERSION" at "+QDate::currentDate().toString()+"
\n"; return out; } #ifdef TEST_GENERATE //Additional dependency files //deps: //Required cflags (autoconf vars may be used) //cflags: //Required link options (autoconf vars may be used) //libs: #include "test.h" TEST_BEGIN; // TODO: Put some testcode here (see test.h for usable macros). TEST_TRUE(false, "No tests yet!"); TEST_END; #endif/*TEST_GENERATE*/