THtml.h

Go to the documentation of this file.
00001 // @(#)root/html:$Id: THtml.h 27910 2009-03-21 17:26:55Z axel $
00002 // Author: Nenad Buncic   18/10/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_THtml
00013 #define ROOT_THtml
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////////////
00017 //                                                                        //
00018 // THtml                                                                  //
00019 //                                                                        //
00020 // Html generates documentation for all ROOT classes                      //
00021 // using XHTML 1.0 transitional                                           //
00022 //                                                                        //
00023 ////////////////////////////////////////////////////////////////////////////
00024 
00025 #ifndef ROOT_THashList
00026 #include "THashList.h"
00027 #endif
00028 
00029 #ifndef ROOT_THashTable
00030 #include "THashTable.h"
00031 #endif
00032 
00033 #ifndef ROOT_TExMap
00034 #include "TExMap.h"
00035 #endif
00036 
00037 #include <map>
00038 
00039 class TClass;
00040 class TClassDocInfo;
00041 class TGClient;
00042 class TVirtualMutex;
00043 
00044 class THtml: public TObject {
00045 public:
00046    //______________________________________________________________
00047    // Helper base class.
00048    class THelperBase: public TObject {
00049    public:
00050       THelperBase(): fHtml(0) {}
00051       virtual ~THelperBase();
00052       void    SetOwner(THtml* html);
00053       THtml*  GetOwner() const { return fHtml; }
00054    private:
00055       THtml*  fHtml; // object owning the helper
00056       ClassDef(THelperBase, 0); // a helper object's base class
00057    };
00058 
00059    class TFileSysEntry;
00060 
00061    //______________________________________________________________
00062    // Helper class to translate between classes and their
00063    // modules. Can be derived from and thus replaced by
00064    // the user; see THtml::SetModuleDefinition().
00065    class TModuleDefinition: public THelperBase {
00066    public:
00067       virtual bool GetModule(TClass* cl, TFileSysEntry* fse, TString& out_modulename) const;
00068       ClassDef(TModuleDefinition, 0); // helper class to determine a class's module
00069    };
00070 
00071    //______________________________________________________________
00072    // Helper class to translate between classes and their
00073    // filenames. Can be derived from and thus replaced by
00074    // the user; see THtml::SetFileDefinition().
00075    class TFileDefinition: public THelperBase {
00076    public:
00077       virtual bool GetDeclFileName(const TClass* cl, TString& out_filename, TString& out_fsys,
00078                                    TFileSysEntry** fse = 0) const;
00079       virtual bool GetImplFileName(const TClass* cl, TString& out_filename, TString& out_fsys,
00080                                    TFileSysEntry** fse = 0) const;
00081    protected:
00082       virtual bool GetFileName(const TClass* cl, bool decl, TString& out_filename, TString& out_fsys,
00083                                TFileSysEntry** fse = 0) const;
00084       TString MatchFileSysName(TString& filename, TFileSysEntry** fse = 0) const;
00085 
00086       void SplitClassIntoDirFile(const TString& clname, TString& dir, TString& filename) const;
00087       void NormalizePath(TString& path) const;
00088       void ExpandSearchPath(TString& path) const;
00089       ClassDef(TFileDefinition, 0); // helper class to determine a class's source files
00090    };
00091 
00092    //______________________________________________________________
00093    // Helper class to translate between file names and their
00094    // version used for documentation. Can be derived from and thus
00095    // replaced by the user; see THtml::SetPathDefinition().
00096    class TPathDefinition: public THelperBase {
00097    public:
00098       virtual bool GetMacroPath(const TString& module, TString& out_dir) const;
00099       virtual bool GetIncludeAs(TClass* cl, TString& out_include_as) const;
00100       virtual bool GetFileNameFromInclude(const char* included, TString& out_fsname) const;
00101       virtual bool GetDocDir(const TString& module, TString& doc_dir) const;
00102    protected:
00103       ClassDef(TPathDefinition, 0); // helper class to determine directory layouts
00104    };
00105 
00106    class TFileSysDir;
00107    class TFileSysDB;
00108    //______________________________________________________________
00109    // Utility class representing a directory entry
00110    class TFileSysEntry: public TObject {
00111    public:
00112       TFileSysEntry(const char* name, TFileSysDir* parent):
00113          fName(name), fParent(parent), fLevel(parent ? parent->GetLevel() + 1 : 0) {}
00114       const char* GetName() const { return fName; }
00115       virtual ULong_t Hash() const { return fName.Hash(); }
00116       virtual void GetFullName(TString& fullname, Bool_t asIncluded) const {
00117          if (fParent) {
00118             fParent->GetFullName(fullname, asIncluded);
00119             if (fullname[0])
00120                fullname += "/";
00121          } else
00122             fullname = "";
00123          fullname += fName;
00124       }
00125 
00126       TFileSysDir* GetParent() const { return fParent; }
00127       Int_t GetLevel() const { return fLevel; }
00128    protected:
00129       TString      fName; // name of the element
00130       TFileSysDir* fParent; // parent directory
00131       Int_t        fLevel; // level of directory
00132       ClassDef(TFileSysEntry, 0); // an entry of the local file system
00133    };
00134 
00135    //______________________________________________________________
00136    // Utility class representing a directory
00137    class TFileSysDir: public TFileSysEntry {
00138    public:
00139       TFileSysDir(const char* name, TFileSysDir* parent):
00140          TFileSysEntry(name, parent)
00141       { fFiles.SetOwner(); fDirs.SetOwner(); }
00142       const TList* GetFiles() const { return &fFiles; }
00143       const TList* GetSubDirs() const { return &fDirs; }
00144 
00145       void Recurse(TFileSysDB* db, const char* path);
00146 
00147    protected:
00148       TList fFiles;
00149       TList fDirs;
00150       ClassDef(TFileSysDir, 0); // an directory of the local file system
00151    };
00152 
00153    //______________________________________________________________
00154    // Utility class representing a root directory as specified in
00155    // THtml::GetInputPath()
00156    class TFileSysRoot: public TFileSysDir {
00157    public:
00158       TFileSysRoot(const char* name, TFileSysDB* parent):
00159          TFileSysDir(name, parent) {}
00160       void GetFullName(TString& fullname, Bool_t asIncluded) const {
00161          // prepend directory part of THtml::GetInputPath() only
00162          // if !asIncluded
00163          fullname = "";
00164          if (!asIncluded)
00165             fullname += fName;
00166       }
00167 
00168       ClassDef(TFileSysRoot, 0); // an root directory of the local file system
00169    };
00170 
00171    //______________________________________________________________
00172    // Utility class representing a directory
00173    class TFileSysDB: public TFileSysDir {
00174    public:
00175       TFileSysDB(const char* path, const char* ignore, Int_t maxdirlevel):
00176          TFileSysDir(path, 0), fEntries(1009, 5), fIgnorePath(ignore), fMaxLevel(maxdirlevel)
00177       { Fill(); }
00178 
00179       TExMap& GetMapIno() { return fMapIno; }
00180       THashTable& GetEntries() { return fEntries; }
00181       const TString& GetIgnore() const { return fIgnorePath; }
00182       Int_t   GetMaxLevel() const { return fMaxLevel; }
00183 
00184    protected:
00185       void Fill();
00186 
00187    private:
00188       TExMap   fMapIno; // inode to TFileSysDir map, to detect softlinks
00189       THashTable fEntries; // hash map of all filenames without paths
00190       TString  fIgnorePath; // regexp of path to ignore while building entry tree
00191       Int_t    fMaxLevel; // maximum level of directory nesting
00192       ClassDef(TFileSysDB, 0); // instance of file system data
00193    };
00194 
00195 
00196    //______________________________________________________________
00197    // Configuration holder for path related settings
00198    struct PathInfo_t {
00199       enum EDotAccess {
00200          kDotUnknown,
00201          kDotFound,
00202          kDotNotFound
00203       };
00204 
00205       PathInfo_t():
00206          fFoundDot(kDotUnknown),
00207 #ifdef R__WIN32
00208          fInputPath("./;src/;include/"),
00209 #else
00210          fInputPath("./:src/:include/"),
00211 #endif
00212          fIncludePath("include"),
00213          // .whatever implicitly ignored, no need to add .svn!
00214          fIgnorePath("\\b(include|CVS|test|tutorials|doc|lib|python|demo|freetype-|gdk|libAfterImage|etc|config|build|bin)\\b"),
00215          fDocPath("doc"),
00216          fMacroPath("macros:."),
00217          fOutputDir("htmldoc") {}
00218 
00219       EDotAccess     fFoundDot;        // whether dot is accessible
00220       TString        fInputPath;       // directories to look for classes; prepended to Decl/ImplFileName()
00221       TString        fIncludePath;     // directory prefixes (":" delimited) to remove when quoting include files
00222       TString        fIgnorePath;      // regexp pattern for directories to ignore ("\b(CVS|\.svn)\b") for ROOT
00223       TString        fDocPath;         // subdir to check for module documentation ("doc" for ROOT)
00224       TString        fMacroPath;       // subdir of fDocPath for macros run via the Begin/End Macro directive; ("macros" for ROOT)
00225       TString        fDotDir;          // directory of GraphViz's dot binary
00226       TString        fEtcDir;          // directory containing auxiliary files
00227       TString        fOutputDir;       // output directory
00228    };
00229 
00230 
00231 public:
00232    enum EConvertOutput {
00233       kNoOutput, // do not run the source, do not show its output
00234       kInterpretedOutput, // interpret the source and show output
00235       kCompiledOutput, // run the source through ACLiC and show output
00236       kForceOutput = 0x10, // re-generate the output files (canvas PNGs)
00237       kSeparateProcessOutput = 0x20 // run the script in a separate process
00238    };
00239 
00240    THtml();
00241    virtual      ~THtml();
00242 
00243    static void   LoadAllLibs();
00244 
00245    // Functions to generate documentation
00246    void          Convert(const char *filename, const char *title, 
00247                          const char *dirname = "", const char *relpath="../",
00248                          Int_t includeOutput = kNoOutput,
00249                          const char* context = "");
00250    void          CreateHierarchy();
00251    void          MakeAll(Bool_t force=kFALSE, const char *filter="*",
00252                          int numthreads = 1);
00253    void          MakeClass(const char *className, Bool_t force=kFALSE);
00254    void          MakeIndex(const char *filter="*");
00255    void          MakeTree(const char *className, Bool_t force=kFALSE);
00256 
00257    // Configuration setters
00258    void          SetModuleDefinition(const TModuleDefinition& md);
00259    void          SetFileDefinition(const TFileDefinition& fd);
00260    void          SetPathDefinition(const TPathDefinition& pd);
00261    void          SetProductName(const char* product) { fProductName = product; }
00262    void          SetOutputDir(const char *dir);
00263    void          SetInputDir(const char *dir);
00264    void          SetSourceDir(const char *dir) { SetInputDir(dir); }
00265    void          SetIncludePath(const char* dir) { fPathInfo.fIncludePath = dir; }
00266    void          SetEtcDir(const char* dir) { fPathInfo.fEtcDir = dir; }
00267    void          SetDocPath(const char* path) { fPathInfo.fDocPath = path; }
00268    void          SetDotDir(const char* dir) { fPathInfo.fDotDir = dir; fPathInfo.fFoundDot = PathInfo_t::kDotUnknown; }
00269    void          SetRootURL(const char* url) { fLinkInfo.fROOTURL = url; }
00270    void          SetLibURL(const char* lib, const char* url) { fLinkInfo.fLibURLs[lib] = url; }
00271    void          SetXwho(const char *xwho) { fLinkInfo.fXwho = xwho; }
00272    void          SetMacroPath(const char* path) {fPathInfo.fMacroPath = path;}
00273    void          AddMacroPath(const char* path);
00274    void          SetCounterFormat(const char* format) { fCounterFormat = format; }
00275    void          SetClassDocTag(const char* tag) { fDocSyntax.fClassDocTag = tag; }
00276    void          SetAuthorTag(const char* tag) { fDocSyntax.fAuthorTag = tag; }
00277    void          SetLastUpdateTag(const char* tag) { fDocSyntax.fLastUpdateTag = tag; }
00278    void          SetCopyrightTag(const char* tag) { fDocSyntax.fCopyrightTag = tag; }
00279    void          SetHeader(const char* file) { fOutputStyle.fHeader = file; }
00280    void          SetFooter(const char* file) { fOutputStyle.fFooter = file; }
00281    void          SetHomepage(const char* url) { fLinkInfo.fHomepage = url; }
00282    void          SetSearchStemURL(const char* url) { fLinkInfo.fSearchStemURL = url; }
00283    void          SetSearchEngine(const char* url) { fLinkInfo.fSearchEngine = url; }
00284    void          SetViewCVS(const char* url) { fLinkInfo.fViewCVS = url; }
00285    void          SetWikiURL(const char* url) { fLinkInfo.fWikiURL = url; }
00286    void          SetCharset(const char* charset) { fOutputStyle.fCharset = charset; }
00287    void          SetDocStyle(const char* style) { fDocSyntax.fDocStyle = style; }
00288 
00289    // Configuration getters
00290    const TModuleDefinition& GetModuleDefinition() const;
00291    const TFileDefinition&   GetFileDefinition() const;
00292    const TPathDefinition&   GetPathDefinition() const;
00293    const TString&      GetProductName() const { return fProductName; }
00294    const TString&      GetInputPath() const { return fPathInfo.fInputPath; }
00295    const TString&      GetOutputDir(Bool_t createDir = kTRUE) const;
00296    virtual const char* GetEtcDir() const;
00297    const TString&      GetModuleDocPath() const { return fPathInfo.fDocPath; }
00298    const TString&      GetDotDir() const { return fPathInfo.fDotDir; }
00299    const char*         GetURL(const char* lib = 0) const;
00300    const TString&      GetXwho() const { return fLinkInfo.fXwho; }
00301    const TString&      GetMacroPath() const { return fPathInfo.fMacroPath; }
00302    const char*         GetCounterFormat() const { return fCounterFormat; }
00303    const TString&      GetClassDocTag() const { return fDocSyntax.fClassDocTag; }
00304    const TString&      GetAuthorTag() const { return fDocSyntax.fAuthorTag; }
00305    const TString&      GetLastUpdateTag() const { return fDocSyntax.fLastUpdateTag; }
00306    const TString&      GetCopyrightTag() const { return fDocSyntax.fCopyrightTag; }
00307    const TString&      GetHeader() const { return fOutputStyle.fHeader; }
00308    const TString&      GetFooter() const { return fOutputStyle.fFooter; }
00309    const TString&      GetHomepage() const { return fLinkInfo.fHomepage; }
00310    const TString&      GetSearchStemURL() const { return fLinkInfo.fSearchStemURL; }
00311    const TString&      GetSearchEngine() const { return fLinkInfo.fSearchEngine; }
00312    const TString&      GetViewCVS() const { return fLinkInfo.fViewCVS; }
00313    const TString&      GetWikiURL() const { return fLinkInfo.fWikiURL; }
00314    const TString&      GetCharset() const { return fOutputStyle.fCharset; }
00315    const TString&      GetDocStyle() const { return fDocSyntax.fDocStyle; }
00316 
00317    // Functions that should only be used by TDocOutput etc.
00318    Bool_t              CopyFileFromEtcDir(const char* filename) const;
00319    virtual void        CreateAuxiliaryFiles() const;
00320    virtual TClass*     GetClass(const char *name) const;
00321    const char*         ShortType(const char *name) const;
00322    const char*         GetCounter() const { return fCounter; }
00323    void                GetModuleMacroPath(const TString& module, TString& out_path) const { GetPathDefinition().GetMacroPath(module, out_path); }
00324    virtual bool        GetDeclFileName(TClass* cl, Bool_t filesys, TString& out_name) const;
00325    void                GetDerivedClasses(TClass* cl, std::map<TClass*, Int_t>& derived) const;
00326    static const char*  GetDirDelimiter() {
00327       // ";" on windows, ":" everywhere else
00328 #ifdef R__WIN32
00329       return ";";
00330 #else
00331       return ":";
00332 #endif
00333    }
00334    virtual bool        GetImplFileName(TClass* cl, Bool_t filesys, TString& out_name) const;
00335    virtual void        GetHtmlFileName(TClass *classPtr, TString& filename) const;
00336    virtual const char* GetHtmlFileName(const char* classname) const;
00337    TList*              GetLibraryDependencies() { return &fDocEntityInfo.fLibDeps; }
00338    void                SortListOfModules() { fDocEntityInfo.fModules.Sort(); }
00339    const TList*        GetListOfModules() const { return &fDocEntityInfo.fModules; }
00340    const TList*        GetListOfClasses() const { return &fDocEntityInfo.fClasses; }
00341    TFileSysDB*         GetLocalFiles() const { if (!fLocalFiles) SetLocalFiles(); return fLocalFiles; }
00342    TVirtualMutex*      GetMakeClassMutex() const { return  fMakeClassMutex; }
00343    virtual void        GetModuleNameForClass(TString& module, TClass* cl) const;
00344    const PathInfo_t&    GetPathInfo() const { return fPathInfo; }
00345    Bool_t              HaveDot();
00346    void                HelperDeleted(THelperBase* who);
00347    static Bool_t       IsNamespace(const TClass*cl);
00348    void                SetDeclFileName(TClass* cl, const char* filename);
00349    void                SetFoundDot(Bool_t found = kTRUE);
00350    void                SetImplFileName(TClass* cl, const char* filename);
00351    void                SetBatch(Bool_t batch = kTRUE) { fBatch = batch; }
00352    Bool_t              IsBatch() const { return fBatch; }
00353    // unused
00354    void                ReplaceSpecialChars(std::ostream&, const char*) {
00355       Error("ReplaceSpecialChars",
00356             "Removed, call TDocOutput::ReplaceSpecialChars() instead!"); }
00357    void                SetEscape(char /*esc*/ ='\\') {} // for backward comp
00358 
00359 protected:
00360    struct DocSyntax_t {
00361       TString        fClassDocTag;     // tag for class documentation
00362       TString        fAuthorTag;       // tag for author
00363       TString        fLastUpdateTag;   // tag for last update
00364       TString        fCopyrightTag;    // tag for copyright
00365       TString        fDocStyle;        // doc style (only "Doc++" has special treatment)
00366    };
00367 
00368    struct LinkInfo_t {
00369       TString        fXwho;            // URL for name lookup
00370       TString        fROOTURL;         // Root URL for ROOT's reference guide for libs that are not in fLibURLs
00371       std::map<std::string, TString> fLibURLs; // URL for documentation of external libraries
00372       TString        fHomepage;        // URL of homepage
00373       TString        fSearchStemURL;   // URL stem used to build search URL
00374       TString        fSearchEngine;    // link to search engine
00375       TString        fViewCVS;         // link to ViewCVS; %f is replaced by the filename (no %f: it's appended)
00376       TString        fWikiURL;         // URL stem of class's wiki page, %c replaced by mangled class name (no %c: appended)
00377    };
00378 
00379    struct OutputStyle_t {
00380       TString        fHeader;          // header file name
00381       TString        fFooter;          // footerer file name
00382       TString        fCharset;         // Charset for doc pages
00383    };
00384 
00385    struct DocEntityInfo_t {
00386       DocEntityInfo_t(): fClasses(503, 3) {}
00387       TString        fClassFilter;     // filter used for buidling known classes
00388       THashList      fClasses;         // known classes
00389       mutable THashList fShortClassNames; // class names with default template args replaced
00390       THashList      fModules;         // known modules
00391       THashList      fLibDeps;         // Library dependencies
00392    };
00393 
00394 protected:
00395    virtual void    CreateJavascript() const;
00396    virtual void    CreateStyleSheet() const;
00397    void            CreateListOfTypes();
00398    void            CreateListOfClasses(const char* filter);
00399    virtual bool    GetDeclImplFileName(TClass* cl, bool filesys, bool decl, TString& out_name) const;
00400    void            MakeClass(void* cdi, Bool_t force=kFALSE);
00401    TClassDocInfo  *GetNextClass();
00402    void            SetLocalFiles() const;
00403 
00404    static void    *MakeClassThreaded(void* info);
00405 
00406 protected:   
00407    TString        fCounter;         // counter string
00408    TString        fCounterFormat;   // counter printf-like format
00409    TString        fProductName;     // name of the product to document
00410    TIter         *fThreadedClassIter; // fClasses iterator for MakeClassThreaded
00411    Int_t          fThreadedClassCount; // counter of processed classes for MakeClassThreaded
00412    TVirtualMutex *fMakeClassMutex; // Mutex for MakeClassThreaded
00413    TGClient      *fGClient; // gClient, cached and queried through CINT
00414    DocSyntax_t     fDocSyntax;      // doc syntax configuration
00415    LinkInfo_t      fLinkInfo;       // link (URL) configuration
00416    OutputStyle_t   fOutputStyle;    // output style configuration
00417    mutable PathInfo_t fPathInfo;       // path configuration
00418    DocEntityInfo_t fDocEntityInfo;  // data for documented entities
00419    mutable TPathDefinition *fPathDef; // object translating classes to module names
00420    mutable TModuleDefinition *fModuleDef; // object translating classes to module names
00421    mutable TFileDefinition* fFileDef; // object translating classes to file names
00422    mutable TFileSysDB    *fLocalFiles; // files found locally for a given source path
00423    Bool_t               fBatch; // Whether to enable GUI output
00424 
00425    ClassDef(THtml,0)  //Convert class(es) into HTML file(s)
00426 };
00427 
00428 R__EXTERN THtml *gHtml;
00429 
00430 #endif

Generated on Tue Jul 5 14:24:42 2011 for ROOT_528-00b_version by  doxygen 1.5.1