11#include "IException.h"
22using json = nlohmann::json;
63 for(
auto it = jsonobj.begin(); it != jsonobj.end(); it++) {
65 keyword.setName(QString::fromStdString(it.key()));
66 if (it.value().is_array()) {
67 for(auto ar = it.value().begin(); ar!=it.value().end(); ar++) {
69 keyword.addJsonValue(*ar);
71 catch (IException &e) {
72 QString msg =
"While attempting to parse " + name +
" the following occured";
73 throw IException(e, IException::Unknown, msg, _FILEINFO_);
78 keyword.setJsonValue(*it);
96 vector<PvlObject *> searchList;
97 searchList.push_back(
this);
99 while(searchList.size() > 0) {
101 searchList[0]->findGroup(
name,
104 if(it != searchList[0]->
endGroup())
return *it;
106 for(
int i = 0; i < searchList[0]->objects(); i++) {
107 searchList.push_back(&searchList[0]->
object(i));
110 searchList.erase(searchList.begin());
113 QString msg =
"Unable to find PVL group [" +
name +
"]";
131 vector<const PvlObject *> searchList;
132 searchList.push_back(
this);
134 while(searchList.size() > 0) {
135 ConstPvlGroupIterator it =
136 searchList[0]->findGroup(
name,
139 if(it != searchList[0]->
endGroup())
return *it;
141 for(
int i = 0; i < searchList[0]->objects(); i++) {
142 searchList.push_back(&searchList[0]->
object(i));
145 searchList.erase(searchList.begin());
148 QString msg =
"Unable to find PVL group [" +
name +
"]";
177 vector<PvlObject *> searchList;
178 searchList.push_back(
this);
180 while(searchList.size() > 0) {
182 searchList[0]->findKeyword(kname, searchList[0]->
begin(),
183 searchList[0]->
end());
184 if(it != searchList[0]->
end()) {
189 for(
int g = 0; g < searchList[0]->groups(); g++) {
191 searchList[0]->group(g).findKeyword(kname,
194 if(it != searchList[0]->
group(g).
end()) {
201 for(
int i = 0; i < searchList[0]->objects(); i++) {
202 searchList.push_back(&searchList[0]->
object(i));
206 searchList.erase(searchList.begin());
210 QString msg =
"Unable to find PVL keyword [" + kname +
"]";
236 vector<const PvlObject *> searchList;
237 searchList.push_back(
this);
239 while(searchList.size() > 0) {
241 searchList[0]->findKeyword(kname, searchList[0]->
begin(),
242 searchList[0]->
end());
243 if(it != searchList[0]->
end()) {
248 for(
int g = 0; g < searchList[0]->groups(); g++) {
250 searchList[0]->group(g).findKeyword(kname,
254 if(it != searchList[0]->
group(g).
end()) {
261 for(
int i = 0; i < searchList[0]->objects(); i++) {
262 searchList.push_back(&searchList[0]->
object(i));
266 searchList.erase(searchList.begin());
284 vector<PvlObject *> searchList;
285 searchList.push_back(
this);
287 while(searchList.size() > 0) {
289 searchList[0]->findObject(
name,
292 if(it != searchList[0]->
endObject())
return *it;
294 for(
int i = 0; i < searchList[0]->objects(); i++) {
295 searchList.push_back(&searchList[0]->
object(i));
298 searchList.erase(searchList.begin());
301 QString msg =
"Unable to find PVL object [" +
name +
"]";
319 vector<const PvlObject *> searchList;
320 searchList.push_back(
this);
322 while(searchList.size() > 0) {
323 ConstPvlObjectIterator it =
324 searchList[0]->findObject(
name,
333 for(
int i = 0; i < searchList[0]->objects(); i++) {
334 searchList.push_back(&searchList[0]->
object(i));
338 searchList.erase(searchList.begin());
341 QString msg =
"Unable to find PVL object [" +
name +
"]";
361 QString msg =
"Unable to find PVL object [" +
name +
"] in " +
type() +
362 " [" + this->name() +
"]";
379 if(index >= (
int)
m_objects.size() || index < 0) {
380 QString msg =
"The specified index is out of bounds in PVL " +
type() +
387 for(
int i = 0; i < index; i++) key++;
403 QString msg =
"Unable to find PVL group [" +
name +
"] in " +
type() +
404 " [" + this->name() +
"]";
421 if(index >= (
int)
m_groups.size() || index < 0) {
422 QString msg =
"The specified index is out of bounds in PVL " +
type() +
429 for(
int i = 0; i < index; i++) key++;
445 if(index < 0 || index >= (
int)
m_groups.size()) {
464 if(index < 0 || index >= (
int)
m_groups.size()) {
482 if(index < 0 || index >= (
int)
m_objects.size()) {
500 if(index < 0 || index >= (
int)
m_objects.size()) {
518 bool removeFormatter =
false;
519 if(
object.format() == NULL) {
521 removeFormatter =
true;
525 if(
object.hasFormatTemplate())
532 for(
int i = 0; i < outTemplate.comments(); i++) {
533 newTemp.addComment(outTemplate.comment(i));
537 for(
int i = 0; i < outTemplate.
keywords(); i++) {
538 if(outTemplate[i].
isNamed(
"Isis:PvlTemplate:File")) {
539 QString filename = outTemplate[i];
542 QString message =
"Could not open the following PVL template file: ";
549 for(
int j = 0; j < include.
keywords(); j++) {
554 for(
int j = 0; j < include.
objects(); j++) {
559 for(
int j = 0; j < include.
groups(); j++) {
570 for(
int i = 0; i < outTemplate.
objects(); i++) {
576 for(
int i = 0; i < outTemplate.
groups(); i++) {
581 outTemplate = newTemp;
584 if(outTemplate.comments() > 0) {
585 for(
int k = 0; k < outTemplate.comments(); k++) {
586 for(
int l = 0; l <
object.indent(); l++) os <<
" ";
587 os << outTemplate.comment(k) <<
object.format()->formatEOL();
593 os <<
object.nameKeyword() <<
object.
format()->formatEOL();
594 object.setIndent(
object.indent() + 2);
605 for(
int i = 0; i < outTemplate.
objects(); i++) {
606 for(
int j = 0; j <
object.objects(); j++) {
607 if(outTemplate.
object(i).
name() !=
object.object(j).name())
continue;
609 os <<
object.format()->formatEOL();
611 object.object(j).setIndent(
object.indent());
612 object.object(j).setFormatTemplate(outTemplate.
object(i));
613 object.object(j).setFormat(
object.format());
614 os <<
object.object(j) <<
object.format()->formatEOL();
615 object.object(j).setFormat(NULL);
616 object.object(j).setIndent(0);
618 if(++numObjects <
object.
objects())
619 os <<
object.format()->formatEOL();
625 for(
int i = 0; i <
object.objects(); i++) {
626 if(outTemplate.
hasObject(
object.object(i).name()))
continue;
628 os <<
object.format()->formatEOL();
630 object.object(i).setIndent(
object.indent());
631 object.object(i).setFormat(
object.format());
632 os <<
object.object(i) <<
object.format()->formatEOL();
633 object.object(i).setFormat(NULL);
634 object.object(i).setIndent(0);
636 if(++numObjects <
object.
objects())
637 os <<
object.format()->formatEOL();
645 for(
int i = 0; i < outTemplate.
groups(); i++) {
646 for(
int j = 0; j <
object.groups(); j++) {
647 if(outTemplate.
group(i).
name() !=
object.group(j).name())
continue;
648 if((numgroups == 0) &&
650 os <<
object.format()->formatEOL();
652 object.group(j).setIndent(
object.indent());
653 object.group(j).setFormatTemplate(outTemplate.
group(i));
654 object.group(j).setFormat(
object.format());
655 os <<
object.group(j) <<
object.format()->formatEOL();
656 object.group(j).setFormat(NULL);
657 object.group(j).setIndent(0);
658 if(++numgroups <
object.
groups()) os <<
object.format()->formatEOL();
663 for(
int i = 0; i <
object.groups(); i++) {
664 if(outTemplate.
hasGroup(
object.group(i).name()))
continue;
665 if((numgroups == 0) &&
667 os <<
object.format()->formatEOL();
669 object.group(i).setIndent(
object.indent());
670 object.group(i).setFormat(
object.format());
671 os <<
object.group(i) <<
object.format()->formatEOL();
672 object.group(i).setFormat(NULL);
673 object.group(i).setIndent(0);
675 if(++numgroups <
object.
groups())
676 os <<
object.format()->formatEOL();
680 object.setIndent(
object.indent() - 2);
681 for(
int i = 0; i <
object.indent(); i++) os <<
" ";
682 os <<
object.format()->formatEnd(
"End_Object",
object.nameKeyword());
684 if(removeFormatter) {
685 delete object.format();
686 object.setFormat(NULL);
706 istream::pos_type beforeKeywordPos = is.tellg();
710 if(is.eof() && !is.bad()) {
714 is.seekg(beforeKeywordPos, ios::beg);
716 QString msg =
"Expected PVL keyword named [Object], found keyword named [";
717 msg += readKeyword.
name();
722 if(readKeyword.
size() == 1) {
723 result.
setName(readKeyword[0]);
726 is.seekg(beforeKeywordPos, ios::beg);
728 QString msg =
"Expected a single value for PVL object name, found [(";
730 for(
int i = 0; i < readKeyword.
size(); i++) {
731 if(i != 0) msg +=
", ";
733 msg += readKeyword[i];
740 for(
int comment = 0; comment < readKeyword.
comments(); comment++) {
741 result.addComment(readKeyword.
comment(comment));
745 beforeKeywordPos = is.tellg();
748 while(readKeyword != termination) {
749 for(
unsigned int errorKey = 0;
750 errorKey <
sizeof(errorKeywords) /
sizeof(
PvlKeyword);
752 if(readKeyword == errorKeywords[errorKey]) {
753 if(is.eof() && !is.bad()) {
757 is.seekg(beforeKeywordPos, ios::beg);
759 QString msg =
"Unexpected [";
760 msg += readKeyword.
name();
761 msg +=
"] in PVL Object [";
762 msg += result.
name();
769 is.seekg(beforeKeywordPos);
774 else if(readKeyword ==
PvlKeyword(
"Object")) {
775 is.seekg(beforeKeywordPos);
785 beforeKeywordPos = is.tellg();
796 if(readKeyword != termination) {
797 if(is.eof() && !is.bad()) {
801 is.seekg(beforeKeywordPos, ios::beg);
803 QString msg =
"PVL Object [" + result.
name();
804 msg +=
"] EndObject not found before end of file";
838 for(
int i=0; i<iObjSize; i++) {
841 QString sObjName = pvlTmplObj.
name();
842 bool bObjFound =
false;
854 QString sOption = sObjName +
"__Required";
858 if(pvlKeyOption[0] ==
"true") {
863 if (bObjFound ==
false) {
864 QString sErrMsg =
"Object \"" + sObjName +
"\" Not Found in the Template File\n";
870 int iTmplGrpSize =
groups();
871 for(
int i=0; i<iTmplGrpSize; i++) {
873 bool bGrpFound =
false;
874 QString sGrpName = pvlTmplGrp.
name();
887 QString sOption = sGrpName +
"__Required";
890 if(pvlKeyOption[0] ==
"true") {
895 if (bGrpFound ==
false) {
896 QString sErrMsg =
"Group \"" + sGrpName +
"\" Not Found in the Template File\n";
File name manipulation and expansion.
bool fileExists() const
Returns true if the file exists; false otherwise.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Programmer
This error is for when a programmer made an API call that was illegal.
@ Io
A type of error that occurred when performing an actual I/O operation.
Contains more than one keyword-value pair.
PvlContainer(const QString &type)
Constructs a PvlContainer object with a type.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
const PvlContainer & operator=(const PvlContainer &other)
This is an assignment operator.
QList< PvlKeyword >::iterator PvlKeywordIterator
The keyword iterator.
QString m_filename
This contains the filename used to initialize the pvl object.
PvlKeywordIterator begin()
Return the beginning iterator.
QList< PvlKeyword >::const_iterator ConstPvlKeywordIterator
The const keyword iterator.
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
PvlKeywordIterator end()
Return the ending iterator.
void setName(const QString &name)
Set the name of the container.
QString name() const
Returns the container name.
QString type() const
Returns the container type.
void validateAllKeywords(PvlContainer &pPvlCont)
Validate All the Keywords in a Container comparing with the Template.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
Contains multiple PvlContainers.
void validateGroup(PvlGroup &pPvlGrp)
Validate a Group comparing with the Template Group.
Container for cube-like labels.
A single keyword-value pair.
QString name() const
Returns the keyword name.
int size() const
Returns the number of values stored in this keyword.
int comments() const
Returns the number of lines of comments associated with this keyword.
QString comment(const int index) const
Return a comment at the specified index.
PvlFormat * format()
Get the current PvlFormat or create one.
Contains Pvl Groups and Pvl Objects.
PvlObjectIterator beginObject()
Returns the index of the beginning object.
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
PvlGroupIterator beginGroup()
Returns the beginning group index.
const PvlObject & operator=(const PvlObject &other)
This is an assignment operator.
friend std::istream & operator>>(std::istream &is, PvlObject &result)
This method reads a PvlObject from the input stream.
friend std::ostream & operator<<(std::ostream &os, Isis::PvlObject &object)
Outputs the PvlObject data to a specified output stream.
QList< Isis::PvlGroup >::iterator PvlGroupIterator
The counter for groups.
PvlGroup & group(const int index)
Return the group at the specified index.
PvlObject()
Creates a blank PvlObject.
QList< PvlGroup > m_groups
A vector of PvlGroups contained in the current PvlObject.
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not.
int groups() const
Returns the number of groups contained.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
void deleteObject(const QString &name)
Remove an object from the current PvlObject.
int objects() const
Returns the number of objects.
QList< PvlObject >::iterator PvlObjectIterator
The counter for objects.
PvlObject & object(const int index)
Return the object at the specified index.
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
FindOptions
A collection of options to use when finding.
@ Traverse
Search child objects.
@ None
Search only the current level.
QList< PvlObject > m_objects
A vector of PvlObjects contained in the current PvlObject.
void addObject(const PvlObject &object)
Add a PvlObject.
PvlObjectIterator endObject()
Returns the index of the ending object.
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
void validateObject(PvlObject &pPvlObj)
Validate Object.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
void deleteGroup(const QString &name)
Remove a group from the current PvlObject.
PvlGroupIterator endGroup()
Returns the ending group index.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
QString ArraySubscriptNotInRange(int index)
This error should be used when an Isis object or application is checking array bounds and the legal r...
This is free and unencumbered software released into the public domain.
Namespace for the standard library.