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