helpType.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "helpType.H"
27 #include "doxygenXmlParser.H"
28 #include "SortableList.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(helpType, 0);
35  defineRunTimeSelectionTable(helpType, dictionary);
36 }
37 
38 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
39 
41 {
42  const dictionary& docDict = debug::controlDict().subDict("Documentation");
43  List<fileName> docDirs(docDict.lookup("doxyDocDirs"));
44 
45  label dirI = -1;
46  forAll(docDirs, i)
47  {
48  if (isDir(docDirs[i].expand()))
49  {
50  dirI = i;
51  break;
52  }
53  }
54 
55  if (dirI == -1)
56  {
57  Info<< "No Doxygen sources found under search paths: "
58  << docDirs << endl;
59  return fileName();
60  }
61 
62  return docDirs[dirI];
63 }
64 
65 
67 (
68  const string& searchStr,
69  const bool exactMatch
70 ) const
71 {
72  fileName doxyPath(doxygenPath());
73 
74  if (doxyPath.empty())
75  {
76  return;
77  }
78 
79  Info<< "Found doxygen help in " << doxyPath.c_str() << nl << endl;
80 
81  doxygenXmlParser parser
82  (
83  doxyPath/"../DTAGS",
84  "tagfile",
85  searchStr,
86  exactMatch
87  );
88 
89  Info<< "Valid types include:" << nl << SortableList<word>(parser.toc());
90 }
91 
92 
94 (
95  const word& className,
96  const string& searchStr,
97  const bool exactMatch
98 ) const
99 {
100  fileName doxyPath(doxygenPath());
101 
102  if (doxyPath.empty())
103  {
104  return;
105  }
106 
107  Info<< "Found doxygen help in " << doxyPath.c_str() << nl << endl;
108 
109  string docBrowser = getEnv("FOAM_DOC_BROWSER");
110  if (docBrowser.empty())
111  {
112  const dictionary& docDict =
113  debug::controlDict().subDict("Documentation");
114  docDict.lookup("docBrowser") >> docBrowser;
115  }
116 
117  doxygenXmlParser parser
118  (
119  doxyPath/"../DTAGS",
120  "tagfile",
121  searchStr,
122  exactMatch
123  );
124 
125  if (debug)
126  {
127  Info<< parser;
128  }
129 
130  if (parser.found(className))
131  {
132  fileName docFile(doxyPath/parser.subDict(className).lookup("filename"));
133 
134  // can use FOAM_DOC_BROWSER='application file://%f' if required
135  docBrowser.replaceAll("%f", docFile);
136 
137  fileName classDirectory(parser.subDict(className).lookup("path"));
138  word classFile(parser.subDict(className).lookup("name"));
139 
140  Info<< "Showing documentation for type " << className << nl << endl;
141 
142  Info<< "Source file: " << classDirectory.c_str() << classFile << nl
143  << endl;
144 
145  system(docBrowser);
146  }
147  else
148  {
150  << "No help for type " << className << " found."
151  << " Valid options include:" << SortableList<word>(parser.toc())
152  << exit(FatalError);
153  }
154 }
155 
156 
157 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
158 
160 {}
161 
162 
163 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
164 
166 {}
167 
168 
169 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
170 
172 {
174  (
175  "browse",
176  "word",
177  "display documentation for boundary condition in browser"
178  );
179 }
180 
181 
182 // ************************************************************************* //
string getEnv(const word &)
Return environment variable of given name.
Definition: POSIX.C:102
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
fileName doxygenPath() const
Return file path to the Doxygen sources (if available)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void displayDocOptions(const string &searchStr, const bool exactMatch) const
Display the list of documentation options.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
helpType()
Constructor.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:633
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:486
virtual ~helpType()
Destructor.
string expand(const string &, const HashTable< string, word, string::hash > &mapping, const char sigil= '$')
Expand occurences of variables according to the mapping.
Definition: stringOps.C:75
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:93
static const char nl
Definition: Ostream.H:262
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
messageStream Info
void displayDoc(const word &className, const string &searchStr, const bool exactMatch) const
Display the help documentation in a browser.
dictionary & controlDict()
The central control dictionary.
Definition: debug.C:92
virtual void init()
Initialise - typically setting static variables,.
Namespace for OpenFOAM.
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1020
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451