File failed to load: https://isis.astrogeology.usgs.gov/7.1.0/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
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
20namespace Isis {
21 class PvlSequence;
22 class PvlFormat;
23
82 class PvlKeyword {
83 public:
84 PvlKeyword();
85 PvlKeyword(QString name);
86 PvlKeyword(QString name, QString value,
87 QString unit = "");
88 PvlKeyword(const PvlKeyword &other);
90
91 void setName(QString name);
92
98 QString name() const {
99 if(m_name)
100 return m_name;
101 else
102 return "";
103 };
110 bool isNamed(QString name) const {
111 return stringEqual(name, this->name());
112 };
113
114 void setValue(QString value, QString unit = "");
115
116 void setUnits(QString units);
117 void setUnits(QString value, QString units);
118
119 PvlKeyword &operator=(QString value);
120
121 void addValue(QString value, QString unit = "");
122 PvlKeyword &operator+=(QString value);
123
125 int size() const {
126 return m_values.size();
127 };
128 bool isNull(const int index = 0) const;
129 void clear();
130
131 friend std::istream &operator>>(std::istream &is, PvlKeyword &result);
132 friend std::ostream &operator<<(std::ostream &os,
133 const PvlKeyword &keyword);
134
136 operator double() const {
137 return toDouble(operator[](0));
138 };
140 operator int() const {
141 return toInt(operator[](0));
142 };
144 operator Isis::BigInt() const {
145 return toBigInt(operator[](0));
146 };
147
148 operator QString() const;
149
150 const QString &operator[](int index) const;
151 QString &operator[](int index);
152 QString unit(const int index = 0) const;
153
154 void addComment(QString comment);
155 void addCommentWrapped(QString comment);
156
157 void addComments(const std::vector<QString> &comments);
158
160 int comments() const {
161 return (m_comments ? m_comments->size() : 0);
162 };
163 QString comment(const int index) const;
164 void clearComment();
165
171 bool operator==(const PvlKeyword &key) const {
172 if(!m_name && !key.m_name) return true;
173 if(!m_name || !key.m_name) return false;
174
175 return (stringEqual(m_name, key.m_name));
176 };
177
183 bool operator!=(const PvlKeyword &key) const {
184 return !(*this == key);
185 };
186
187 bool isEquivalent(QString string1, int index = 0) const;
188
194 void setWidth(int width) {
195 m_width = width;
196 };
197
203 void setIndent(int indent) {
204 m_indent = indent;
205 };
206
208 int width() const {
209 return m_width;
210 };
211
213 int indent() const {
214 return m_indent;
215 };
216
218
219 void setFormat(PvlFormat *formatter);
220 PvlFormat *format();
221
222 static bool stringEqual(const QString &string1,
223 const QString &string2);
224
225
226 static QString readLine(std::istream &is, bool insideComment);
227
228 static bool readCleanKeyword(QString keyword,
229 std::vector< QString > &keywordComments,
230 QString &keywordName,
231 std::vector< std::pair<QString, QString> >
232 &keywordValues);
233
234 static QString readValue(QString &keyword, bool &quoteProblem);
235 static QString readValue(QString &keyword, bool &quoteProblem,
236 const std::vector< std::pair<char, char> > &
237 otherDelimiters);
238
239 const PvlKeyword &operator=(const PvlKeyword &other);
240
242 void validateKeyword(PvlKeyword & pvlKwrd, QString psValueType="", PvlKeyword* pvlKwrdRange=NULL);
243
244 protected:
245 QString reform(const QString &value) const;
246 QString toPvl(const QString &value) const;
247 QString toIPvl(const QString &value) const;
248 std::ostream &writeWithWrap(std::ostream &os,
249 const QString &textToWrite,
250 int startColumn,
251 PvlFormat &format) const;
252
255
256 private:
258 char * m_name;
259
268 QVarLengthArray<QString, 1> m_values;
269
271 std::vector<QString> *m_units;
272
274 std::vector<QString> *m_comments;
275
276 void init();
277
278 void writeSpaces(std::ostream &, int) const;
279
284 int m_width;
289 int m_indent;
290 };
291};
292
293#endif
294
Formats a Pvl name value pair to Isis standards.
Definition: PvlFormat.h:108
A single keyword-value pair.
Definition: PvlKeyword.h:82
PvlKeyword()
Constructs a blank PvlKeyword object.
Definition: PvlKeyword.cpp:22
void setIndent(int indent)
Sets the indent level when outputted(for formatting)
Definition: PvlKeyword.h:203
const QString & operator[](int index) const
Gets value for this object at specified index.
Definition: PvlKeyword.cpp:340
void setName(QString name)
Sets the keyword name.
Definition: PvlKeyword.cpp:120
friend std::istream & operator>>(std::istream &is, PvlKeyword &result)
Read in a keyword.
Definition: PvlKeyword.cpp:909
QString toIPvl(const QString &value) const
Converts a value to iPVL format.
Definition: PvlKeyword.cpp:482
int width() const
Returns the current set longest keyword name.
Definition: PvlKeyword.h:208
QString name() const
Returns the keyword name.
Definition: PvlKeyword.h:98
int size() const
Returns the number of values stored in this keyword.
Definition: PvlKeyword.h:125
PvlKeyword & operator+=(QString value)
Adds a value.
Definition: PvlKeyword.cpp:285
bool isNull(const int index=0) const
Decides whether a value is null or not at a given index.
Definition: PvlKeyword.cpp:102
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:1123
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:357
~PvlKeyword()
Destructs a PvlKeyword object.
Definition: PvlKeyword.cpp:64
void setFormat(PvlFormat *formatter)
Set the PvlFormatter used to format the keyword name and value(s)
Definition: PvlKeyword.cpp:885
friend std::ostream & operator<<(std::ostream &os, const PvlKeyword &keyword)
Write out the keyword.
Definition: PvlKeyword.cpp:1765
int comments() const
Returns the number of lines of comments associated with this keyword.
Definition: PvlKeyword.h:160
QString comment(const int index) const
Return a comment at the specified index.
Definition: PvlKeyword.cpp:441
PvlFormat * m_formatter
Formatter object.
Definition: PvlKeyword.h:254
bool operator==(const PvlKeyword &key) const
Returns true of the keyword names match.
Definition: PvlKeyword.h:171
int indent() const
Returns the current indent level.
Definition: PvlKeyword.h:213
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:458
void setUnits(QString units)
Sets the unit of measure for all current values if any exist.
Definition: PvlKeyword.cpp:166
void setWidth(int width)
The width of the longest keyword name (for formatting)
Definition: PvlKeyword.h:194
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
Definition: PvlKeyword.cpp:535
bool operator!=(const PvlKeyword &key) const
Returns true of the keyword names do not match.
Definition: PvlKeyword.h:183
bool isNamed(QString name) const
Determines whether two PvlKeywords have the same name or not.
Definition: PvlKeyword.h:110
static QString readValue(QString &keyword, bool &quoteProblem)
Definition: PvlKeyword.cpp:1546
PvlFormat * format()
Get the current PvlFormat or create one.
Definition: PvlKeyword.cpp:896
void addCommentWrapped(QString comment)
Automatically wraps and adds long comments to the PvlKeyword.
Definition: PvlKeyword.cpp:410
QString toPvl(const QString &value) const
Converts a value to PVL format.
Definition: PvlKeyword.cpp:510
PvlKeyword & operator=(QString value)
Sets new values.
Definition: PvlKeyword.cpp:231
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:611
void setValue(QString value, QString unit="")
Sets new values.
Definition: PvlKeyword.cpp:155
void addComment(QString comment)
Add a comment to the PvlKeyword.
Definition: PvlKeyword.cpp:376
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:562
void clearComment()
Clears the current comments.
Definition: PvlKeyword.cpp:428
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:1102
static QString readLine(std::istream &is, bool insideComment)
This method reads one line of data from the input stream.
Definition: PvlKeyword.cpp:1703
void clear()
Clears all values and units for this PvlKeyword object.
Definition: PvlKeyword.cpp:291
void validateKeyword(PvlKeyword &pvlKwrd, QString psValueType="", PvlKeyword *pvlKwrdRange=NULL)
Validate Keyword for type and required values.
Definition: PvlKeyword.cpp:1873
void addValue(QString value, QString unit="")
Adds a value with units.
Definition: PvlKeyword.cpp:252
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

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 02/21/2025 21:56:47