Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

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, QString unit = "");
123
124 void setUnits(QString units);
125 void setUnits(QString value, QString units);
126
127 PvlKeyword &operator=(QString value);
128
129 void addValue(QString value, QString unit = "");
130 void addJsonValue(nlohmann::json jsonobj, QString unit = "");
131
132 PvlKeyword &operator+=(QString value);
133
135 int size() const {
136 return m_values.size();
137 };
138 bool isNull(const int index = 0) const;
139 void clear();
140
141 friend std::istream &operator>>(std::istream &is, PvlKeyword &result);
142 friend std::ostream &operator<<(std::ostream &os,
143 const PvlKeyword &keyword);
144
146 operator double() const {
147 return toDouble(operator[](0));
148 };
149
150 operator int() const {
151 return toInt(operator[](0));
152 };
153
154 operator Isis::BigInt() const {
155 return toBigInt(operator[](0));
156 };
157
158 operator QString() const;
159
160 const QString &operator[](int index) const;
161 QString &operator[](int index);
162 QString unit(const int index = 0) const;
163
164 void addComment(QString comment);
165 void addCommentWrapped(QString comment);
166
167 void addComments(const std::vector<QString> &comments);
168
170 int comments() const {
171 return (m_comments ? m_comments->size() : 0);
172 };
173 QString comment(const int index) const;
174 void clearComment();
175
181 bool operator==(const PvlKeyword &key) const {
182 if(!m_name && !key.m_name) return true;
183 if(!m_name || !key.m_name) return false;
184
185 return (stringEqual(m_name, key.m_name));
186 };
187
193 bool operator!=(const PvlKeyword &key) const {
194 return !(*this == key);
195 };
196
197 bool isEquivalent(QString string1, int index = 0) const;
198
204 void setWidth(int width) {
205 m_width = width;
206 };
207
213 void setIndent(int indent) {
214 m_indent = indent;
215 };
216
218 int width() const {
219 return m_width;
220 };
221
223 int indent() const {
224 return m_indent;
225 };
226
228
229 void setFormat(PvlFormat *formatter);
230 PvlFormat *format();
231
232 static bool stringEqual(const QString &string1,
233 const QString &string2);
234
235
236 static QString readLine(std::istream &is, bool insideComment);
237
238 static bool readCleanKeyword(QString keyword,
239 std::vector< QString > &keywordComments,
240 QString &keywordName,
241 std::vector< std::pair<QString, QString> >
242 &keywordValues);
243
244 static QString readValue(QString &keyword, bool &quoteProblem);
245 static QString readValue(QString &keyword, bool &quoteProblem,
246 const std::vector< std::pair<char, char> > &
247 otherDelimiters);
248
249 const PvlKeyword &operator=(const PvlKeyword &other);
250
252 void validateKeyword(PvlKeyword & pvlKwrd, QString psValueType="", PvlKeyword* pvlKwrdRange=NULL);
253
254 protected:
255 QString reform(const QString &value) const;
256 QString toPvl(const QString &value) const;
257 QString toIPvl(const QString &value) const;
258 std::ostream &writeWithWrap(std::ostream &os,
259 const QString &textToWrite,
260 int startColumn,
261 PvlFormat &format) const;
262
265
266 private:
268 char * m_name;
269
278 QVarLengthArray<QString, 1> m_values;
279
281 std::vector<QString> *m_units;
282
284 std::vector<QString> *m_comments;
285
286 void init();
287
288 void writeSpaces(std::ostream &, int) const;
289
294 int m_width;
299 int m_indent;
300 };
301};
302
303#endif
304
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:24
void setIndent(int indent)
Sets the indent level when outputted(for formatting)
Definition PvlKeyword.h:213
const QString & operator[](int index) const
Gets value for this object at specified index.
Definition PvlKeyword.cpp:417
void setName(QString name)
Sets the keyword name.
Definition PvlKeyword.cpp:140
friend std::istream & operator>>(std::istream &is, PvlKeyword &result)
Read in a keyword.
Definition PvlKeyword.cpp:986
void setJsonValue(nlohmann::json jsonobj, QString unit="")
Sets new value from Json.
Definition PvlKeyword.cpp:193
QString toIPvl(const QString &value) const
Converts a value to iPVL format.
Definition PvlKeyword.cpp:559
int width() const
Returns the current set longest keyword name.
Definition PvlKeyword.h:218
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:135
PvlKeyword & operator+=(QString value)
Adds a value.
Definition PvlKeyword.cpp:362
bool isNull(const int index=0) const
Decides whether a value is null or not at a given index.
Definition PvlKeyword.cpp:122
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:1200
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:434
~PvlKeyword()
Destructs a PvlKeyword object.
Definition PvlKeyword.cpp:84
void setFormat(PvlFormat *formatter)
Set the PvlFormatter used to format the keyword name and value(s)
Definition PvlKeyword.cpp:962
friend std::ostream & operator<<(std::ostream &os, const PvlKeyword &keyword)
Write out the keyword.
Definition PvlKeyword.cpp:1867
int comments() const
Returns the number of lines of comments associated with this keyword.
Definition PvlKeyword.h:170
QString comment(const int index) const
Return a comment at the specified index.
Definition PvlKeyword.cpp:518
PvlFormat * m_formatter
Formatter object.
Definition PvlKeyword.h:264
bool operator==(const PvlKeyword &key) const
Returns true of the keyword names match.
Definition PvlKeyword.h:181
int indent() const
Returns the current indent level.
Definition PvlKeyword.h:223
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:535
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:204
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
Definition PvlKeyword.cpp:612
bool operator!=(const PvlKeyword &key) const
Returns true of the keyword names do not match.
Definition PvlKeyword.h:193
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:1648
PvlFormat * format()
Get the current PvlFormat or create one.
Definition PvlKeyword.cpp:973
void addCommentWrapped(QString comment)
Automatically wraps and adds long comments to the PvlKeyword.
Definition PvlKeyword.cpp:487
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:587
void addJsonValue(nlohmann::json jsonobj, QString unit="")
Adds a value with units.
Definition PvlKeyword.cpp:322
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:688
void setValue(QString value, QString unit="")
Sets new values.
Definition PvlKeyword.cpp:175
void addComment(QString comment)
Add a comment to the PvlKeyword.
Definition PvlKeyword.cpp:453
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:639
void clearComment()
Clears the current comments.
Definition PvlKeyword.cpp:505
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:1179
static QString readLine(std::istream &is, bool insideComment)
This method reads one line of data from the input stream.
Definition PvlKeyword.cpp:1805
void clear()
Clears all values and units for this PvlKeyword object.
Definition PvlKeyword.cpp:368
void validateKeyword(PvlKeyword &pvlKwrd, QString psValueType="", PvlKeyword *pvlKwrdRange=NULL)
Validate Keyword for type and required values.
Definition PvlKeyword.cpp:1975
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