Isis 3 Programmer Reference
PvlKeyword.h
1 #ifndef PvlKeyword_h
2 #define PvlKeyword_h
3 
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 namespace 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);
89  ~PvlKeyword();
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 
Isis::PvlKeyword::name
QString name() const
Returns the keyword name.
Definition: PvlKeyword.h:98
Isis::PvlKeyword::operator>>
friend std::istream & operator>>(std::istream &is, PvlKeyword &result)
Read in a keyword.
Definition: PvlKeyword.cpp:909
Isis::PvlKeyword::m_indent
int m_indent
The number of indentations to make.
Definition: PvlKeyword.h:289
Isis::PvlKeyword::operator<<
friend std::ostream & operator<<(std::ostream &os, const PvlKeyword &keyword)
Write out the keyword.
Definition: PvlKeyword.cpp:1765
Isis::PvlKeyword::operator=
PvlKeyword & operator=(QString value)
Sets new values.
Definition: PvlKeyword.cpp:231
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::PvlKeyword::PvlKeyword
PvlKeyword()
Constructs a blank PvlKeyword object.
Definition: PvlKeyword.cpp:22
Isis::PvlFormat
Formats a Pvl name value pair to Isis standards.
Definition: PvlFormat.h:108
Isis::PvlKeyword::validateKeyword
void validateKeyword(PvlKeyword &pvlKwrd, QString psValueType="", PvlKeyword *pvlKwrdRange=NULL)
Validate Keyword for type and required values.
Definition: PvlKeyword.cpp:1873
Isis::PvlKeyword::m_units
std::vector< QString > * m_units
The units for the values.
Definition: PvlKeyword.h:271
Isis::PvlKeyword::init
void init()
Clears all PvlKeyword data.
Definition: PvlKeyword.cpp:83
Isis::PvlKeyword::addComments
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
Isis::PvlKeyword::indent
int indent() const
Returns the current indent level.
Definition: PvlKeyword.h:213
Isis::PvlKeyword::addValue
void addValue(QString value, QString unit="")
Adds a value with units.
Definition: PvlKeyword.cpp:252
Isis::PvlKeyword::setFormat
void setFormat(PvlFormat *formatter)
Set the PvlFormatter used to format the keyword name and value(s)
Definition: PvlKeyword.cpp:885
Isis::PvlKeyword::clear
void clear()
Clears all values and units for this PvlKeyword object.
Definition: PvlKeyword.cpp:291
Isis::PvlKeyword::readLine
static QString readLine(std::istream &is, bool insideComment)
This method reads one line of data from the input stream.
Definition: PvlKeyword.cpp:1703
Isis::PvlKeyword::~PvlKeyword
~PvlKeyword()
Destructs a PvlKeyword object.
Definition: PvlKeyword.cpp:64
Isis::PvlKeyword::setUnits
void setUnits(QString units)
Sets the unit of measure for all current values if any exist.
Definition: PvlKeyword.cpp:166
Isis::PvlKeyword::toIPvl
QString toIPvl(const QString &value) const
Converts a value to iPVL format.
Definition: PvlKeyword.cpp:482
Isis::PvlKeyword::m_comments
std::vector< QString > * m_comments
The comments for the keyword.
Definition: PvlKeyword.h:274
Isis::PvlKeyword::width
int width() const
Returns the current set longest keyword name.
Definition: PvlKeyword.h:208
Isis::PvlKeyword::format
PvlFormat * format()
Get the current PvlFormat or create one.
Definition: PvlKeyword.cpp:896
Isis::PvlKeyword::addCommentWrapped
void addCommentWrapped(QString comment)
Automatically wraps and adds long comments to the PvlKeyword.
Definition: PvlKeyword.cpp:410
Isis::PvlKeyword::setIndent
void setIndent(int indent)
Sets the indent level when outputted(for formatting)
Definition: PvlKeyword.h:203
Isis::PvlKeyword::comments
int comments() const
Returns the number of lines of comments associated with this keyword.
Definition: PvlKeyword.h:160
Isis::PvlKeyword::setName
void setName(QString name)
Sets the keyword name.
Definition: PvlKeyword.cpp:120
Isis::toBigInt
BigInt toBigInt(const QString &string)
Global function to convert from a string to a "big" integer.
Definition: IString.cpp:115
Isis::PvlKeyword::setWidth
void setWidth(int width)
The width of the longest keyword name (for formatting)
Definition: PvlKeyword.h:194
Isis::PvlKeyword::operator==
bool operator==(const PvlKeyword &key) const
Returns true of the keyword names match.
Definition: PvlKeyword.h:171
Isis::toInt
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:93
Isis::PvlKeyword::toPvl
QString toPvl(const QString &value) const
Converts a value to PVL format.
Definition: PvlKeyword.cpp:510
Isis::PvlKeyword::m_name
char * m_name
The keyword's name... This is a c-string for memory efficiency.
Definition: PvlKeyword.h:258
Isis::PvlKeyword::addComment
void addComment(QString comment)
Add a comment to the PvlKeyword.
Definition: PvlKeyword.cpp:376
Isis::BigInt
long long int BigInt
Big int.
Definition: Constants.h:49
Isis::PvlKeyword::operator[]
const QString & operator[](int index) const
Gets value for this object at specified index.
Definition: PvlKeyword.cpp:340
Isis::PvlKeyword::writeSpaces
void writeSpaces(std::ostream &, int) const
This writes numSpaces spaces to the ostream.
Definition: PvlKeyword.cpp:872
Isis::PvlKeyword::operator!=
bool operator!=(const PvlKeyword &key) const
Returns true of the keyword names do not match.
Definition: PvlKeyword.h:183
Isis::PvlKeyword::setValue
void setValue(QString value, QString unit="")
Sets new values.
Definition: PvlKeyword.cpp:155
Isis::PvlKeyword::isNamed
bool isNamed(QString name) const
Determines whether two PvlKeywords have the same name or not.
Definition: PvlKeyword.h:110
Isis::PvlKeyword::m_formatter
PvlFormat * m_formatter
Formatter object.
Definition: PvlKeyword.h:254
Isis::PvlKeyword::operator+=
PvlKeyword & operator+=(QString value)
Adds a value.
Definition: PvlKeyword.cpp:285
Isis::PvlKeyword::writeWithWrap
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
Isis::PvlKeyword::m_values
QVarLengthArray< QString, 1 > m_values
The values in the keyword.
Definition: PvlKeyword.h:268
Isis::toDouble
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:149
Isis::PvlKeyword::clearComment
void clearComment()
Clears the current comments.
Definition: PvlKeyword.cpp:428
Isis::PvlKeyword::isNull
bool isNull(const int index=0) const
Decides whether a value is null or not at a given index.
Definition: PvlKeyword.cpp:102
Isis::PvlKeyword::size
int size() const
Returns the number of values stored in this keyword.
Definition: PvlKeyword.h:125
Isis::PvlKeyword::unit
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
Isis::PvlKeyword::reform
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
Isis::PvlKeyword::isEquivalent
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
Isis::PvlSequence
Parse and return elements of a Pvl sequence.
Definition: PvlSequence.h:46
Isis::PvlKeyword::comment
QString comment(const int index) const
Return a comment at the specified index.
Definition: PvlKeyword.cpp:441
Isis::PvlKeyword::m_width
int m_width
The width of the longest keyword.
Definition: PvlKeyword.h:284
Isis::PvlKeyword::readCleanKeyword
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
Isis::PvlKeyword::stringEqual
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
Definition: PvlKeyword.cpp:535
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16