6 |
|
* redistribute this software in source and binary code form, provided |
7 |
|
* that the following conditions are met: |
8 |
|
* |
9 |
< |
* 1. Acknowledgement of the program authors must be made in any |
10 |
< |
* publication of scientific results based in part on use of the |
11 |
< |
* program. An acceptable form of acknowledgement is citation of |
12 |
< |
* the article in which the program was described (Matthew |
13 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
< |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
< |
* |
18 |
< |
* 2. Redistributions of source code must retain the above copyright |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
* |
12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
* documentation and/or other materials provided with the |
15 |
|
* distribution. |
28 |
|
* arising out of the use of or inability to use software, even if the |
29 |
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
* such damages. |
31 |
+ |
* |
32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
+ |
* research, please cite the appropriate papers when you publish your |
34 |
+ |
* work. Good starting points are: |
35 |
+ |
* |
36 |
+ |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
+ |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
+ |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
#include <algorithm> |
43 |
|
#include <stack> |
44 |
+ |
#include <cstdio> |
45 |
|
#include "io/SectionParserManager.hpp" |
46 |
|
#include "utils/Trim.hpp" |
47 |
|
#include "utils/simError.h" |
48 |
|
|
49 |
< |
namespace oopse { |
49 |
> |
namespace OpenMD { |
50 |
|
|
51 |
|
SectionParserManager::~SectionParserManager() { |
52 |
|
SectionParserManager::iterator i; |
74 |
|
|
75 |
|
std::string line = trimLeftCopy(buffer); |
76 |
|
//a line begins with "//" is a comment line |
77 |
< |
if ( line.empty() || (line.size() >= 2 && line[0] == '/' && line[1] == '/')) { |
77 |
> |
if ( line.empty() || (line.size() >= 2 && line[0] == '/' |
78 |
> |
&& line[1] == '/') ) { |
79 |
|
continue; |
80 |
|
} else { |
81 |
|
StringTokenizer tokenizer(line); |
87 |
|
if (keyword == "begin") { |
88 |
|
std::string section = tokenizer.nextToken(); |
89 |
|
sectionNameStack.push(section); |
90 |
< |
|
91 |
< |
i = std::find_if(sectionParsers_.begin(), sectionParsers_.end(), SameSectionParserFunctor(section)); |
90 |
> |
|
91 |
> |
i = std::find_if(sectionParsers_.begin(), sectionParsers_.end(), |
92 |
> |
SameSectionParserFunctor(section)); |
93 |
|
if (i == sectionParsers_.end()){ |
94 |
< |
sprintf(painCave.errMsg, "SectionParserManager Error: Can not find corresponding section parser for %s\n", |
95 |
< |
section.c_str()); |
94 |
> |
sprintf(painCave.errMsg, |
95 |
> |
"SectionParserManager Error: Can not find corresponding " |
96 |
> |
"section parser for %s\n", |
97 |
> |
section.c_str()); |
98 |
|
painCave.isFatal = 1; |
99 |
|
simError(); |
100 |
|
} else { |
101 |
|
if (i->isActive) { |
102 |
< |
sprintf(painCave.errMsg, "SectionParserManager Error:find multiple %s section\n", |
103 |
< |
section.c_str()); |
104 |
< |
painCave.isFatal = 1; |
105 |
< |
simError(); |
102 |
> |
sprintf(painCave.errMsg, "SectionParserManager Error:find multiple %s " |
103 |
> |
"section\n", |
104 |
> |
section.c_str()); |
105 |
> |
painCave.isFatal = 1; |
106 |
> |
simError(); |
107 |
|
} else { |
108 |
< |
i->isActive = true; |
109 |
< |
i->lineNo = lineNo; |
110 |
< |
i->offset = input.tellg(); |
108 |
> |
i->isActive = true; |
109 |
> |
i->lineNo = lineNo; |
110 |
> |
i->offset = input.tellg(); |
111 |
|
} |
112 |
|
} |
113 |
|
} else if (keyword == "end") { |
116 |
|
sectionNameStack.pop(); |
117 |
|
} else { |
118 |
|
sprintf(painCave.errMsg, "SectionParserManager Error: begin %s and end %s does not match at line %d\n", |
119 |
< |
sectionNameStack.top().c_str(), section.c_str(), lineNo); |
119 |
> |
sectionNameStack.top().c_str(), section.c_str(), lineNo); |
120 |
|
painCave.isFatal = 1; |
121 |
|
simError(); |
122 |
|
} |
123 |
< |
|
123 |
> |
|
124 |
|
} else { |
125 |
|
continue; |
126 |
|
} |
127 |
|
} |
128 |
|
} |
129 |
< |
|
129 |
> |
|
130 |
|
} |
131 |
< |
|
131 |
> |
|
132 |
|
if (!sectionNameStack.empty()) { |
133 |
|
sprintf(painCave.errMsg, "SectionParserManager Error: stack is not empty\n"); |
134 |
|
painCave.isFatal = 1; |
135 |
|
simError(); |
136 |
|
} |
137 |
< |
|
137 |
> |
|
138 |
|
//invoke parser |
139 |
|
for (i = sectionParsers_.begin(); i != sectionParsers_.end(); ++i) { |
140 |
|
if (i->isActive) { |
141 |
< |
//C++ standard does not guarantee seekg reset EOF, in that case, seekg will fail |
142 |
< |
//It is always a good idea to call clear() before seek |
143 |
< |
input.clear(); |
144 |
< |
input.seekg(i->offset); |
145 |
< |
(i->sectionParser)->parse(input, ff, i->lineNo); |
141 |
> |
//C++ standard does not guarantee seekg reset EOF, in that case, seekg will fail |
142 |
> |
//It is always a good idea to call clear() before seek |
143 |
> |
input.clear(); |
144 |
> |
input.seekg(i->offset); |
145 |
> |
(i->sectionParser)->parse(input, ff, i->lineNo); |
146 |
> |
(i->sectionParser)->validateSection(); |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
|
} |
151 |
< |
|
151 |
> |
|
152 |
|
void SectionParserManager::push_front(SectionParser* sp) { |
153 |
|
SectionParserManager::iterator i; |
154 |
|
i = findSectionParser(sp->getSectionName()); |
155 |
|
if (i != sectionParsers_.end()) { |
156 |
< |
std::cerr << sp->getSectionName() << " section parser is alway existed" << std::endl; |
156 |
> |
std::cerr << sp->getSectionName() << " section parser already exists" |
157 |
> |
<< std::endl; |
158 |
|
return; |
159 |
|
} |
160 |
|
|
165 |
|
} else { |
166 |
|
context.priority = sectionParsers_.front().priority - priorityDifference_; |
167 |
|
} |
168 |
< |
|
168 |
> |
|
169 |
|
context.sectionParser = sp; |
170 |
|
context.lineNo = 0; |
171 |
|
context.offset = 0; |
178 |
|
SectionParserManager::iterator i; |
179 |
|
i = findSectionParser(sp->getSectionName()); |
180 |
|
if (i != sectionParsers_.end()) { |
181 |
< |
std::cerr << sp->getSectionName() << " section parser is alway existed" << std::endl; |
181 |
> |
std::cerr << sp->getSectionName() << " section parser already exists" |
182 |
> |
<< std::endl; |
183 |
|
return; |
184 |
|
} |
185 |
|
|
203 |
|
SectionParserManager::iterator i; |
204 |
|
i = findSectionParser(sp->getSectionName()); |
205 |
|
if (i != sectionParsers_.end()) { |
206 |
< |
std::cerr << sp->getSectionName() << " section parser is alway existed" << std::endl; |
206 |
> |
std::cerr << sp->getSectionName() << " section parser already exists" |
207 |
> |
<< std::endl; |
208 |
|
} |
209 |
|
|
210 |
|
SectionParserContext context; |
237 |
|
SectionParserManager::iterator i; |
238 |
|
for (i = sectionParsers_.begin(); i != sectionParsers_.end(); ++i) { |
239 |
|
if (i->sectionParser->getSectionName() == sectionName) { |
240 |
< |
break; |
240 |
> |
break; |
241 |
|
} |
242 |
|
} |
243 |
|
|