30 |
|
SectionParserManager::~SectionParserManager() { |
31 |
|
SectionParserManager::iterator i; |
32 |
|
for (i = sectionParsers_.begin(); i != sectionParsers_.end(); ++i) { |
33 |
< |
delete (i->sp); |
33 |
> |
delete (i->sectionParser); |
34 |
|
} |
35 |
|
sectionParsers_.clear(); |
36 |
|
} |
37 |
|
|
38 |
< |
void SectionParserManager::parse(ifstrstream& input, ForceField& ff) { |
38 |
> |
void SectionParserManager::parse(std::istream& input, ForceField& ff) { |
39 |
|
|
40 |
|
//reset active flags |
41 |
|
SectionParserManager::iterator i; |
49 |
|
//scan through the input stream and find section names |
50 |
|
while(input.getline(buffer, bufferSize)) { |
51 |
|
++lineNo; |
52 |
< |
line = LeftTrim(buffer); |
53 |
< |
|
52 |
> |
/**@todo implement trimLeft() */ |
53 |
> |
//std::string line = LeftTrim(buffer); |
54 |
> |
std::string line= buffer; |
55 |
|
//a line begins with "//" is comment |
56 |
|
if ( line.empty() || (line.size() >= 2 && line[0] == '/' && line[1] == '/')) { |
57 |
|
continue; |
68 |
|
|
69 |
|
std::string section = tokenizer.nextToken(); |
70 |
|
|
71 |
< |
i = std::find_if(sectionParsers_.begin(), sectionParsers_.end(), predict); |
71 |
> |
i = std::find_if(sectionParsers_.begin(), sectionParsers_.end(), SameSectionParserFunctor(section)); |
72 |
|
if (i == sectionParsers_.end()){ |
73 |
|
//can not find corresponding section parser |
74 |
|
std::cerr << "Can not find corresponding section parser for section: " << section << std::endl; |
75 |
|
} else { |
76 |
|
i->isActive = true; |
77 |
|
i->lineNo = lineNo; |
78 |
< |
i->offset = input->tellg(); |
78 |
> |
i->offset = input.tellg(); |
79 |
|
} |
80 |
|
|
81 |
|
} |
87 |
|
//invoke parser |
88 |
|
for (i = sectionParsers_.begin(); i != sectionParsers_.end(); ++i) { |
89 |
|
if (i->isActive) { |
90 |
< |
input->seekg(i->offset); |
90 |
> |
input.seekg(i->offset); |
91 |
|
(i->sectionParser)->parse(input, ff, i->lineNo); |
92 |
|
} |
93 |
|
} |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
< |
iterator SectionParserManager::findSectionParser(const std::string& sectionName) { |
175 |
> |
SectionParserManager::iterator SectionParserManager::findSectionParser(const std::string& sectionName) { |
176 |
|
SectionParserManager::iterator i; |
177 |
|
for (i = sectionParsers_.begin(); i != sectionParsers_.end(); ++i) { |
178 |
|
if (i->sectionParser->getSectionName() == sectionName) { |