56 m_internalTemplate =
false;
65 m_internalTemplate =
false;
83 istm.open(
m_filename.toAscii().data(), std::ios::in);
95 QString message =
"Unable to read PVL file [" + temp.expanded() +
"]";
100 QString message =
"Unable to read PVL file [" + temp.expanded() +
"]";
121 bool removeFormatter =
false;
122 if(format() == NULL) {
124 removeFormatter =
true;
129 QString tempName(temp.expanded());
130 ostm.open(tempName.toAscii().data(), std::ios::out);
131 ostm.seekp(0, std::ios::beg);
140 if(
terminator() !=
"") ostm << format()->formatEOL();
144 QString message =
"Unable to write PVL to file [" + temp.expanded() +
"]";
149 QString message =
"Unable to write PVL to file [" + temp.expanded() +
"]";
153 if(removeFormatter) {
175 bool removeFormatter =
false;
176 if(format() == NULL) {
178 removeFormatter =
true;
183 QString tempName(temp.expanded());
184 ostm.open(tempName.toAscii().data(), std::ios::app);
185 ostm.seekp(0, std::ios::end);
194 if(
terminator() !=
"") ostm << format()->formatEOL();
198 QString message =
"Unable to append PVL infomation to file [" +
199 temp.expanded() +
"]";
203 if(removeFormatter) {
213 void Pvl::setFormatTemplate(
Isis::Pvl &temp) {
214 if(m_internalTemplate)
delete m_formatTemplate;
215 m_internalTemplate =
false;
216 Isis::PvlObject::setFormatTemplate(temp);
220 void Pvl::setFormatTemplate(
const QString &file) {
221 if(m_internalTemplate)
delete m_formatTemplate;
222 m_internalTemplate =
true;
237 bool removeFormatter =
false;
238 if(pvl.format() == NULL) {
240 removeFormatter =
true;
244 if(pvl.hasFormatTemplate()) outTemplate = *(
Isis::Pvl *)pvl.formatTemplate();
250 for(
int i = 0; i < outTemplate.
keywords(); i++) {
251 if(outTemplate[i].isNamed(
"Isis:PvlTemplate:File")) {
252 QString filename = outTemplate[i];
254 if(!file.fileExists()) {
255 QString message =
"Could not open the template file [" + filename +
"]";
260 for(
int j = 0; j < include.keywords(); j++) {
265 for(
int j = 0; j < include.objects(); j++) {
266 if(!newTemp.
hasObject(include.object(j).name()))
270 for(
int j = 0; j < include.groups(); j++) {
271 if(!newTemp.
hasGroup(include.group(j).name()))
281 for(
int i = 0; i < outTemplate.
objects(); i++) {
287 for(
int i = 0; i < outTemplate.
groups(); i++) {
292 outTemplate = newTemp;
295 for(
int i = 0; i < pvl.comments(); i++) {
296 os << pvl.comment(i) << pvl.format()->formatEOL();
297 if(i == (pvl.comments() - 1)) os << pvl.format()->formatEOL();
309 for(
int i = 0; i < outTemplate.
objects(); i++) {
310 for(
int j = 0; j < pvl.
objects(); j++) {
312 if(numObjects == 0 && pvl.
keywords() > 0) os << pvl.format()->formatEOL();
313 pvl.
object(j).setIndent(pvl.indent());
315 pvl.
object(j).setFormat(pvl.format());
316 os << pvl.
object(j) << pvl.format()->formatEOL();
317 pvl.
object(j).setFormat(NULL);
318 pvl.
object(j).setIndent(0);
319 if(++numObjects < pvl.
objects()) os << pvl.format()->formatEOL();
324 for(
int i = 0; i < pvl.
objects(); i++) {
326 if(numObjects == 0 && pvl.
keywords() > 0) os << pvl.format()->formatEOL();
327 pvl.
object(i).setIndent(pvl.indent());
328 pvl.
object(i).setFormat(pvl.format());
329 os << pvl.
object(i) << pvl.format()->formatEOL();
330 pvl.
object(i).setFormat(NULL);
331 pvl.
object(i).setIndent(0);
332 if(++numObjects < pvl.
objects()) os << pvl.format()->formatEOL();
339 for(
int i = 0; i < outTemplate.
groups(); i++) {
340 for(
int j = 0; j < pvl.
groups(); j++) {
342 if((numGroups == 0) &&
343 (pvl.
objects() > 0 || pvl.
keywords() > 0)) os << pvl.format()->formatEOL();
344 pvl.
group(j).setIndent(pvl.indent());
345 pvl.
group(j).setFormatTemplate(outTemplate.
group(i));
346 pvl.
group(j).setFormat(pvl.format());
347 os << pvl.
group(j) << pvl.format()->formatEOL();
348 pvl.
group(j).setFormat(NULL);
349 pvl.
group(j).setIndent(0);
350 if(++numGroups < pvl.
groups()) os << pvl.format()->formatEOL();
355 for(
int i = 0; i < pvl.
groups(); i++) {
357 if((numGroups == 0) &&
358 (pvl.
objects() > 0 || pvl.
keywords() > 0)) os << pvl.format()->formatEOL();
359 pvl.
group(i).setIndent(pvl.indent());
360 pvl.
group(i).setFormat(pvl.format());
361 os << pvl.
group(i) << pvl.format()->formatEOL();
362 pvl.
group(i).setFormat(NULL);
363 pvl.
group(i).setIndent(0);
364 if(++numGroups < pvl.
groups()) os << pvl.format()->formatEOL();
372 if(removeFormatter) {
391 string msg =
"Tried to read input stream with an error state into a Pvl";
404 istream::pos_type beforeKeywordPos = is.tellg();
408 while(readKeyword != termination) {
409 for(
unsigned int errorKey = 0;
410 errorKey <
sizeof(errorKeywords) /
sizeof(
PvlKeyword);
412 if(readKeyword == errorKeywords[errorKey]) {
413 is.seekg(beforeKeywordPos, ios::beg);
415 QString msg =
"Unexpected [";
416 msg += readKeyword.
name();
417 msg +=
"] in PVL Object [ROOT]";
423 is.seekg(beforeKeywordPos);
428 else if(readKeyword ==
PvlKeyword(
"Object")) {
429 is.seekg(beforeKeywordPos);
439 beforeKeywordPos = is.tellg();
442 if(is.good() && (is.peek() < 32 || is.peek() > 126)) {
459 if(is.eof() && !is.bad()) {
464 istream::pos_type errorPos = is.tellg();
465 if((
int)errorPos == -1)
throw;
467 is.seekg(0, ios::beg);
470 if((
int)is.tellg() == -1)
throw;
472 while(is.good() && is.tellg() < errorPos) {
473 char next = is.get();
475 if(!isprint(next) && !isspace(next)) {
476 is.seekg(errorPos, ios::beg);
478 else if(next ==
'\n') {
485 msg =
"Error in PVL file on line [";
486 msg +=
IString((Isis::BigInt)lineNumber);
499 m_internalTemplate = other.m_internalTemplate;
517 pPvlResults=
Pvl(pPvl);
522 for(
int i=0; i<iTmplObjSize; i++) {
525 QString sObjName = pvlTmplObj.
name();
526 bool bObjFound =
false;
538 QString sOption = sObjName +
"__Required";
542 if(pvlKeyOption[0] ==
"true") {
547 if (bObjFound ==
false) {
548 QString sErrMsg =
"Object \"" + sObjName +
"\" Not Found in the Template File\n";
554 int iTmplGrpSize =
groups();
555 for(
int i=0; i<iTmplGrpSize; i++) {
558 QString sGrpName = pvlTmplGrp.
name();
559 bool bGrpFound =
false;
572 QString sOption = sGrpName +
"__Required";
575 if(pvlKeyOption[0] ==
"true") {
580 if (bGrpFound ==
false) {
581 QString sErrMsg =
"Group \"" + sGrpName +
"\" Not Found in the Template File\n";