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