74 vector<PvlObject *> searchList;
75 searchList.push_back(
this);
77 while(searchList.size() > 0) {
79 searchList[0]->findGroup(name,
82 if(it != searchList[0]->
endGroup())
return *it;
84 for(
int i = 0; i < searchList[0]->objects(); i++) {
85 searchList.push_back(&searchList[0]->
object(i));
88 searchList.erase(searchList.begin());
91 QString msg =
"Unable to find PVL group [" + name +
"]";
109 vector<const PvlObject *> searchList;
110 searchList.push_back(
this);
112 while(searchList.size() > 0) {
113 ConstPvlGroupIterator it =
114 searchList[0]->findGroup(name,
117 if(it != searchList[0]->
endGroup())
return *it;
119 for(
int i = 0; i < searchList[0]->objects(); i++) {
120 searchList.push_back(&searchList[0]->
object(i));
123 searchList.erase(searchList.begin());
126 QString msg =
"Unable to find PVL group [" + name +
"]";
156 vector<PvlObject *> searchList;
157 searchList.push_back(
this);
159 while(searchList.size() > 0) {
161 searchList[0]->findKeyword(kname, searchList[0]->
begin(),
162 searchList[0]->
end());
163 if(it != searchList[0]->
end()) {
168 for(
int g = 0; g < searchList[0]->groups(); g++) {
170 searchList[0]->group(g).findKeyword(kname,
173 if(it != searchList[0]->
group(g).
end()) {
180 for(
int i = 0; i < searchList[0]->objects(); i++) {
181 searchList.push_back(&searchList[0]->
object(i));
185 searchList.erase(searchList.begin());
189 QString msg =
"Unable to find PVL keyword [" + kname +
"]";
215 vector<const PvlObject *> searchList;
216 searchList.push_back(
this);
218 while(searchList.size() > 0) {
220 searchList[0]->findKeyword(kname, searchList[0]->
begin(),
221 searchList[0]->
end());
222 if(it != searchList[0]->
end()) {
227 for(
int g = 0; g < searchList[0]->groups(); g++) {
229 searchList[0]->group(g).findKeyword(kname,
233 if(it != searchList[0]->
group(g).
end()) {
240 for(
int i = 0; i < searchList[0]->objects(); i++) {
241 searchList.push_back(&searchList[0]->
object(i));
245 searchList.erase(searchList.begin());
263 vector<PvlObject *> searchList;
264 searchList.push_back(
this);
266 while(searchList.size() > 0) {
268 searchList[0]->findObject(name,
271 if(it != searchList[0]->
endObject())
return *it;
273 for(
int i = 0; i < searchList[0]->objects(); i++) {
274 searchList.push_back(&searchList[0]->
object(i));
277 searchList.erase(searchList.begin());
280 QString msg =
"Unable to find PVL object [" + name +
"]";
298 vector<const PvlObject *> searchList;
299 searchList.push_back(
this);
301 while(searchList.size() > 0) {
302 ConstPvlObjectIterator it =
303 searchList[0]->findObject(name,
312 for(
int i = 0; i < searchList[0]->objects(); i++) {
313 searchList.push_back(&searchList[0]->
object(i));
317 searchList.erase(searchList.begin());
320 QString msg =
"Unable to find PVL object [" + name +
"]";
340 QString msg =
"Unable to find PVL object [" + name +
"] in " +
type() +
341 " [" + this->
name() +
"]";
358 if(index >= (
int)
m_objects.size() || index < 0) {
359 QString msg =
"The specified index is out of bounds in PVL " +
type() +
366 for(
int i = 0; i < index; i++) key++;
382 QString msg =
"Unable to find PVL group [" + name +
"] in " +
type() +
383 " [" + this->
name() +
"]";
400 if(index >= (
int)
m_groups.size() || index < 0) {
401 QString msg =
"The specified index is out of bounds in PVL " +
type() +
408 for(
int i = 0; i < index; i++) key++;
424 if(index < 0 || index >= (
int)
m_groups.size()) {
443 if(index < 0 || index >= (
int)
m_groups.size()) {
461 if(index < 0 || index >= (
int)
m_objects.size()) {
479 if(index < 0 || index >= (
int)
m_objects.size()) {
497 bool removeFormatter =
false;
498 if(
object.format() == NULL) {
500 removeFormatter =
true;
504 if(
object.hasFormatTemplate())
511 for(
int i = 0; i < outTemplate.comments(); i++) {
512 newTemp.addComment(outTemplate.comment(i));
516 for(
int i = 0; i < outTemplate.
keywords(); i++) {
517 if(outTemplate[i].isNamed(
"Isis:PvlTemplate:File")) {
518 QString filename = outTemplate[i];
520 if(!file.fileExists()) {
521 QString message =
"Could not open the following PVL template file: ";
528 for(
int j = 0; j < include.keywords(); j++) {
529 if(!newTemp.hasKeyword(include[j].name()))
533 for(
int j = 0; j < include.objects(); j++) {
534 if(!newTemp.hasObject(include.object(j).name()))
535 newTemp.addObject(include.object(j));
538 for(
int j = 0; j < include.groups(); j++) {
539 if(!newTemp.hasGroup(include.group(j).name()))
540 newTemp.addGroup(include.group(j));
544 else if(!newTemp.hasKeyword(outTemplate[i].
name()))
545 newTemp.addKeyword(outTemplate[i]);
549 for(
int i = 0; i < outTemplate.
objects(); i++) {
550 if(!newTemp.hasObject(outTemplate.
object(i).
name()))
551 newTemp.addObject(outTemplate.
object(i));
555 for(
int i = 0; i < outTemplate.
groups(); i++) {
556 if(!newTemp.hasGroup(outTemplate.
group(i).
name()))
557 newTemp.addGroup(outTemplate.
group(i));
560 outTemplate = newTemp;
563 if(outTemplate.comments() > 0) {
564 for(
int k = 0; k < outTemplate.comments(); k++) {
565 for(
int l = 0; l <
object.indent(); l++) os <<
" ";
566 os << outTemplate.comment(k) <<
object.format()->formatEOL();
572 os <<
object.nameKeyword() <<
object.format()->formatEOL();
573 object.setIndent(
object.indent() + 2);
576 if(
object.keywords() > 0) {
584 for(
int i = 0; i < outTemplate.
objects(); i++) {
585 for(
int j = 0; j <
object.objects(); j++) {
586 if(outTemplate.
object(i).
name() !=
object.object(j).name())
continue;
587 if(j == 0 &&
object.keywords() > 0)
588 os <<
object.format()->formatEOL();
590 object.object(j).setIndent(
object.indent());
591 object.object(j).setFormatTemplate(outTemplate.
object(i));
592 object.object(j).setFormat(
object.format());
593 os <<
object.object(j) <<
object.format()->formatEOL();
594 object.object(j).setFormat(NULL);
595 object.object(j).setIndent(0);
597 if(++numObjects <
object.objects())
598 os <<
object.format()->formatEOL();
604 for(
int i = 0; i <
object.objects(); i++) {
605 if(outTemplate.
hasObject(
object.object(i).name()))
continue;
606 if(i == 0 &&
object.keywords() > 0)
607 os <<
object.format()->formatEOL();
609 object.object(i).setIndent(
object.indent());
610 object.object(i).setFormat(
object.format());
611 os <<
object.object(i) <<
object.format()->formatEOL();
612 object.object(i).setFormat(NULL);
613 object.object(i).setIndent(0);
615 if(++numObjects <
object.objects())
616 os <<
object.format()->formatEOL();
624 for(
int i = 0; i < outTemplate.
groups(); i++) {
625 for(
int j = 0; j <
object.groups(); j++) {
626 if(outTemplate.
group(i).
name() !=
object.group(j).name())
continue;
627 if((numgroups == 0) &&
628 (
object.objects() > 0 ||
object.keywords() > 0))
629 os <<
object.format()->formatEOL();
631 object.group(j).setIndent(
object.indent());
632 object.group(j).setFormatTemplate(outTemplate.
group(i));
633 object.group(j).setFormat(
object.format());
634 os <<
object.group(j) <<
object.format()->formatEOL();
635 object.group(j).setFormat(NULL);
636 object.group(j).setIndent(0);
637 if(++numgroups <
object.groups()) os <<
object.format()->formatEOL();
642 for(
int i = 0; i <
object.groups(); i++) {
643 if(outTemplate.
hasGroup(
object.group(i).name()))
continue;
644 if((numgroups == 0) &&
645 (
object.objects() > 0 ||
object.keywords() > 0))
646 os <<
object.format()->formatEOL();
648 object.group(i).setIndent(
object.indent());
649 object.group(i).setFormat(
object.format());
650 os <<
object.group(i) <<
object.format()->formatEOL();
651 object.group(i).setFormat(NULL);
652 object.group(i).setIndent(0);
654 if(++numgroups <
object.groups())
655 os <<
object.format()->formatEOL();
659 object.setIndent(
object.indent() - 2);
660 for(
int i = 0; i <
object.indent(); i++) os <<
" ";
661 os <<
object.format()->formatEnd(
"End_Object",
object.nameKeyword());
663 if(removeFormatter) {
664 delete object.format();
665 object.setFormat(NULL);
685 istream::pos_type beforeKeywordPos = is.tellg();
689 if(is.eof() && !is.bad()) {
693 is.seekg(beforeKeywordPos, ios::beg);
695 QString msg =
"Expected PVL keyword named [Object], found keyword named [";
696 msg += readKeyword.name();
701 if(readKeyword.size() == 1) {
702 result.
setName(readKeyword[0]);
705 is.seekg(beforeKeywordPos, ios::beg);
707 QString msg =
"Expected a single value for PVL object name, found [(";
709 for(
int i = 0; i < readKeyword.size(); i++) {
710 if(i != 0) msg +=
", ";
712 msg += readKeyword[i];
719 for(
int comment = 0; comment < readKeyword.comments(); comment++) {
720 result.addComment(readKeyword.comment(comment));
724 beforeKeywordPos = is.tellg();
727 while(readKeyword != termination) {
728 for(
unsigned int errorKey = 0;
729 errorKey <
sizeof(errorKeywords) /
sizeof(
PvlKeyword);
731 if(readKeyword == errorKeywords[errorKey]) {
732 if(is.eof() && !is.bad()) {
736 is.seekg(beforeKeywordPos, ios::beg);
738 QString msg =
"Unexpected [";
739 msg += readKeyword.name();
740 msg +=
"] in PVL Object [";
741 msg += result.
name();
748 is.seekg(beforeKeywordPos);
753 else if(readKeyword ==
PvlKeyword(
"Object")) {
754 is.seekg(beforeKeywordPos);
764 beforeKeywordPos = is.tellg();
775 if(readKeyword != termination) {
776 if(is.eof() && !is.bad()) {
780 is.seekg(beforeKeywordPos, ios::beg);
782 QString msg =
"PVL Object [" + result.
name();
783 msg +=
"] EndObject not found before end of file";
817 for(
int i=0; i<iObjSize; i++) {
820 QString sObjName = pvlTmplObj.
name();
821 bool bObjFound =
false;
833 QString sOption = sObjName +
"__Required";
837 if(pvlKeyOption[0] ==
"true") {
842 if (bObjFound ==
false) {
843 QString sErrMsg =
"Object \"" + sObjName +
"\" Not Found in the Template File\n";
849 int iTmplGrpSize =
groups();
850 for(
int i=0; i<iTmplGrpSize; i++) {
852 bool bGrpFound =
false;
853 QString sGrpName = pvlTmplGrp.
name();
866 QString sOption = sGrpName +
"__Required";
869 if(pvlKeyOption[0] ==
"true") {
874 if (bGrpFound ==
false) {
875 QString sErrMsg =
"Group \"" + sGrpName +
"\" Not Found in the Template File\n";