File failed to load: https://isis.astrogeology.usgs.gov/dev/Object/assets/jax/output/NativeMML/config.js
Isis Developer Reference
PvlKeyword.h
Go to the documentation of this file.
1#ifndef PvlKeyword_h
2#define PvlKeyword_h
7
8/* SPDX-License-Identifier: CC0-1.0 */
9#include <vector>
10#include <map>
11#include <iostream>
12
13#include <QString>
14#include <QVariant>
15#include <QVarLengthArray>
16
17#include "Constants.h"
18#include "IString.h"
19
20#include <nlohmann/json.hpp>
21
22namespace Isis {
23 class PvlSequence;
24 class PvlFormat;
25
87 class PvlKeyword {
88 public:
89 PvlKeyword();
90 PvlKeyword(QString name);
91 PvlKeyword(QString name, QString value,
92 QString unit = "");
93 PvlKeyword(QString name, std::vector<std::string> vecValue,
94 QString unit = "");
95 PvlKeyword(const PvlKeyword &other);
97
98 void setName(QString name);
99
105 QString name() const {
106 if(m_name)
107 return m_name;
108 else
109 return "";
110 };
111
117 bool isNamed(QString name) const {
118 return stringEqual(name, this->name());
119 };
120
121 void setValue(QString value, QString unit = "");
122 void setJsonValue(nlohmann::json jsonobj);
123 void setJsonArrayValue(nlohmann::json jsonobj);
124
125
126 void setUnits(QString units);
127 void setUnits(QString value, QString units);
128
129 PvlKeyword &operator=(QString value);
130
131 void addValue(QString value, QString unit = "");
132 void addJsonValue(nlohmann::json jsonobj);
133 void addJsonArrayValue(nlohmann::json jsonobj);
134
135 PvlKeyword &operator+=(QString value);
136
138 int size() const {
139 return m_values.size();
140 };
141 bool isNull(const int index = 0) const;
142 void clear();
143
144 friend std::istream &operator>>(std::istream &is, PvlKeyword &result);
145 friend std::ostream &operator<<(std::ostream &os,
146 const PvlKeyword &keyword);
147
149 operator double() const {
150 return toDouble(operator[](0));
151 };
152
153 operator int() const {
154 return toInt(operator[](0));
155 };
156
157 operator Isis::BigInt() const {
158 return toBigInt(operator[](0));
159 };
160
161 operator QString() const;
162
163 nlohmann::json toJson();
164
165 const QString &operator[](int index) const;
166 QString &operator[](int index);
167 QString unit(const int index = 0) const;
168
169 void addComment(QString comment);
170 void addCommentWrapped(QString comment);
171
172 void addComments(const std::vector<QString> &comments);
173
175 int comments() const {
176 return (m_comments ? m_comments->size() : 0);
177 };
178 QString comment(const int index) const;
179 void clearComment();
180
186 bool operator==(const PvlKeyword &key) const {
187 if(!m_name && !key.m_name) return true;
188 if(!m_name || !key.m_name) return false;
189
190 return (stringEqual(m_name, key.m_name));
191 };
192
198 bool operator!=(const PvlKeyword &key) const {
199 return !(*this == key);
200 };
201
202 bool isEquivalent(QString string1, int index = 0) const;
203
209 void setWidth(int width) {
210 m_width = width;
211 };
212
218 void setIndent(int indent) {
219 m_indent = indent;
220 };
221
223 int width() const {
224 return m_width;
225 };
226
228 int indent() const {
229 return m_indent;
230 };
231
233
234 void setFormat(PvlFormat *formatter);
235 PvlFormat *format();
236
237 static bool stringEqual(const QString &string1,
238 const QString &string2);
239
240
241 static QString readLine(std::istream &is, bool insideComment);
242
243 static bool readCleanKeyword(QString keyword,
244 std::vector< QString > &keywordComments,
245 QString &keywordName,
246 std::vector< std::pair<QString, QString> >
247 &keywordValues);
248
249 static QString readValue(QString &keyword, bool &quoteProblem);
250 static QString readValue(QString &keyword, bool &quoteProblem,
251 const std::vector< std::pair<char, char> > &
252 otherDelimiters);
253
254 const PvlKeyword &operator=(const PvlKeyword &other);
255
257 void validateKeyword(PvlKeyword & pvlKwrd, QString psValueType="", PvlKeyword* pvlKwrdRange=NULL);
258
259 protected:
260 QString reform(const QString &value) const;
261 QString toPvl(const QString &value) const;
262 QString toIPvl(const QString &value) const;
263 std::ostream &writeWithWrap(std::ostream &os,
264 const QString &textToWrite,
265 int startColumn,
266 PvlFormat &format) const;
267
270
271 private:
273 char * m_name;
274
283 QVarLengthArray<QString, 1> m_values;
284
286 std::vector<QString> *m_units;
287
289 std::vector<QString> *m_comments;
290
291 void init();
292
293 void writeSpaces(std::ostream &, int) const;
294
299 int m_width;
304 int m_indent;
305 };
306};
307
308#endif
309
Formats a Pvl name value pair to Isis standards.
Definition PvlFormat.h:108
A single keyword-value pair.
Definition PvlKeyword.h:87
PvlKeyword()
Constructs a blank PvlKeyword object.
Definition PvlKeyword.cpp:25
void setIndent(int indent)
Sets the indent level when outputted(for formatting)
Definition PvlKeyword.h:218
const QString & operator[](int index) const
Gets value for this object at specified index.
Definition PvlKeyword.cpp:494
void setName(QString name)
Sets the keyword name.
Definition PvlKeyword.cpp:141
friend std::istream & operator>>(std::istream &is, PvlKeyword &result)
Read in a keyword.
Definition PvlKeyword.cpp:1063
QString toIPvl(const QString &value) const
Converts a value to iPVL format.
Definition PvlKeyword.cpp:636
int width() const
Returns the current set longest keyword name.
Definition PvlKeyword.h:223
QString name() const
Returns the keyword name.
Definition PvlKeyword.h:105
int size() const
Returns the number of values stored in this keyword.
Definition PvlKeyword.h:138
PvlKeyword & operator+=(QString value)
Adds a value.
Definition PvlKeyword.cpp:439
void setJsonArrayValue(nlohmann::json jsonobj)
sets multiple items from a json array.
Definition PvlKeyword.cpp:418
bool isNull(const int index=0) const
Decides whether a value is null or not at a given index.
Definition PvlKeyword.cpp:123
static bool readCleanKeyword(QString keyword, std::vector< QString > &keywordComments, QString &keywordName, std::vector< std::pair< QString, QString > > &keywordValues)
This reads a keyword compressed back to 1 line of data (excluding comments, which are included on sep...
Definition PvlKeyword.cpp:1277
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...
Definition PvlKeyword.cpp:511
~PvlKeyword()
Destructs a PvlKeyword object.
Definition PvlKeyword.cpp:85
void setFormat(PvlFormat *formatter)
Set the PvlFormatter used to format the keyword name and value(s)
Definition PvlKeyword.cpp:1039
friend std::ostream & operator<<(std::ostream &os, const PvlKeyword &keyword)
Write out the keyword.
Definition PvlKeyword.cpp:1944
int comments() const
Returns the number of lines of comments associated with this keyword.
Definition PvlKeyword.h:175
QString comment(const int index) const
Return a comment at the specified index.
Definition PvlKeyword.cpp:595
PvlFormat * m_formatter
Formatter object.
Definition PvlKeyword.h:269
bool operator==(const PvlKeyword &key) const
Returns true of the keyword names match.
Definition PvlKeyword.h:186
int indent() const
Returns the current indent level.
Definition PvlKeyword.h:228
QString reform(const QString &value) const
Checks if the value needs to be converted to PVL or iPVL and returns it in the correct format.
Definition PvlKeyword.cpp:612
void setUnits(QString units)
Sets the unit of measure for all current values if any exist.
Definition PvlKeyword.cpp:204
void setWidth(int width)
The width of the longest keyword name (for formatting)
Definition PvlKeyword.h:209
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
Definition PvlKeyword.cpp:689
bool operator!=(const PvlKeyword &key) const
Returns true of the keyword names do not match.
Definition PvlKeyword.h:198
bool isNamed(QString name) const
Determines whether two PvlKeywords have the same name or not.
Definition PvlKeyword.h:117
static QString readValue(QString &keyword, bool &quoteProblem)
Definition PvlKeyword.cpp:1725
PvlFormat * format()
Get the current PvlFormat or create one.
Definition PvlKeyword.cpp:1050
void addCommentWrapped(QString comment)
Automatically wraps and adds long comments to the PvlKeyword.
Definition PvlKeyword.cpp:564
nlohmann::json toJson()
Definition PvlKeyword.cpp:384
PvlKeyword(QString name, std::vector< std::string > vecValue, QString unit="")
QString toPvl(const QString &value) const
Converts a value to PVL format.
Definition PvlKeyword.cpp:664
PvlKeyword & operator=(QString value)
Sets new values.
Definition PvlKeyword.cpp:267
std::ostream & writeWithWrap(std::ostream &os, const QString &textToWrite, int startColumn, PvlFormat &format) const
Wraps output so that length doesn't exceed the character limit.
Definition PvlKeyword.cpp:765
void setValue(QString value, QString unit="")
Sets new values.
Definition PvlKeyword.cpp:176
void addComment(QString comment)
Add a comment to the PvlKeyword.
Definition PvlKeyword.cpp:530
bool isEquivalent(QString string1, int index=0) const
Checks to see if a value with a specified index is equivalent to another QString.
Definition PvlKeyword.cpp:716
void setJsonValue(nlohmann::json jsonobj)
Sets new value from Json.
Definition PvlKeyword.cpp:194
void clearComment()
Clears the current comments.
Definition PvlKeyword.cpp:582
void addComments(const std::vector< QString > &comments)
This method adds multiple comments at once by calling AddComments on each element in the vector.
Definition PvlKeyword.cpp:1256
static QString readLine(std::istream &is, bool insideComment)
This method reads one line of data from the input stream.
Definition PvlKeyword.cpp:1882
void clear()
Clears all values and units for this PvlKeyword object.
Definition PvlKeyword.cpp:445
void validateKeyword(PvlKeyword &pvlKwrd, QString psValueType="", PvlKeyword *pvlKwrdRange=NULL)
Validate Keyword for type and required values.
Definition PvlKeyword.cpp:2052
void addJsonArrayValue(nlohmann::json jsonobj)
Adds multiple items from a json array.
Definition PvlKeyword.cpp:366
void addJsonValue(nlohmann::json jsonobj)
Adds a value with units.
Definition PvlKeyword.cpp:322
void addValue(QString value, QString unit="")
Adds a value with units.
Definition PvlKeyword.cpp:288
Parse and return elements of a Pvl sequence.
Definition PvlSequence.h:46
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition IString.cpp:93
BigInt toBigInt(const QString &string)
Global function to convert from a string to a "big" integer.
Definition IString.cpp:115
long long int BigInt
Big int.
Definition Constants.h:49
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition IString.cpp:149