Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
THtml.h
Go to the documentation of this file.
1 // @(#)root/html:$Id$
2 // Author: Nenad Buncic 18/10/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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_THtml
13 #define ROOT_THtml
14 
15 
16 ////////////////////////////////////////////////////////////////////////////
17 // //
18 // THtml //
19 // //
20 // Html generates documentation for all ROOT classes //
21 // using XHTML 1.0 transitional //
22 // //
23 ////////////////////////////////////////////////////////////////////////////
24 
25 #include "THashList.h"
26 
27 #include "THashTable.h"
28 
29 #include "TExMap.h"
30 
31 #include "TROOT.h"
32 
33 #include <map>
34 
35 class TClass;
36 class TClassDocInfo;
37 class TGClient;
38 class TVirtualMutex;
39 
40 class THtml: public TObject {
41 public:
42  //______________________________________________________________
43  // Helper base class.
44  class THelperBase: public TObject {
45  public:
46  THelperBase(): fHtml(0) {}
47  virtual ~THelperBase();
48  void SetOwner(THtml* html);
49  THtml* GetOwner() const { return fHtml; }
50  private:
51  THtml* fHtml; // object owning the helper
52  ClassDef(THelperBase, 0); // a helper object's base class
53  };
54 
55  class TFileSysEntry;
56 
57  //______________________________________________________________
58  // Helper class to translate between classes and their
59  // modules. Can be derived from and thus replaced by
60  // the user; see THtml::SetModuleDefinition().
61  class TModuleDefinition: public THelperBase {
62  public:
63  virtual bool GetModule(TClass* cl, TFileSysEntry* fse, TString& out_modulename) const;
64  ClassDef(TModuleDefinition, 0); // helper class to determine a class's module
65  };
66 
67  //______________________________________________________________
68  // Helper class to translate between classes and their
69  // filenames. Can be derived from and thus replaced by
70  // the user; see THtml::SetFileDefinition().
71  class TFileDefinition: public THelperBase {
72  public:
73  virtual bool GetDeclFileName(const TClass* cl, TString& out_filename, TString& out_fsys,
74  TFileSysEntry** fse = 0) const;
75  virtual bool GetImplFileName(const TClass* cl, TString& out_filename, TString& out_fsys,
76  TFileSysEntry** fse = 0) const;
77  protected:
78  virtual bool GetFileName(const TClass* cl, bool decl, TString& out_filename, TString& out_fsys,
79  TFileSysEntry** fse = 0) const;
80  TString MatchFileSysName(TString& filename, TFileSysEntry** fse = 0) const;
81 
82  void SplitClassIntoDirFile(const TString& clname, TString& dir, TString& filename) const;
83  void NormalizePath(TString& path) const;
84  void ExpandSearchPath(TString& path) const;
85  ClassDef(TFileDefinition, 0); // helper class to determine a class's source files
86  };
87 
88  //______________________________________________________________
89  // Helper class to translate between file names and their
90  // version used for documentation. Can be derived from and thus
91  // replaced by the user; see THtml::SetPathDefinition().
92  class TPathDefinition: public THelperBase {
93  public:
94  virtual bool GetMacroPath(const TString& module, TString& out_dir) const;
95  virtual bool GetIncludeAs(TClass* cl, TString& out_include_as) const;
96  virtual bool GetFileNameFromInclude(const char* included, TString& out_fsname) const;
97  virtual bool GetDocDir(const TString& module, TString& doc_dir) const;
98  protected:
99  ClassDef(TPathDefinition, 0); // helper class to determine directory layouts
100  };
101 
102  class TFileSysDir;
103  class TFileSysDB;
104  //______________________________________________________________
105  // Utility class representing a directory entry
106  class TFileSysEntry: public TObject {
107  public:
108  TFileSysEntry(const char* name, TFileSysDir* parent):
109  fName(name), fParent(parent), fLevel(parent ? parent->GetLevel() + 1 : 0) {}
110  ~TFileSysEntry()
111  {
112  // Required since we overload TObject::Hash.
113  ROOT::CallRecursiveRemoveIfNeeded(*this);
114  }
115  const char* GetName() const { return fName; }
116  virtual ULong_t Hash() const { return fName.Hash(); }
117  virtual void GetFullName(TString& fullname, Bool_t asIncluded) const {
118  if (fParent) {
119  fParent->GetFullName(fullname, asIncluded);
120  if (fullname[0])
121  fullname += "/";
122  } else
123  fullname = "";
124  fullname += fName;
125  }
126 
127  TFileSysDir* GetParent() const { return fParent; }
128  Int_t GetLevel() const { return fLevel; }
129  protected:
130  TString fName; // name of the element
131  TFileSysDir* fParent; // parent directory
132  Int_t fLevel; // level of directory
133  ClassDef(TFileSysEntry, 0); // an entry of the local file system
134  };
135 
136  //______________________________________________________________
137  // Utility class representing a directory
138  class TFileSysDir: public TFileSysEntry {
139  public:
140  TFileSysDir(const char* name, TFileSysDir* parent):
141  TFileSysEntry(name, parent)
142  { fFiles.SetOwner(); fDirs.SetOwner(); }
143  const TList* GetFiles() const { return &fFiles; }
144  const TList* GetSubDirs() const { return &fDirs; }
145 
146  void Recurse(TFileSysDB* db, const char* path);
147 
148  protected:
149  TList fFiles;
150  TList fDirs;
151  ClassDef(TFileSysDir, 0); // an directory of the local file system
152  };
153 
154  //______________________________________________________________
155  // Utility class representing a root directory as specified in
156  // THtml::GetInputPath()
157  class TFileSysRoot: public TFileSysDir {
158  public:
159  TFileSysRoot(const char* name, TFileSysDB* parent):
160  TFileSysDir(name, parent) {}
161  void GetFullName(TString& fullname, Bool_t asIncluded) const {
162  // prepend directory part of THtml::GetInputPath() only
163  // if !asIncluded
164  fullname = "";
165  if (!asIncluded)
166  fullname += fName;
167  }
168 
169  ClassDef(TFileSysRoot, 0); // an root directory of the local file system
170  };
171 
172  //______________________________________________________________
173  // Utility class representing a directory
174  class TFileSysDB: public TFileSysDir {
175  public:
176  TFileSysDB(const char* path, const char* ignorePath, Int_t maxdirlevel):
177  TFileSysDir(path, 0), fEntries(1009, 5), fIgnorePath(ignorePath), fMaxLevel(maxdirlevel)
178  { Fill(); }
179 
180  TExMap& GetMapIno() { return fMapIno; }
181  THashTable& GetEntries() { return fEntries; }
182  const TString& GetIgnore() const { return fIgnorePath; }
183  Int_t GetMaxLevel() const { return fMaxLevel; }
184 
185  protected:
186  void Fill();
187 
188  private:
189  TExMap fMapIno; // inode to TFileSysDir map, to detect softlinks
190  THashTable fEntries; // hash map of all filenames without paths
191  TString fIgnorePath; // regexp of path to ignore while building entry tree
192  Int_t fMaxLevel; // maximum level of directory nesting
193  ClassDef(TFileSysDB, 0); // instance of file system data
194  };
195 
196 
197  //______________________________________________________________
198  // Configuration holder for path related settings
199  struct PathInfo_t {
200  enum EDotAccess {
201  kDotUnknown,
202  kDotFound,
203  kDotNotFound
204  };
205 
206  PathInfo_t():
207  fFoundDot(kDotUnknown),
208 #ifdef R__WIN32
209  fInputPath("./;src/;include/"),
210 #else
211  fInputPath("./:src/:include/"),
212 #endif
213  fIncludePath("include"),
214  // .whatever implicitly ignored, no need to add .svn!
215  fIgnorePath("\\b(include|CVS|test|tutorials|doc|lib|python|demo|freetype-|gdk|libAfterImage|etc|config|build|bin)\\b"),
216  fDocPath("doc"),
217  fMacroPath("macros:."),
218  fOutputDir("htmldoc") {}
219 
220  EDotAccess fFoundDot; // whether dot is accessible
221  TString fInputPath; // directories to look for classes; prepended to Decl/ImplFileName()
222  TString fIncludePath; // directory prefixes (":" delimited) to remove when quoting include files
223  TString fIgnorePath; // regexp pattern for directories to ignore ("\b(CVS|\.svn)\b") for ROOT
224  TString fDocPath; // subdir to check for module documentation ("doc" for ROOT)
225  TString fMacroPath; // subdir of fDocPath for macros run via the Begin/End Macro directive; ("macros" for ROOT)
226  TString fDotDir; // directory of GraphViz's dot binary
227  TString fEtcDir; // directory containing auxiliary files
228  TString fOutputDir; // output directory
229  };
230 
231 
232 public:
233  enum EConvertOutput {
234  kNoOutput, // do not run the source, do not show its output
235  kInterpretedOutput, // interpret the source and show output
236  kCompiledOutput, // run the source through ACLiC and show output
237  kForceOutput = 0x10, // re-generate the output files (canvas PNGs)
238  kSeparateProcessOutput = 0x20 // run the script in a separate process
239  };
240 
241  THtml();
242  virtual ~THtml();
243 
244  static void LoadAllLibs();
245 
246  // Functions to generate documentation
247  void Convert(const char *filename, const char *title,
248  const char *dirname = "", const char *relpath="../",
249  Int_t includeOutput = kNoOutput,
250  const char* context = "");
251  void CreateHierarchy();
252  void MakeAll(Bool_t force=kFALSE, const char *filter="*",
253  int numthreads = 1);
254  void MakeClass(const char *className, Bool_t force=kFALSE);
255  void MakeIndex(const char *filter="*");
256  void MakeTree(const char *className, Bool_t force=kFALSE);
257 
258  // Configuration setters
259  void SetModuleDefinition(const TModuleDefinition& md);
260  void SetFileDefinition(const TFileDefinition& fd);
261  void SetPathDefinition(const TPathDefinition& pd);
262  void SetProductName(const char* product) { fProductName = product; }
263  void SetOutputDir(const char *dir);
264  void SetInputDir(const char *dir);
265  void SetSourceDir(const char *dir) { SetInputDir(dir); }
266  void SetIncludePath(const char* dir) { fPathInfo.fIncludePath = dir; }
267  void SetEtcDir(const char* dir) { fPathInfo.fEtcDir = dir; }
268  void SetDocPath(const char* path) { fPathInfo.fDocPath = path; }
269  void SetDotDir(const char* dir) { fPathInfo.fDotDir = dir; fPathInfo.fFoundDot = PathInfo_t::kDotUnknown; }
270  void SetRootURL(const char* url) { fLinkInfo.fROOTURL = url; }
271  void SetLibURL(const char* lib, const char* url) { fLinkInfo.fLibURLs[lib] = url; }
272  void SetXwho(const char *xwho) { fLinkInfo.fXwho = xwho; }
273  void SetMacroPath(const char* path) {fPathInfo.fMacroPath = path;}
274  void AddMacroPath(const char* path);
275  void SetCounterFormat(const char* format) { fCounterFormat = format; }
276  void SetClassDocTag(const char* tag) { fDocSyntax.fClassDocTag = tag; }
277  void SetAuthorTag(const char* tag) { fDocSyntax.fAuthorTag = tag; }
278  void SetLastUpdateTag(const char* tag) { fDocSyntax.fLastUpdateTag = tag; }
279  void SetCopyrightTag(const char* tag) { fDocSyntax.fCopyrightTag = tag; }
280  void SetHeader(const char* file) { fOutputStyle.fHeader = file; }
281  void SetFooter(const char* file) { fOutputStyle.fFooter = file; }
282  void SetHomepage(const char* url) { fLinkInfo.fHomepage = url; }
283  void SetSearchStemURL(const char* url) { fLinkInfo.fSearchStemURL = url; }
284  void SetSearchEngine(const char* url) { fLinkInfo.fSearchEngine = url; }
285  void SetViewCVS(const char* url) { fLinkInfo.fViewCVS = url; }
286  void SetWikiURL(const char* url) { fLinkInfo.fWikiURL = url; }
287  void SetCharset(const char* charset) { fOutputStyle.fCharset = charset; }
288  void SetDocStyle(const char* style) { fDocSyntax.fDocStyle = style; }
289 
290  // Configuration getters
291  const TModuleDefinition& GetModuleDefinition() const;
292  const TFileDefinition& GetFileDefinition() const;
293  const TPathDefinition& GetPathDefinition() const;
294  const TString& GetProductName() const { return fProductName; }
295  const TString& GetInputPath() const { return fPathInfo.fInputPath; }
296  const TString& GetOutputDir(Bool_t createDir = kTRUE) const;
297  virtual const char* GetEtcDir() const;
298  const TString& GetModuleDocPath() const { return fPathInfo.fDocPath; }
299  const TString& GetDotDir() const { return fPathInfo.fDotDir; }
300  const char* GetURL(const char* lib = 0) const;
301  const TString& GetXwho() const { return fLinkInfo.fXwho; }
302  const TString& GetMacroPath() const { return fPathInfo.fMacroPath; }
303  const char* GetCounterFormat() const { return fCounterFormat; }
304  const TString& GetClassDocTag() const { return fDocSyntax.fClassDocTag; }
305  const TString& GetAuthorTag() const { return fDocSyntax.fAuthorTag; }
306  const TString& GetLastUpdateTag() const { return fDocSyntax.fLastUpdateTag; }
307  const TString& GetCopyrightTag() const { return fDocSyntax.fCopyrightTag; }
308  const TString& GetHeader() const { return fOutputStyle.fHeader; }
309  const TString& GetFooter() const { return fOutputStyle.fFooter; }
310  const TString& GetHomepage() const { return fLinkInfo.fHomepage; }
311  const TString& GetSearchStemURL() const { return fLinkInfo.fSearchStemURL; }
312  const TString& GetSearchEngine() const { return fLinkInfo.fSearchEngine; }
313  const TString& GetViewCVS() const { return fLinkInfo.fViewCVS; }
314  const TString& GetWikiURL() const { return fLinkInfo.fWikiURL; }
315  const TString& GetCharset() const { return fOutputStyle.fCharset; }
316  const TString& GetDocStyle() const { return fDocSyntax.fDocStyle; }
317 
318  // Functions that should only be used by TDocOutput etc.
319  Bool_t CopyFileFromEtcDir(const char* filename) const;
320  virtual void CreateAuxiliaryFiles() const;
321  virtual TClass* GetClass(const char *name) const;
322  const char* ShortType(const char *name) const;
323  const char* GetCounter() const { return fCounter; }
324  void GetModuleMacroPath(const TString& module, TString& out_path) const { GetPathDefinition().GetMacroPath(module, out_path); }
325  virtual bool GetDeclFileName(TClass* cl, Bool_t filesys, TString& out_name) const;
326  void GetDerivedClasses(TClass* cl, std::map<TClass*, Int_t>& derived) const;
327  static const char* GetDirDelimiter() {
328  // ";" on windows, ":" everywhere else
329 #ifdef R__WIN32
330  return ";";
331 #else
332  return ":";
333 #endif
334  }
335  virtual bool GetImplFileName(TClass* cl, Bool_t filesys, TString& out_name) const;
336  virtual void GetHtmlFileName(TClass *classPtr, TString& filename) const;
337  virtual const char* GetHtmlFileName(const char* classname) const;
338  TList* GetLibraryDependencies() { return &fDocEntityInfo.fLibDeps; }
339  void SortListOfModules() { fDocEntityInfo.fModules.Sort(); }
340  const TList* GetListOfModules() const { return &fDocEntityInfo.fModules; }
341  const TList* GetListOfClasses() const { return &fDocEntityInfo.fClasses; }
342  TFileSysDB* GetLocalFiles() const { if (!fLocalFiles) SetLocalFiles(); return fLocalFiles; }
343  TVirtualMutex* GetMakeClassMutex() const { return fMakeClassMutex; }
344  virtual void GetModuleNameForClass(TString& module, TClass* cl) const;
345  const PathInfo_t& GetPathInfo() const { return fPathInfo; }
346  Bool_t HaveDot();
347  void HelperDeleted(THelperBase* who);
348  static Bool_t IsNamespace(const TClass*cl);
349  void SetDeclFileName(TClass* cl, const char* filename);
350  void SetFoundDot(Bool_t found = kTRUE);
351  void SetImplFileName(TClass* cl, const char* filename);
352  void SetBatch(Bool_t batch = kTRUE) { fBatch = batch; }
353  Bool_t IsBatch() const { return fBatch; }
354  // unused
355  void ReplaceSpecialChars(std::ostream&, const char*) {
356  Error("ReplaceSpecialChars",
357  "Removed, call TDocOutput::ReplaceSpecialChars() instead!"); }
358  void SetEscape(char /*esc*/ ='\\') {} // for backward comp
359 
360 protected:
361  struct DocSyntax_t {
362  TString fClassDocTag; // tag for class documentation
363  TString fAuthorTag; // tag for author
364  TString fLastUpdateTag; // tag for last update
365  TString fCopyrightTag; // tag for copyright
366  TString fDocStyle; // doc style (only "Doc++" has special treatment)
367  };
368 
369  struct LinkInfo_t {
370  TString fXwho; // URL for name lookup
371  TString fROOTURL; // Root URL for ROOT's reference guide for libs that are not in fLibURLs
372  std::map<std::string, TString> fLibURLs; // URL for documentation of external libraries
373  TString fHomepage; // URL of homepage
374  TString fSearchStemURL; // URL stem used to build search URL
375  TString fSearchEngine; // link to search engine
376  TString fViewCVS; // link to ViewCVS; %f is replaced by the filename (no %f: it's appended)
377  TString fWikiURL; // URL stem of class's wiki page, %c replaced by mangled class name (no %c: appended)
378  };
379 
380  struct OutputStyle_t {
381  TString fHeader; // header file name
382  TString fFooter; // footerer file name
383  TString fCharset; // Charset for doc pages
384  };
385 
386  struct DocEntityInfo_t {
387  DocEntityInfo_t(): fClasses(503, 3) {}
388  TString fClassFilter; // filter used for buidling known classes
389  THashList fClasses; // known classes
390  mutable THashList fShortClassNames; // class names with default template args replaced
391  THashList fModules; // known modules
392  THashList fLibDeps; // Library dependencies
393  };
394 
395 protected:
396  virtual void CreateJavascript() const;
397  virtual void CreateStyleSheet() const;
398  void CreateListOfTypes();
399  void CreateListOfClasses(const char* filter);
400  virtual bool GetDeclImplFileName(TClass* cl, bool filesys, bool decl, TString& out_name) const;
401  void MakeClass(void* cdi, Bool_t force=kFALSE);
402  TClassDocInfo *GetNextClass();
403  void SetLocalFiles() const;
404 
405  static void *MakeClassThreaded(void* info);
406 
407 protected:
408  TString fCounter; // counter string
409  TString fCounterFormat; // counter printf-like format
410  TString fProductName; // name of the product to document
411  TIter *fThreadedClassIter; // fClasses iterator for MakeClassThreaded
412  Int_t fThreadedClassCount; // counter of processed classes for MakeClassThreaded
413  TVirtualMutex *fMakeClassMutex; // Mutex for MakeClassThreaded
414  TGClient *fGClient; // gClient, cached and queried through CINT
415  DocSyntax_t fDocSyntax; // doc syntax configuration
416  LinkInfo_t fLinkInfo; // link (URL) configuration
417  OutputStyle_t fOutputStyle; // output style configuration
418  mutable PathInfo_t fPathInfo; // path configuration
419  DocEntityInfo_t fDocEntityInfo; // data for documented entities
420  mutable TPathDefinition *fPathDef; // object translating classes to module names
421  mutable TModuleDefinition *fModuleDef; // object translating classes to module names
422  mutable TFileDefinition* fFileDef; // object translating classes to file names
423  mutable TFileSysDB *fLocalFiles; // files found locally for a given source path
424  Bool_t fBatch; // Whether to enable GUI output
425 
426  ClassDef(THtml,0) //Convert class(es) into HTML file(s)
427 };
428 
429 R__EXTERN THtml *gHtml;
430 
431 #endif