doxygenXmlParser.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "doxygenXmlParser.H"
29 #include "regExp.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 (
35  const fileName& fName,
36  const string& startTag,
37  const string& searchStr,
38  const bool exactMatch,
39  const word& ext
40 )
41 :
42  dictionary(dictionary::null)
43 {
44  // Pre-construct and compile regular expressions
45  const regExp nameRe(".*.H");
46  const regExp searchStrRe(searchStr);
47 
48  // Pre-construct constant strings and names to speed-up comparisons
49  const string slashStartTag('/' + startTag);
50  const string kindFileStr("kind=\"file\"");
51  const word compoundWord("compound");
52  const word nameWord("name");
53  const word pathWord("path");
54  const word filenameWord("filename");
55 
56  IFstream is(fName);
57 
58  // Skip forward to entry name
59  skipForward(is, startTag);
60 
61  char c;
62 
63  while (is.get(c))
64  {
65  if (c == '<')
66  {
67  // If in block, read block name
68  string blockName;
69  string params;
70  bool readingParam = false;
71  while (is.get(c) && c != '>')
72  {
73  if (c == ' ')
74  {
75  readingParam = true;
76  }
77  else
78  {
79  if (readingParam)
80  {
81  params = params + c;
82  }
83  else
84  {
85  blockName = blockName + c;
86  }
87  }
88  }
89 
90  if (blockName == slashStartTag)
91  {
92  break;
93  }
94 
95  if ((blockName == compoundWord) && (params == kindFileStr))
96  {
97  // Keep entry
98  word name;
99  fileName path;
100  word fName;
101  bool foundName = false;
102  bool foundPath = false;
103  bool foundFName = false;
104  bool earlyExit = false;
105  while (!foundName || !foundPath || !foundFName)
106  {
107  word entryName;
108  getEntry<word>(is, entryName);
109  if (entryName == nameWord)
110  {
111  getValue<word>(is, name);
112  if (nameRe.match(name))
113  {
114  foundName = true;
115  }
116  else
117  {
118  // Not interested in this compound
119  break;
120  }
121  }
122  else if (entryName == pathWord)
123  {
124  getValue<fileName>(is, path);
125 
126  // Filter path on regExp
127  if (searchStrRe.match(path))
128  {
129  foundPath = true;
130  }
131  else
132  {
133  // Not interested in this compound
134  break;
135  }
136  }
137  else if (entryName == filenameWord)
138  {
139  getValue<word>(is, fName);
140  foundFName = true;
141  }
142  else
143  {
144  skipBlock(is, entryName);
145  }
146  }
147 
148  if (foundPath && !earlyExit)
149  {
150  word tName(path.components().last());
151 
152  // Only insert if type is not already known
153  // NOTE: not ideal for cases where there are multiple types
154  // but contained within different namespaces
155  // preferentially take exact match if it exists
156  if (exactMatch && (tName + "." + ext) == name)
157  {
158  dictionary dict(dictionary::null);
159  dict.add("name", name);
160  dict.add("filename", fName + ".html");
161  dict.add("path", path);
162  this->add(tName, dict);
163  }
164  else if
165  (
166  !exactMatch
167  && !found(tName) // not already added
168  && regExp(".*" + tName + ".*").match(name)
169  )
170  {
171  dictionary dict(dictionary::null);
172  dict.add("name", name);
173  dict.add("filename", fName + ".html");
174  dict.add("path", path);
175  this->add(tName, dict);
176  }
177  }
178 
179  // Skip remaining entries
180  skipBlock(is, blockName);
181  }
182  else
183  {
184  skipBlock(is, blockName);
185  }
186  }
187  }
188 }
189 
190 
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 
194 (
195  IFstream& is,
196  const word& blockName
197 ) const
198 {
199  // Recurse to move forward in 'is' until come across </blockName>
200  string closeName;
201 
202  char c;
203  while (is.good() && (closeName != blockName))
204  {
205  // Fast-forward until we reach a '<'
206  while (is.get(c) && c != '<')
207  {}
208 
209  // Check to see if this is a closing block
210  if (is.get(c) && c == '/')
211  {
212  closeName = "";
213 
214  while (is.get(c) && c != '>')
215  {
216  closeName += c;
217  }
218  }
219  }
220 }
221 
222 
224 (
225  IFstream& is,
226  const word& blockName
227 ) const
228 {
229  // Recurse to move forward in 'is' until come across <blockName>
230  string entryName = "";
231  char c;
232 
233  while (is.good() && (entryName != blockName))
234  {
235  entryName = "";
236 
237  // Fast-forward until we reach a '<'
238  while (is.get(c) && c != '<')
239  {}
240 
241  while (is.get(c) && c != '>')
242  {
243  entryName = entryName + c;
244  }
245  }
246 }
247 
248 
249 // ************************************************************************* //
Foam::doxygenXmlParser::skipForward
void skipForward(IFstream &is, const word &blockName) const
Skip forward to block.
Foam::doxygenXmlParser::skipBlock
void skipBlock(IFstream &is, const word &blockName) const
Skip past a block.
Foam::regExp
regExpCxx regExp
Selection of preferred regular expression implementation.
Definition: regExpFwd.H:41
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
doxygenXmlParser.H
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::stringOps::match
bool match(const UList< wordRe > &patterns, const std::string &text)
Return true if text matches one of the regular expressions.
Definition: stringOps.H:75
path
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::doxygenXmlParser::doxygenXmlParser
doxygenXmlParser(const fileName &fName, const string &startTag, const string &searchStr, const bool exactMatch, const word &ext)
Construct from components.