11#include "IException.h" 
   15#include "Application.h" 
   23using json = nlohmann::json;
 
   64    for(
auto it = jsonobj.begin(); it != jsonobj.end(); it++) {
 
   66        keyword.
setName(QString::fromStdString(it.key()));
 
   67        if (it.value().is_array()) {
 
   68          for(
auto ar = it.value().begin(); ar!=it.value().end(); ar++) {
 
   73              QString msg = 
"While attempting to parse " + 
name + 
" the following occured";
 
 
   97    vector<PvlObject *> searchList;
 
   98    searchList.push_back(
this);
 
  100    while(searchList.size() > 0) {
 
  102        searchList[0]->findGroup(
name,
 
  105      if(it != searchList[0]->
endGroup()) 
return *it;
 
  107        for(
int i = 0; i < searchList[0]->objects(); i++) {
 
  108          searchList.push_back(&searchList[0]->
object(i));
 
  111      searchList.erase(searchList.begin());
 
  114    QString msg = 
"Unable to find PVL group [" + 
name + 
"]";
 
 
  132    vector<const PvlObject *> searchList;
 
  133    searchList.push_back(
this);
 
  135    while(searchList.size() > 0) {
 
  136      ConstPvlGroupIterator it =
 
  137        searchList[0]->findGroup(
name,
 
  140      if(it != searchList[0]->
endGroup()) 
return *it;
 
  142        for(
int i = 0; i < searchList[0]->objects(); i++) {
 
  143          searchList.push_back(&searchList[0]->
object(i));
 
  146      searchList.erase(searchList.begin());
 
  149    QString msg = 
"Unable to find PVL group [" + 
name + 
"]";
 
 
  162    QString msg = 
"This function(PvlObject::addLogGroup) will be depreciated in ISIS3 v9.0 in " 
  163                  "favor of Application::appendLogGroup";
 
  164    std::cerr << msg << std::endl;
 
 
  191    vector<PvlObject *> searchList;
 
  192    searchList.push_back(
this);
 
  194    while(searchList.size() > 0) {
 
  196        searchList[0]->findKeyword(kname, searchList[0]->
begin(),
 
  197                                   searchList[0]->
end());
 
  198      if(it != searchList[0]->
end()) {
 
  203      for(
int g = 0; g < searchList[0]->groups(); g++) {
 
  205          searchList[0]->group(g).findKeyword(kname,
 
  208        if(it != searchList[0]->
group(g).
end()) {
 
  215      for(
int i = 0; i < searchList[0]->objects(); i++) {
 
  216        searchList.push_back(&searchList[0]->
object(i));
 
  220      searchList.erase(searchList.begin());
 
  224    QString msg = 
"Unable to find PVL keyword [" + kname + 
"]";
 
 
  250    vector<const PvlObject *> searchList;
 
  251    searchList.push_back(
this);
 
  253    while(searchList.size() > 0) {
 
  255        searchList[0]->findKeyword(kname, searchList[0]->
begin(),
 
  256                                   searchList[0]->
end());
 
  257      if(it != searchList[0]->
end()) {
 
  262      for(
int g = 0; g < searchList[0]->groups(); g++) {
 
  264          searchList[0]->group(g).findKeyword(kname,
 
  268        if(it != searchList[0]->
group(g).
end()) {
 
  275      for(
int i = 0; i < searchList[0]->objects(); i++) {
 
  276        searchList.push_back(&searchList[0]->
object(i));
 
  280      searchList.erase(searchList.begin());
 
 
  298    vector<PvlObject *> searchList;
 
  299    searchList.push_back(
this);
 
  301    while(searchList.size() > 0) {
 
  306      if(it != searchList[0]->
endObject()) 
return *it;
 
  308        for(
int i = 0; i < searchList[0]->objects(); i++) {
 
  309          searchList.push_back(&searchList[0]->
object(i));
 
  312      searchList.erase(searchList.begin());
 
  315    QString msg = 
"Unable to find PVL object [" + 
name + 
"]";
 
 
  333    vector<const PvlObject *> searchList;
 
  334    searchList.push_back(
this);
 
  336    while(searchList.size() > 0) {
 
  337      ConstPvlObjectIterator it =
 
  347        for(
int i = 0; i < searchList[0]->objects(); i++) {
 
  348          searchList.push_back(&searchList[0]->
object(i));
 
  352      searchList.erase(searchList.begin());
 
  355    QString msg = 
"Unable to find PVL object [" + 
name + 
"]";
 
 
  375      QString msg = 
"Unable to find PVL object [" + 
name + 
"] in " + 
type() +
 
  376                   " [" + this->
name() + 
"]";
 
 
  393    if(index >= (
int)
m_objects.size() || index < 0) {
 
  394      QString msg = 
"The specified index is out of bounds in PVL " + 
type() +
 
  401    for(
int i = 0; i < index; i++)  key++;
 
 
  417      QString msg = 
"Unable to find PVL group [" + 
name + 
"] in " + 
type() +
 
  418                   " [" + this->
name() + 
"]";
 
 
  435    if(index >= (
int)
m_groups.size() || index < 0) {
 
  436      QString msg = 
"The specified index is out of bounds in PVL " + 
type() +
 
  443    for(
int i = 0; i < index; i++)  key++;
 
 
  459    if(index < 0 || index >= (
int)
m_groups.size()) {
 
 
  478    if(index < 0 || index >= (
int)
m_groups.size()) {
 
 
  496    if(index < 0 || index >= (
int)
m_objects.size()) {
 
 
  514    if(index < 0 || index >= (
int)
m_objects.size()) {
 
 
  532    bool removeFormatter = 
false;
 
  533    if(
object.format() == NULL) {
 
  535      removeFormatter = 
true;
 
  539    if(
object.hasFormatTemplate())
 
  546    for(
int i = 0; i < outTemplate.comments(); i++) {
 
  547      newTemp.addComment(outTemplate.comment(i));
 
  551    for(
int i = 0; i < outTemplate.keywords(); i++) {
 
  552      if(outTemplate[i].isNamed(
"Isis:PvlTemplate:File")) {
 
  553        QString filename = outTemplate[i];
 
  555        if(!file.fileExists()) {
 
  556          QString message = 
"Could not open the following PVL template file: ";
 
  563        for(
int j = 0; j < include.
keywords(); j++) {
 
  564          if(!newTemp.hasKeyword(include[j].
name()))
 
  565            newTemp.addKeyword(include[j]);
 
  568        for(
int j = 0; j < include.
objects(); j++) {
 
  569          if(!newTemp.hasObject(include.
object(j).
name()))
 
  570            newTemp.addObject(include.
object(j));
 
  573        for(
int j = 0; j < include.
groups(); j++) {
 
  574          if(!newTemp.hasGroup(include.
group(j).
name()))
 
  575            newTemp.addGroup(include.
group(j));
 
  579      else if(!newTemp.hasKeyword(outTemplate[i].name()))
 
  580        newTemp.addKeyword(outTemplate[i]);
 
  584    for(
int i = 0; i < outTemplate.objects(); i++) {
 
  585      if(!newTemp.hasObject(outTemplate.object(i).name()))
 
  586        newTemp.addObject(outTemplate.object(i));
 
  590    for(
int i = 0; i < outTemplate.groups(); i++) {
 
  591      if(!newTemp.hasGroup(outTemplate.group(i).name()))
 
  592        newTemp.addGroup(outTemplate.group(i));
 
  595    outTemplate = newTemp;
 
  598    if(outTemplate.comments() > 0) {
 
  599      for(
int k = 0; k < outTemplate.comments(); k++) {
 
  600        for(
int l = 0; l < 
object.indent(); l++) os << 
" ";
 
  601        os << outTemplate.comment(k) << 
object.format()->formatEOL();
 
  607    os << 
object.nameKeyword() << 
object.format()->formatEOL();
 
  608    object.setIndent(
object.indent() + 2);
 
  611    if(
object.keywords() > 0) {
 
  619    for(
int i = 0; i < outTemplate.objects(); i++) {
 
  620      for(
int j = 0; j < 
object.objects(); j++) {
 
  621        if(outTemplate.object(i).name() != 
object.object(j).name()) 
continue;
 
  622        if(j == 0 && 
object.keywords() > 0)
 
  623          os << 
object.format()->formatEOL();
 
  625        object.object(j).setIndent(
object.indent());
 
  626        object.object(j).setFormatTemplate(outTemplate.object(i));
 
  627        object.object(j).setFormat(
object.format());
 
  628        os << 
object.object(j) << 
object.format()->formatEOL();
 
  629        object.object(j).setFormat(NULL);
 
  630        object.object(j).setIndent(0);
 
  632        if(++numObjects < 
object.objects())
 
  633          os << 
object.format()->formatEOL();
 
  639    for(
int i = 0; i < 
object.objects(); i++) {
 
  640      if(outTemplate.hasObject(
object.object(i).name())) 
continue;
 
  641      if(i == 0 && 
object.keywords() > 0)
 
  642        os << 
object.format()->formatEOL();
 
  644      object.object(i).setIndent(
object.indent());
 
  645      object.object(i).setFormat(
object.format());
 
  646      os << 
object.object(i) << 
object.format()->formatEOL();
 
  647      object.object(i).setFormat(NULL);
 
  648      object.object(i).setIndent(0);
 
  650      if(++numObjects < 
object.objects())
 
  651        os << 
object.format()->formatEOL();
 
  659    for(
int i = 0; i < outTemplate.groups(); i++) {
 
  660      for(
int j = 0; j < 
object.groups(); j++) {
 
  661        if(outTemplate.group(i).name() != 
object.group(j).name()) 
continue;
 
  662        if((numgroups == 0) &&
 
  663            (
object.objects() > 0 || 
object.keywords() > 0))
 
  664          os << 
object.format()->formatEOL();
 
  666        object.group(j).setIndent(
object.indent());
 
  667        object.group(j).setFormatTemplate(outTemplate.group(i));
 
  668        object.group(j).setFormat(
object.format());
 
  669        os << 
object.group(j) << 
object.format()->formatEOL();
 
  670        object.group(j).setFormat(NULL);
 
  671        object.group(j).setIndent(0);
 
  672        if(++numgroups < 
object.groups()) os << 
object.format()->formatEOL();
 
  677    for(
int i = 0; i < 
object.groups(); i++) {
 
  678      if(outTemplate.hasGroup(
object.group(i).name())) 
continue;
 
  679      if((numgroups == 0) &&
 
  680          (
object.objects() > 0 || 
object.keywords() > 0))
 
  681        os << 
object.format()->formatEOL();
 
  683      object.group(i).setIndent(
object.indent());
 
  684      object.group(i).setFormat(
object.format());
 
  685      os << 
object.group(i) << 
object.format()->formatEOL();
 
  686      object.group(i).setFormat(NULL);
 
  687      object.group(i).setIndent(0);
 
  689      if(++numgroups < 
object.groups())
 
  690        os << 
object.format()->formatEOL();
 
  694    object.setIndent(
object.indent() - 2);
 
  695    for(
int i = 0; i < 
object.indent(); i++) os << 
" ";
 
  696    os << 
object.format()->formatEnd(
"End_Object", 
object.nameKeyword());
 
  698    if(removeFormatter) {
 
  699      delete object.format();
 
  700      object.setFormat(NULL);
 
 
  720    istream::pos_type beforeKeywordPos = is.tellg();
 
  724      if(is.eof() && !is.bad()) {
 
  728      is.seekg(beforeKeywordPos, ios::beg);
 
  730      QString msg = 
"Expected PVL keyword named [Object], found keyword named [";
 
  731      msg += readKeyword.name();
 
  736    if(readKeyword.size() == 1) {
 
  737      result.
setName(readKeyword[0]);
 
  740      is.seekg(beforeKeywordPos, ios::beg);
 
  742      QString msg = 
"Expected a single value for PVL object name, found [(";
 
  744      for(
int i = 0; i < readKeyword.size(); i++) {
 
  745        if(i != 0) msg += 
", ";
 
  747        msg += readKeyword[i];
 
  754    for(
int comment = 0; comment < readKeyword.comments(); comment++) {
 
  755      result.addComment(readKeyword.comment(comment));
 
  759    beforeKeywordPos = is.tellg();
 
  762    while(readKeyword != termination) {
 
  763      for(
unsigned int errorKey = 0;
 
  764          errorKey < 
sizeof(errorKeywords) / 
sizeof(
PvlKeyword);
 
  766        if(readKeyword == errorKeywords[errorKey]) {
 
  767          if(is.eof() && !is.bad()) {
 
  771          is.seekg(beforeKeywordPos, ios::beg);
 
  773          QString msg = 
"Unexpected [";
 
  774          msg += readKeyword.name();
 
  775          msg += 
"] in PVL Object [";
 
  776          msg += result.
name();
 
  783        is.seekg(beforeKeywordPos);
 
  788      else if(readKeyword == 
PvlKeyword(
"Object")) {
 
  789        is.seekg(beforeKeywordPos);
 
  799      beforeKeywordPos = is.tellg();
 
  810    if(readKeyword != termination) {
 
  811      if(is.eof() && !is.bad()) {
 
  815      is.seekg(beforeKeywordPos, ios::beg);
 
  817      QString msg = 
"PVL Object [" + result.
name();
 
  818      msg += 
"] EndObject not found before end of file";
 
 
  852    for(
int i=0; i<iObjSize; i++) {
 
  855      QString sObjName = pvlTmplObj.name();
 
  856      bool bObjFound = 
false;
 
  859      if(pPvlObj.hasObject(sObjName)) {
 
  861        pvlTmplObj.validateObject(pvlObj);
 
  862        if(pvlObj.objects()==0 && pvlObj.groups()==0 && pvlObj.keywords()==0) {
 
  863          pPvlObj.deleteObject(pvlObj.name());
 
  868        QString sOption = sObjName + 
"__Required";
 
  870        if(pvlTmplObj.hasKeyword(sOption)) {
 
  871          PvlKeyword pvlKeyOption = pvlTmplObj.findKeyword(sOption);
 
  872          if(pvlKeyOption[0] == 
"true") { 
 
  877      if (bObjFound == 
false) {
 
  878        QString sErrMsg = 
"Object \"" + sObjName + 
"\" Not Found in the Template File\n";
 
  884    int iTmplGrpSize = 
groups();
 
  885    for(
int i=0; i<iTmplGrpSize; i++) {
 
  887      bool bGrpFound = 
false;
 
  888      QString sGrpName = pvlTmplGrp.name();
 
  891      if(pPvlObj.hasGroup(sGrpName)) {
 
  892        PvlGroup & pvlGrp = pPvlObj.findGroup(sGrpName);
 
  894        if(pvlGrp.keywords()==0) {
 
  895          pPvlObj.deleteGroup(pvlGrp.name());
 
  901        QString sOption = sGrpName + 
"__Required";
 
  902        if(pvlTmplGrp.hasKeyword(sOption)) {
 
  903          PvlKeyword pvlKeyOption = pvlTmplGrp.findKeyword(sOption);
 
  904          if(pvlKeyOption[0] == 
"true") { 
 
  909      if (bGrpFound == 
false) {
 
  910        QString sErrMsg = 
"Group \"" + sGrpName + 
"\" Not Found in the Template File\n";
 
 
static void Log(PvlGroup &results)
Writes Pvl results to sessionlog and printfile.
 
File name manipulation and expansion.
 
@ 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.
 
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.
 
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.
 
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.
 
void setName(QString name)
Sets the keyword name.
 
void setJsonValue(nlohmann::json jsonobj, QString unit="")
Sets new value from Json.
 
void addJsonValue(nlohmann::json jsonobj, QString unit="")
Adds a value with units.
 
void clear()
Clears all values and units for this PvlKeyword object.
 
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.
 
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.
 
int groups() const
Returns the number of groups contained.
 
void addLogGroup(Isis::PvlGroup &group)
Add a group to the object and report it to the log/terminal.
 
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.
 
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.
 
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
 
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
 
Namespace for the standard library.