printdocvisitor.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * $Id: $
00004  *
00005  *
00006  * Copyright (C) 1997-2008 by Dimitri van Heesch.
00007  *
00008  * Permission to use, copy, modify, and distribute this software and its
00009  * documentation under the terms of the GNU General Public License is hereby 
00010  * granted. No representations are made about the suitability of this software 
00011  * for any purpose. It is provided "as is" without express or implied warranty.
00012  * See the GNU General Public License for more details.
00013  *
00014  * Documents produced by Doxygen are derivative works derived from the
00015  * input used in their production; they are not affected by this license.
00016  *
00017  */
00018 
00019 #ifndef _PRINTDOCVISITOR_H
00020 #define _PRINTDOCVISITOR_H
00021 
00022 #include "docvisitor.h"
00023 
00025 class PrintDocVisitor : public DocVisitor
00026 {
00027   public:
00028     PrintDocVisitor() : DocVisitor(DocVisitor_Other), m_indent(0), 
00029                         m_needsEnter(FALSE), m_insidePre(FALSE) {}
00030     
00031     //--------------------------------------
00032     
00033     void visit(DocWord *w)
00034     {
00035       indent_leaf();
00036       printf("%s",w->word().data());
00037     }
00038     void visit(DocLinkedWord *w)
00039     {
00040       indent_leaf();
00041       printf("%s",w->word().data());
00042     }
00043     void visit(DocWhiteSpace *w)
00044     {
00045       indent_leaf();
00046       if (m_insidePre)
00047       {
00048         printf("%s",w->chars().data());
00049       }
00050       else
00051       {
00052         printf(" ");
00053       }
00054     }
00055     void visit(DocSymbol *s)
00056     {
00057       indent_leaf();
00058       switch(s->symbol())
00059       {
00060         case DocSymbol::BSlash:  printf("\\"); break;
00061         case DocSymbol::At:      printf("@"); break;
00062         case DocSymbol::Less:    printf("<"); break;
00063         case DocSymbol::Greater: printf(">"); break;
00064         case DocSymbol::Amp:     printf("&"); break;
00065         case DocSymbol::Dollar:  printf("$"); break;
00066         case DocSymbol::Hash:    printf("#"); break;
00067         case DocSymbol::Percent: printf("%%"); break;
00068         case DocSymbol::Copy:    printf("&copy;"); break;
00069         case DocSymbol::Apos:    printf("'"); break;
00070         case DocSymbol::Quot:    printf("\""); break;
00071         case DocSymbol::Lsquo:   printf("&lsquo;"); break;
00072         case DocSymbol::Rsquo:   printf("&rsquo;"); break;
00073         case DocSymbol::Ldquo:   printf("&ldquo;"); break;
00074         case DocSymbol::Rdquo:   printf("&rdquo;"); break;
00075         case DocSymbol::Ndash:   printf("&ndash;"); break;
00076         case DocSymbol::Mdash:   printf("&mdash;"); break;
00077         case DocSymbol::Uml:     printf("&%cuml;",s->letter()); break;
00078         case DocSymbol::Acute:   printf("&%cacute;",s->letter()); break;
00079         case DocSymbol::Grave:   printf("&%cgrave;",s->letter()); break;
00080         case DocSymbol::Circ:    printf("&%ccirc;",s->letter()); break;
00081         case DocSymbol::Tilde:   printf("&%ctilde;",s->letter()); break;
00082         case DocSymbol::Szlig:   printf("&szlig;"); break;
00083         case DocSymbol::Cedil:   printf("&%ccedul;",s->letter()); break;
00084         case DocSymbol::Ring:    printf("&%cring;",s->letter()); break;
00085         case DocSymbol::Nbsp:    printf("&nbsp;"); break;
00086         default:
00087           printf("Error: unknown symbol found\n");
00088       }
00089     }
00090     void visit(DocURL *u)
00091     {
00092       indent_leaf();
00093       printf("%s",u->url().data());
00094     }
00095     void visit(DocLineBreak *)
00096     {
00097       indent_leaf();
00098       printf("<br/>");
00099     }
00100     void visit(DocHorRuler *)
00101     {
00102       indent_leaf();
00103       printf("<hr>");
00104     }
00105     void visit(DocStyleChange *s)
00106     {
00107       indent_leaf();
00108       switch (s->style())
00109       {
00110         case DocStyleChange::Bold:
00111          if (s->enable()) printf("<bold>"); else printf("</bold>");
00112          break;
00113         case DocStyleChange::Italic:
00114          if (s->enable()) printf("<italic>"); else printf("</italic>");
00115          break;
00116         case DocStyleChange::Code:
00117          if (s->enable()) printf("<code>"); else printf("</code>");
00118          break;
00119         case DocStyleChange::Subscript:
00120          if (s->enable()) printf("<sub>"); else printf("</sub>");
00121          break;
00122         case DocStyleChange::Superscript:
00123          if (s->enable()) printf("<sup>"); else printf("</sup>");
00124          break;
00125         case DocStyleChange::Center:
00126          if (s->enable()) printf("<center>"); else printf("</center>");
00127          break;
00128         case DocStyleChange::Small:
00129          if (s->enable()) printf("<small>"); else printf("</small>");
00130          break;
00131         case DocStyleChange::Preformatted:
00132          if (s->enable()) printf("<pre>"); else printf("</pre>");
00133          break;
00134         case DocStyleChange::Div:
00135          if (s->enable()) printf("<div>"); else printf("</div>");
00136          break;
00137         case DocStyleChange::Span:
00138          if (s->enable()) printf("<span>"); else printf("</span>");
00139          break;
00140       }
00141     }
00142     void visit(DocVerbatim *s)
00143     {
00144       indent_leaf();
00145       switch(s->type())
00146       {
00147         case DocVerbatim::Code: printf("<code>"); break;
00148         case DocVerbatim::Verbatim: printf("<verbatim>"); break;
00149         case DocVerbatim::HtmlOnly: printf("<htmlonly>"); break;
00150         case DocVerbatim::ManOnly: printf("<manonly>"); break;
00151         case DocVerbatim::LatexOnly: printf("<latexonly>"); break;
00152         case DocVerbatim::XmlOnly: printf("<xmlonly>"); break;
00153         case DocVerbatim::Dot: printf("<dot>"); break;
00154         case DocVerbatim::Msc: printf("<msc>"); break;
00155       }
00156       printf("%s",s->text().data());
00157       switch(s->type())
00158       {
00159         case DocVerbatim::Code: printf("</code>"); break;
00160         case DocVerbatim::Verbatim: printf("</verbatim>"); break;
00161         case DocVerbatim::HtmlOnly: printf("</htmlonly>"); break;
00162         case DocVerbatim::ManOnly: printf("</manonly>"); break;
00163         case DocVerbatim::LatexOnly: printf("</latexonly>"); break;
00164         case DocVerbatim::XmlOnly: printf("</xmlonly>"); break;
00165         case DocVerbatim::Dot: printf("</dot>"); break;
00166         case DocVerbatim::Msc: printf("</msc>"); break;
00167       }
00168     }
00169     void visit(DocAnchor *a)
00170     {
00171       indent_leaf();
00172       printf("<anchor name=\"%s\"/>",a->anchor().data());
00173     }
00174     void visit(DocInclude *inc)
00175     {
00176       indent_leaf();
00177       printf("<include file=\"%s\" type=\"",inc->file().data());
00178       switch(inc->type())
00179       {
00180         case DocInclude::Include: printf("include"); break;
00181         case DocInclude::IncWithLines: printf("incwithlines"); break;
00182         case DocInclude::DontInclude: printf("dontinclude"); break;
00183         case DocInclude::HtmlInclude: printf("htmlinclude"); break;
00184         case DocInclude::VerbInclude: printf("verbinclude"); break;
00185       }
00186       printf("\"/>");
00187     }
00188     void visit(DocIncOperator *op)
00189     {
00190       indent_leaf();
00191       printf("<incoperator pattern=\"%s\" type=\"",op->pattern().data());
00192       switch(op->type())
00193       {
00194         case DocIncOperator::Line:     printf("line");     break;
00195         case DocIncOperator::Skip:     printf("skip");     break;
00196         case DocIncOperator::SkipLine: printf("skipline"); break;
00197         case DocIncOperator::Until:    printf("until");    break;
00198       }
00199       printf("\"/>");
00200     }
00201     void visit(DocFormula *f)
00202     {
00203       indent_leaf();
00204       printf("<formula name=%s test=%s/>",f->name().data(),f->text().data());
00205     }
00206     void visit(DocIndexEntry *i)
00207     {
00208       indent_leaf();
00209       printf("<indexentry>%s</indexentry\n",i->entry().data());
00210     }
00211 
00212     //--------------------------------------
00213     
00214     void visitPre(DocAutoList *l)
00215     {
00216       indent_pre();
00217       if (l->isEnumList())
00218       {
00219         printf("<ol>\n");
00220       }
00221       else
00222       {
00223         printf("<ul>\n");
00224       }
00225     }
00226     void visitPost(DocAutoList *l)
00227     {
00228       indent_post();
00229       if (l->isEnumList())
00230       {
00231         printf("</ol>\n");
00232       }
00233       else
00234       {
00235         printf("</ul>\n");
00236       }
00237     }
00238     void visitPre(DocAutoListItem *)
00239     {
00240       indent_pre();
00241       printf("<li>\n");
00242     }
00243     void visitPost(DocAutoListItem *) 
00244     {
00245       indent_post();
00246       printf("</li>\n");
00247     }
00248     void visitPre(DocPara *) 
00249     {
00250       indent_pre();
00251       printf("<para>\n");
00252     }
00253     void visitPost(DocPara *)
00254     {
00255       indent_post();
00256       printf("</para>\n");
00257     }
00258     void visitPre(DocRoot *)
00259     {
00260       indent_pre();
00261       printf("<root>\n");
00262     }
00263     void visitPost(DocRoot *)
00264     {
00265       indent_post();
00266       printf("</root>\n");
00267     }
00268     void visitPre(DocSimpleSect *s)
00269     {
00270       indent_pre();
00271       printf("<simplesect type=");
00272       switch(s->type())
00273       {
00274         case DocSimpleSect::See: printf("see"); break;
00275         case DocSimpleSect::Return: printf("return"); break;
00276         case DocSimpleSect::Author: printf("author"); break;
00277         case DocSimpleSect::Authors: printf("authors"); break;
00278         case DocSimpleSect::Version: printf("version"); break;
00279         case DocSimpleSect::Since: printf("since"); break;
00280         case DocSimpleSect::Date: printf("date"); break;
00281         case DocSimpleSect::Note: printf("note"); break;
00282         case DocSimpleSect::Warning: printf("warning"); break;
00283         case DocSimpleSect::Pre: printf("pre"); break;
00284         case DocSimpleSect::Post: printf("post"); break;
00285         case DocSimpleSect::Invar: printf("invar"); break;
00286         case DocSimpleSect::Remark: printf("remark"); break;
00287         case DocSimpleSect::Attention: printf("attention"); break;
00288         case DocSimpleSect::User: printf("user"); break;
00289         case DocSimpleSect::Rcs: printf("rcs"); break;
00290         case DocSimpleSect::Unknown: printf("unknown"); break;
00291       }
00292       printf(">\n");
00293     }
00294     void visitPost(DocSimpleSect *)
00295     {
00296       indent_post();
00297       printf("</simplesect>\n");
00298     }
00299     void visitPre(DocTitle *)
00300     {
00301       indent_pre();
00302       printf("<title>\n");
00303     }
00304     void visitPost(DocTitle *)
00305     {
00306       indent_post();
00307       printf("</title>\n");
00308     }
00309     void visitPre(DocSimpleList *)
00310     {
00311       indent_pre();
00312       printf("<ul>\n");
00313     }
00314     void visitPost(DocSimpleList *)
00315     {
00316       indent_post();
00317       printf("</ul>\n");
00318     }
00319     void visitPre(DocSimpleListItem *)
00320     {
00321       indent_pre();
00322       printf("<li>\n");
00323     }
00324     void visitPost(DocSimpleListItem *) 
00325     {
00326       indent_post();
00327       printf("</li>\n");
00328     }
00329     void visitPre(DocSection *s)
00330     {
00331       indent_pre();
00332       printf("<sect%d>\n",s->level());
00333     }
00334     void visitPost(DocSection *s) 
00335     {
00336       indent_post();
00337       printf("</sect%d>\n",s->level());
00338     }
00339     void visitPre(DocHtmlList *s)
00340     {
00341       indent_pre();
00342       if (s->type()==DocHtmlList::Ordered) printf("<ol>\n"); else printf("<ul>\n");
00343     }
00344     void visitPost(DocHtmlList *s) 
00345     {
00346       indent_post();
00347       if (s->type()==DocHtmlList::Ordered) printf("</ol>\n"); else printf("</ul>\n");
00348     }
00349     void visitPre(DocHtmlListItem *)
00350     {
00351       indent_pre();
00352       printf("<li>\n");
00353     }
00354     void visitPost(DocHtmlListItem *) 
00355     {
00356       indent_post();
00357       printf("</li>\n");
00358     }
00359     //void visitPre(DocHtmlPre *)
00360     //{
00361     //  indent_pre();
00362     //  printf("<pre>\n");
00363     //  m_insidePre=TRUE;
00364     //}
00365     //void visitPost(DocHtmlPre *) 
00366     //{
00367     //  m_insidePre=FALSE;
00368     //  indent_post();
00369     //  printf("</pre>\n");
00370     //}
00371     void visitPre(DocHtmlDescList *)
00372     {
00373       indent_pre();
00374       printf("<dl>\n");
00375     }
00376     void visitPost(DocHtmlDescList *) 
00377     {
00378       indent_post();
00379       printf("</dl>\n");
00380     }
00381     void visitPre(DocHtmlDescTitle *)
00382     {
00383       indent_pre();
00384       printf("<dt>\n");
00385     }
00386     void visitPost(DocHtmlDescTitle *) 
00387     {
00388       indent_post();
00389       printf("</dt>\n");
00390     }
00391     void visitPre(DocHtmlDescData *)
00392     {
00393       indent_pre();
00394       printf("<dd>\n");
00395     }
00396     void visitPost(DocHtmlDescData *) 
00397     {
00398       indent_post();
00399       printf("</dd>\n");
00400     }
00401     void visitPre(DocHtmlTable *t)
00402     {
00403       indent_pre();
00404       printf("<table rows=\"%d\" cols=\"%d\">\n",
00405           t->numRows(),t->numCols());
00406     }
00407     void visitPost(DocHtmlTable *) 
00408     {
00409       indent_post();
00410       printf("</table>\n");
00411     }
00412     void visitPre(DocHtmlRow *)
00413     {
00414       indent_pre();
00415       printf("<tr>\n");
00416     }
00417     void visitPost(DocHtmlRow *) 
00418     {
00419       indent_post();
00420       printf("</tr>\n");
00421     }
00422     void visitPre(DocHtmlCell *c)
00423     {
00424       indent_pre();
00425       printf("<t%c>\n",c->isHeading()?'h':'d');
00426     }
00427     void visitPost(DocHtmlCell *c) 
00428     {
00429       indent_post();
00430       printf("</t%c>\n",c->isHeading()?'h':'d');
00431     }
00432     void visitPre(DocHtmlCaption *)
00433     {
00434       indent_pre();
00435       printf("<caption>\n");
00436     }
00437     void visitPost(DocHtmlCaption *) 
00438     {
00439       indent_post();
00440       printf("</caption>\n");
00441     }
00442     void visitPre(DocInternal *)
00443     {
00444       indent_pre();
00445       printf("<internal>\n");
00446     }
00447     void visitPost(DocInternal *) 
00448     {
00449       indent_post();
00450       printf("</internal>\n");
00451     }
00452     void visitPre(DocHRef *href)
00453     {
00454       indent_pre();
00455       printf("<a url=\"%s\">\n",href->url().data());
00456     }
00457     void visitPost(DocHRef *) 
00458     {
00459       indent_post();
00460       printf("</a>\n");
00461     }
00462     void visitPre(DocHtmlHeader *header)
00463     {
00464       indent_pre();
00465       printf("<h%d>\n",header->level());
00466     }
00467     void visitPost(DocHtmlHeader *header) 
00468     {
00469       indent_post();
00470       printf("</h%d>\n",header->level());
00471     }
00472     void visitPre(DocImage *img)
00473     {
00474       indent_pre();
00475       printf("<image src=\"%s\" type=\"",img->name().data());
00476       switch(img->type())
00477       {
00478         case DocImage::Html: printf("html"); break;
00479         case DocImage::Latex: printf("latex"); break;
00480         case DocImage::Rtf: printf("rtf"); break;
00481       }
00482       printf("\" width=%s height=%s>\n",img->width().data(),img->height().data());
00483     }
00484     void visitPost(DocImage *) 
00485     {
00486       indent_post();
00487       printf("</image>\n");
00488     }
00489     void visitPre(DocDotFile *df)
00490     {
00491       indent_pre();
00492       printf("<dotfile src=\"%s\">\n",df->name().data());
00493     }
00494     void visitPost(DocDotFile *) 
00495     {
00496       indent_post();
00497       printf("</dotfile>\n");
00498     }
00499     void visitPre(DocLink *lnk)
00500     {
00501       indent_pre();
00502       printf("<link ref=\"%s\" file=\"%s\" anchor=\"%s\">\n",
00503           lnk->ref().data(),lnk->file().data(),lnk->anchor().data());
00504     }
00505     void visitPost(DocLink *) 
00506     {
00507       indent_post();
00508       printf("</link>\n");
00509     }
00510     void visitPre(DocRef *ref)
00511     {
00512       indent_pre();
00513       printf("<ref ref=\"%s\" file=\"%s\" "
00514              "anchor=\"%s\" targetTitle=\"%s\""
00515              " hasLinkText=\"%s\" refToAnchor=\"%s\" refToSection=\"%s\">\n",
00516              ref->ref().data(),ref->file().data(),ref->anchor().data(),
00517              ref->targetTitle().data(),ref->hasLinkText()?"yes":"no",
00518              ref->refToAnchor()?"yes":"no", ref->refToSection()?"yes":"no");
00519     }
00520     void visitPost(DocRef *) 
00521     {
00522       indent_post();
00523       printf("</ref>\n");
00524     }
00525     void visitPre(DocSecRefItem *ref)
00526     {
00527       indent_pre();
00528       printf("<secrefitem target=\"%s\">\n",ref->target().data());
00529     }
00530     void visitPost(DocSecRefItem *) 
00531     {
00532       indent_post();
00533       printf("</secrefitem>\n");
00534     }
00535     void visitPre(DocSecRefList *)
00536     {
00537       indent_pre();
00538       printf("<secreflist>\n");
00539     }
00540     void visitPost(DocSecRefList *) 
00541     {
00542       indent_post();
00543       printf("</secreflist>\n");
00544     }
00545     //void visitPre(DocLanguage *l)
00546     //{
00547     //  indent_pre();
00548     //  printf("<language id=%s>\n",l->id().data());
00549     //}
00550     //void visitPost(DocLanguage *) 
00551     //{
00552     //  indent_post();
00553     //  printf("</language>\n");
00554     //}
00555     void visitPre(DocParamList *pl)
00556     {
00557       indent_pre();
00558       //QStrListIterator sli(pl->parameters());
00559       QListIterator<DocNode> sli(pl->parameters());
00560       //const char *s;
00561       DocNode *param;
00562       printf("<parameters>");
00563       for (sli.toFirst();(param=sli.current());++sli)
00564       {
00565         printf("<param>");
00566         if (param->kind()==DocNode::Kind_Word)
00567         {
00568           visit((DocWord*)param); 
00569         }
00570         else if (param->kind()==DocNode::Kind_LinkedWord)
00571         {
00572           visit((DocLinkedWord*)param); 
00573         }
00574         printf("</param>");
00575       }
00576       printf("\n");
00577     }
00578     void visitPost(DocParamList *)
00579     {
00580       indent_post();
00581       printf("</parameters>\n");
00582     }
00583     void visitPre(DocParamSect *ps)
00584     {
00585       indent_pre();
00586       printf("<paramsect type=");
00587       switch (ps->type())
00588       {
00589         case DocParamSect::Param: printf("param"); break;
00590         case DocParamSect::RetVal: printf("retval"); break;
00591         case DocParamSect::Exception: printf("exception"); break;
00592         case DocParamSect::TemplateParam: printf("templateparam"); break;
00593         case DocParamSect::Unknown: printf("unknown"); break;
00594       }
00595       printf(">\n");
00596     }
00597     void visitPost(DocParamSect *)
00598     {
00599       indent_post();
00600       printf("</paramsect>\n");
00601     }
00602     void visitPre(DocXRefItem *x)
00603     {
00604       indent_pre();
00605       printf("<xrefitem file=\"%s\" anchor=\"%s\" title=\"%s\"/>\n",
00606           x->file().data(),x->anchor().data(),x->title().data());
00607     }
00608     void visitPost(DocXRefItem *)
00609     {
00610       indent_post();
00611       printf("<xrefitem/>\n");
00612     }
00613     void visitPre(DocInternalRef *r)
00614     {
00615       indent_pre();
00616       printf("<internalref file=%s anchor=%s>\n",r->file().data(),r->anchor().data());
00617     }
00618     void visitPost(DocInternalRef *)
00619     {
00620       indent_post();
00621       printf("</internalref>\n");
00622     }
00623     void visitPre(DocCopy *c)
00624     {
00625       indent_pre();
00626       printf("<copy link=\"%s\">\n",c->link().data());
00627     }
00628     void visitPost(DocCopy *)
00629     {
00630       indent_post();
00631       printf("</copy>\n");
00632     }
00633     void visitPre(DocText *)
00634     {
00635       indent_pre();
00636       printf("<text>\n");
00637     }
00638     void visitPost(DocText *)
00639     {
00640       indent_post();
00641       printf("</text>\n");
00642     }
00643 
00644   private:
00645     // helper functions
00646     void indent() 
00647     { 
00648       if (m_needsEnter) printf("\n");
00649       for (int i=0;i<m_indent;i++) printf("."); 
00650       m_needsEnter=FALSE;
00651     } 
00652     void indent_leaf()
00653     {
00654       if (!m_needsEnter) indent();
00655       m_needsEnter=TRUE;
00656     }
00657     void indent_pre()
00658     {
00659       indent();
00660       m_indent++;
00661     }
00662     void indent_post()
00663     {
00664       m_indent--;
00665       indent();
00666     }
00667     
00668     // member variables
00669     int m_indent;
00670     bool m_needsEnter;
00671     bool m_insidePre;
00672 };
00673 
00674 #endif



Generated on Mon Mar 31 10:58:42 2008 by  doxygen 1.5.1