9#include <nlohmann/json.hpp>
12#include "PvlKeyword.h"
13#include "IException.h"
15using json = nlohmann::json;
82 if (keyword.
size() == 1) {
83 jsonKeyword[
"Value"] = keyword[0].toStdString();
85 else if (keyword.
size() > 1) {
87 for (
int i = 0; i < keyword.
size(); i++) {
88 valueList.push_back(keyword[i].toStdString());
90 jsonKeyword[
"Value"] = valueList;
94 if (keyword.
size() == 1 && !keyword.
unit(0).isEmpty()) {
95 jsonKeyword[
"Units"] = keyword.
unit(0).toStdString();
97 else if (keyword.
size() > 1 && !keyword.
unit(0).isEmpty()) {
99 for (
int i = 0; i < keyword.
size(); i++) {
100 valueList.push_back(keyword.
unit(i).toStdString());
102 jsonKeyword[
"Units"] = valueList;
107 jsonKeyword[
"Comment"] = keyword.
comment(0).toStdString();
111 for (
int i = 0; i < keyword.
comments(); i++) {
112 commentList.push_back(keyword.
comment(i).toStdString());
114 jsonKeyword[
"Comment"] = commentList;
138 for (keywordIt = container.begin(); keywordIt != container.end(); keywordIt++) {
139 string keywordName = keywordIt->name().replace(
"^",
"ptr").replace(
":",
"_").toStdString();
141 if ( jsonContainer.contains(keywordName) ) {
142 if (!jsonContainer[keywordName].is_array()) {
144 repeatedArray.push_back(jsonContainer[keywordName]);
145 jsonContainer[keywordName] = repeatedArray;
155 if (container.comments() == 1) {
156 jsonContainer[
"Comment"] = container.comment(0).toStdString();
158 else if (container.comments() > 1) {
160 for (
int i = 0; i < container.comments(); i++) {
161 commentList.push_back(container.comment(i).toStdString());
163 jsonContainer[
"Comment"] = commentList;
165 return jsonContainer;
302 for (groupIt =
object.beginGroup(); groupIt !=
object.endGroup(); groupIt++) {
304 if ( jsonObject.contains(groupIt->name().toStdString()) ) {
305 if (!jsonObject[groupIt->name().toStdString()].is_array()) {
307 repeatedArray.push_back(jsonObject[groupIt->name().toStdString()]);
308 jsonObject[groupIt->name().toStdString()] = repeatedArray;
310 jsonObject[groupIt->name().toStdString()].push_back(
pvlGroupToJSON(*groupIt));
313 jsonObject[groupIt->name().toStdString()] =
pvlGroupToJSON(*groupIt);
319 for (objectIt =
object.beginObject(); objectIt !=
object.endObject(); objectIt++) {
321 if ( jsonObject.contains(objectIt->name().toStdString()) ) {
322 if (!jsonObject[objectIt->name().toStdString()].is_array()) {
324 repeatedArray.push_back(jsonObject[objectIt->name().toStdString()]);
325 jsonObject[objectIt->name().toStdString()] = repeatedArray;
327 jsonObject[objectIt->name().toStdString()].push_back(
pvlObjectToJSON(*objectIt));
330 jsonObject[objectIt->name().toStdString()] =
pvlObjectToJSON(*objectIt);
369 QString msg = QString(
"Failed to open file for PVL Input: [%1]").arg(pvlFile);
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Contains more than one keyword-value pair.
QList< PvlKeyword >::iterator PvlKeywordIterator
The keyword iterator.
Contains multiple PvlContainers.
Container for cube-like labels.
void read(const QString &file)
Loads PVL information from a stream.
A single keyword-value pair.
int size() const
Returns the number of values stored in this keyword.
QString unit(const int index=0) const
Returns the units of measurement of the element of the array of values for the object at the specifie...
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.
Contains Pvl Groups and Pvl Objects.
QList< Isis::PvlGroup >::iterator PvlGroupIterator
The counter for groups.
QList< PvlObject >::iterator PvlObjectIterator
The counter for objects.
This is free and unencumbered software released into the public domain.
json pvlKeywordToJSON(PvlKeyword &keyword)
Convert the contents of a PvlKeyword to a JSON object.
json pvlToJSON(Pvl &pvl)
Convert the contents of a Pvl to a JSON object.
json pvlGroupToJSON(PvlGroup &group)
Convert the contents of a PvlGroup to a JSON object.
json pvlContainerToJSON(PvlContainer &container)
Convert the contents of a PvlContainer to a JSON object.
json pvlObjectToJSON(PvlObject &object)
Convert the contents of a PvlObject to a JSON object.
Namespace for the standard library.