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 3 Programmer Reference
PvlKeyword.h
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) {
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
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.
std::vector< QString > * m_comments
The comments for the keyword.
Definition PvlKeyword.h:284
QVarLengthArray< QString, 1 > m_values
The values in the keyword.
Definition PvlKeyword.h:278
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.
void setName(QString name)
Sets the keyword name.
friend std::istream & operator>>(std::istream &is, PvlKeyword &result)
Read in a keyword.
void setJsonValue(nlohmann::json jsonobj, QString unit="")
Sets new value from Json.
QString toIPvl(const QString &value) const
Converts a value to iPVL format.
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.
std::vector< QString > * m_units
The units for the values.
Definition PvlKeyword.h:281
bool isNull(const int index=0) const
Decides whether a value is null or not at a given index.
char * m_name
The keyword's name... This is a c-string for memory efficiency.
Definition PvlKeyword.h:268
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...
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...
~PvlKeyword()
Destructs a PvlKeyword object.
void setFormat(PvlFormat *formatter)
Set the PvlFormatter used to format the keyword name and value(s)
friend std::ostream & operator<<(std::ostream &os, const PvlKeyword &keyword)
Write out the keyword.
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.
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.
void setUnits(QString units)
Sets the unit of measure for all current values if any exist.
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.
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
PvlFormat * format()
Get the current PvlFormat or create one.
void addCommentWrapped(QString comment)
Automatically wraps and adds long comments to the PvlKeyword.
QString toPvl(const QString &value) const
Converts a value to PVL format.
void addJsonValue(nlohmann::json jsonobj, QString unit="")
Adds a value with units.
PvlKeyword & operator=(QString value)
Sets new values.
void writeSpaces(std::ostream &, int) const
This writes numSpaces spaces to the ostream.
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.
void setValue(QString value, QString unit="")
Sets new values.
void addComment(QString comment)
Add a comment to the PvlKeyword.
int m_width
The width of the longest keyword.
Definition PvlKeyword.h:294
bool isEquivalent(QString string1, int index=0) const
Checks to see if a value with a specified index is equivalent to another QString.
void clearComment()
Clears the current comments.
void addComments(const std::vector< QString > &comments)
This method adds multiple comments at once by calling AddComments on each element in the vector.
static QString readLine(std::istream &is, bool insideComment)
This method reads one line of data from the input stream.
int m_indent
The number of indentations to make.
Definition PvlKeyword.h:299
void clear()
Clears all values and units for this PvlKeyword object.
void validateKeyword(PvlKeyword &pvlKwrd, QString psValueType="", PvlKeyword *pvlKwrdRange=NULL)
Validate Keyword for type and required values.
void init()
Clears all PvlKeyword data.
void addValue(QString value, QString unit="")
Adds a value with units.
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