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 | Copyright (C) 2012-2016 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 "doxygenXmlParser.H"
27 #include "wordRe.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  const fileName& fName,
34  const string& startTag,
35  const string& searchStr,
36  const bool exactMatch
37 )
38 :
39  dictionary(dictionary::null)
40 {
41  // Pre-construct and compile regular expressions
42  const wordRe nameRe(".*.H", wordRe::DETECT);
43  const wordRe searchStrRe(searchStr, wordRe::DETECT);
44 
45  // Pre-construct constant strings and names to speed-up comparisons
46  const string slashStartTag('/' + startTag);
47  const string kindFileStr("kind=\"file\"");
48  const word compoundWord("compound");
49  const word nameWord("name");
50  const word pathWord("path");
51  const word filenameWord("filename");
52 
53  IFstream is(fName);
54 
55  // Skip forward to entry name
56  skipForward(is, startTag);
57 
58  char c;
59 
60  while (is.get(c))
61  {
62  if (c == '<')
63  {
64  // If in block, read block name
65  string blockName;
66  string params;
67  bool readingParam = false;
68  while (is.get(c) && c != '>')
69  {
70  if (c == ' ')
71  {
72  readingParam = true;
73  }
74  else
75  {
76  if (readingParam)
77  {
78  params = params + c;
79  }
80  else
81  {
82  blockName = blockName + c;
83  }
84  }
85  }
86 
87  if (blockName == slashStartTag)
88  {
89  break;
90  }
91 
92  if ((blockName == compoundWord) && (params == kindFileStr))
93  {
94  // Keep entry
95  word name;
96  fileName path;
97  word fName;
98  bool foundName = false;
99  bool foundPath = false;
100  bool foundFName = false;
101  bool earlyExit = false;
102  while (!foundName || !foundPath || !foundFName)
103  {
104  word entryName;
105  getEntry<word>(is, entryName);
106  if (entryName == nameWord)
107  {
108  getValue<word>(is, name);
109  if (nameRe.match(name))
110  {
111  foundName = true;
112  }
113  else
114  {
115  // Not interested in this compound
116  break;
117  }
118  }
119  else if (entryName == pathWord)
120  {
121  getValue<fileName>(is, path);
122 
123  // Filter path on regExp
124  if (searchStrRe.match(path))
125  {
126  foundPath = true;
127  }
128  else
129  {
130  // Not interested in this compound
131  break;
132  }
133  }
134  else if (entryName == filenameWord)
135  {
136  getValue<word>(is, fName);
137  foundFName = true;
138  }
139  else
140  {
141  skipBlock(is, entryName);
142  }
143  }
144 
145  if (foundPath && !earlyExit)
146  {
147  word tName(path.components().last());
148 
149  // Only insert if type is not already known
150  // NOTE: not ideal for cases where there are multiple types
151  // but contained within different namespaces
152  // preferentially take exact match if it exists
153  if (exactMatch && (tName + ".H") == name)
154  {
155  dictionary dict(dictionary::null);
156  dict.add("name", name);
157  dict.add("filename", fName + ".html");
158  dict.add("path", path);
159  this->add(tName, dict);
160  }
161  else if
162  (
163  !exactMatch
164  && !found(tName)
165  && wordRe(".*" + tName + ".*", wordRe::DETECT).match(name)
166  )
167  {
168  dictionary dict(dictionary::null);
169  dict.add("name", name);
170  dict.add("filename", fName + ".html");
171  dict.add("path", path);
172  this->add(tName, dict);
173  }
174  }
175 
176  // Skip remanining entries
177  skipBlock(is, blockName);
178  }
179  else
180  {
181  skipBlock(is, blockName);
182  }
183  }
184  }
185 }
186 
187 
188 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
189 
191 (
192  IFstream& is,
193  const word& blockName
194 ) const
195 {
196  // Recurse to move forward in 'is' until come across </blockName>
197  string closeName;
198 
199  char c;
200  while (is.good() && (closeName != blockName))
201  {
202  // Fast-forward until we reach a '<'
203  while (is.get(c) && c != '<')
204  {}
205 
206  // Check to see if this is a closing block
207  if (is.get(c) && c == '/')
208  {
209  closeName = "";
210 
211  while (is.get(c) && c != '>')
212  {
213  closeName += c;
214  }
215  }
216  }
217 }
218 
219 
221 (
222  IFstream& is,
223  const word& blockName
224 ) const
225 {
226  // Recurse to move forward in 'is' until come across <blockName>
227  string entryName = "";
228  char c;
229 
230  while (is.good() && (entryName != blockName))
231  {
232  entryName = "";
233 
234  // Fast-forward until we reach a '<'
235  while (is.get(c) && c != '<')
236  {}
237 
238  while (is.get(c) && c != '>')
239  {
240  entryName = entryName + c;
241  }
242  }
243 }
244 
245 
246 // ************************************************************************* //
dictionary dict
doxygenXmlParser(const fileName &fName, const string &startTag, const string &searchStr, const bool exactMatch)
Construct from components.
static const dictionary null
Null dictionary.
Definition: dictionary.H:193
void skipForward(IFstream &is, const word &blockName) const
Skip forward to block.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:737
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())
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
const dimensionedScalar c
Speed of light in a vacuum.
void skipBlock(IFstream &is, const word &blockName) const
Skip past a block.
bool found
treat as regular expression
Definition: wordRe.H:98