Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TDocDirective.h
Go to the documentation of this file.
1 // @(#)root/html:$Id$
2 // Author: Axel Naumann 2007-01-25
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TDocDirective
13 #define ROOT_TDocDirective
14 
15 ////////////////////////////////////////////////////////////////////////////
16 // //
17 // TDocDirective //
18 // //
19 // Special treatment of comments, like HTML source, a macro, or latex. //
20 // //
21 ////////////////////////////////////////////////////////////////////////////
22 
23 #include "TNamed.h"
24 
25 
26 class TClass;
27 class TDocParser;
28 class TDocOutput;
29 class THtml;
30 class TLatex;
31 class TMacro;
32 class TVirtualPad;
33 
34 class TDocDirective: public TNamed {
35 protected:
36  TDocParser* fDocParser; // parser invoking this handler
37  THtml* fHtml; // parser's THtml object
38  TDocOutput* fDocOutput; // parser invoking this handler
39  TString fParameters; // parameters to the directive
40  Int_t fCounter; // counter to generate unique names, -1 to ignore
41 
42  virtual void AddParameter(const TString& /*name*/, const char* /*value*/ = 0) {}
43 
44  TDocDirective() {}
45  TDocDirective(const char* name):
46  TNamed(name, ""), fDocParser(0), fHtml(0), fDocOutput(0), fCounter(-1) {};
47  virtual ~TDocDirective() {}
48 
49  const char* GetName() const { return TNamed::GetName(); }
50  void GetName(TString& name) const;
51  TDocParser* GetDocParser() const { return fDocParser; }
52  TDocOutput* GetDocOutput() const { return fDocOutput; }
53  THtml* GetHtml() const { return fHtml; }
54  const char* GetOutputDir() const;
55 
56  void SetParser(TDocParser* parser);
57  void SetParameters(const char* params);
58  void SetTag(const char* tag) { SetTitle(tag); }
59  void SetCounter(Int_t count) { fCounter = count; }
60  virtual void DeleteOutputFiles(const char* ext) const;
61 
62 public:
63  // get the tag ending this directive
64  virtual const char* GetEndTag() const = 0;
65 
66  // add a line to the directive's text
67  virtual void AddLine(const TSubString& line) = 0;
68 
69  // retrieve the result (replacement) of the directive; return false if invalid
70  virtual Bool_t GetResult(TString& result) = 0;
71 
72  // Delete output for the parser's current class or module.
73  virtual void DeleteOutput() const {}
74 
75  friend class TDocParser;
76 
77  ClassDef(TDocDirective, 0); // THtml directive handler
78 };
79 
80 class TDocHtmlDirective: public TDocDirective {
81 private:
82  TString fText; // HTML text to be kept
83  Bool_t fVerbatim; // whether we are in a <pre></pre> block
84 public:
85  TDocHtmlDirective(): TDocDirective("HTML"), fVerbatim(kFALSE) {}
86  virtual ~TDocHtmlDirective() {}
87 
88  virtual void AddLine(const TSubString& line);
89  virtual const char* GetEndTag() const { return "end_html"; }
90  virtual Bool_t GetResult(TString& result);
91 
92  ClassDef(TDocHtmlDirective, 0); // Handler for "Begin_Html"/"End_Html" for raw HTML in documentation comments
93 };
94 
95 class TDocMacroDirective: public TDocDirective {
96 private:
97  TMacro* fMacro; // macro to be executed
98  Bool_t fNeedGraphics; // if set, we cannot switch to batch mode
99  Bool_t fShowSource; // whether a source tab should be created
100  Bool_t fIsFilename; // whether the directive is a failename to be executed
101 
102  virtual void AddParameter(const TString& name, const char* value = 0);
103  TString CreateSubprocessInputFile();
104 
105 public:
106  TDocMacroDirective():
107  TDocDirective("MACRO"), fMacro(0), fNeedGraphics(kFALSE),
108  fShowSource(kFALSE), fIsFilename(kTRUE) {};
109  virtual ~TDocMacroDirective();
110 
111  virtual void AddLine(const TSubString& line);
112  virtual const char* GetEndTag() const { return "end_macro"; }
113  virtual Bool_t GetResult(TString& result);
114  // Delete output for the parser's current class or module.
115  virtual void DeleteOutput() const { DeleteOutputFiles(".gif"); }
116 
117  static void SubProcess(const TString& what, const TString& out);
118 
119  ClassDef(TDocMacroDirective, 0); // Handler for "Begin_Macro"/"End_Macro" for code that is executed and that can generate an image for documentation
120 };
121 
122 class TDocLatexDirective: public TDocDirective {
123 protected:
124  TMacro* fLatex; // collection of lines
125  Int_t fFontSize; // fontsize for current latex block, in pixels
126  TString fSeparator; // column separator, often "="
127  Bool_t fSepIsRegexp; // whether fSeparator is a regexp expression
128  TString fAlignment; // column alignment: 'l' for justify left, 'c' for center, 'r' for right
129  TVirtualPad* fBBCanvas; // canvas for bounding box determination
130 
131  virtual void CreateLatex(const char* filename);
132  virtual void AddParameter(const TString& name, const char* value = 0);
133  virtual void GetBoundingBox(TLatex& latex, const char* text, Float_t& width, Float_t& height);
134 
135 public:
136  TDocLatexDirective():
137  TDocDirective("LATEX"), fLatex(0), fFontSize(16),
138  fSepIsRegexp(kFALSE), fBBCanvas(0) {};
139  virtual ~TDocLatexDirective();
140 
141  virtual void AddLine(const TSubString& line);
142  virtual const char* GetEndTag() const {return "end_latex";}
143 
144  const char* GetAlignment() const {return fAlignment;}
145  const char* GetSeparator() const {return fSeparator;}
146  Bool_t SeparatorIsRegexp() const {return fSepIsRegexp;}
147  Int_t GetFontSize() const {return fFontSize;}
148  TList* GetListOfLines() const;
149 
150  virtual Bool_t GetResult(TString& result);
151  // Delete output for the parser's current class or module.
152  virtual void DeleteOutput() const { DeleteOutputFiles(".gif"); }
153 
154  ClassDef(TDocLatexDirective, 0); // Handler for "Begin_Latex"/"End_Latex" to generate an image from latex
155 };
156 
157 #endif // ROOT_TDocDirective