Isis 3 Developer Reference
PvlKeyword.h
Go to the documentation of this file.
1 #ifndef PvlKeyword_h
2 #define PvlKeyword_h
3 
25 #include <vector>
26 #include <map>
27 #include <iostream>
28 
29 #include <QString>
30 #include <QVariant>
31 #include <QVarLengthArray>
32 
33 #include "Constants.h"
34 #include "IString.h"
35 
36 namespace Isis {
37  class PvlSequence;
38  class PvlFormat;
39 
98  class PvlKeyword {
99  public:
100  PvlKeyword();
101  PvlKeyword(QString name);
102  PvlKeyword(QString name, QString value,
103  QString unit = "");
104  PvlKeyword(const PvlKeyword &other);
105  ~PvlKeyword();
106 
107  void setName(QString name);
108 
114  QString name() const {
115  if(m_name)
116  return m_name;
117  else
118  return "";
119  };
126  bool isNamed(QString name) const {
127  return stringEqual(name, this->name());
128  };
129 
130  void setValue(QString value, QString unit = "");
131 
132  void setUnits(QString units);
133  void setUnits(QString value, QString units);
134 
135  PvlKeyword &operator=(QString value);
136 
137  void addValue(QString value, QString unit = "");
138  PvlKeyword &operator+=(QString value);
139 
141  int size() const {
142  return m_values.size();
143  };
144  bool isNull(const int index = 0) const;
145  void clear();
146 
147  friend std::istream &operator>>(std::istream &is, PvlKeyword &result);
148  friend std::ostream &operator<<(std::ostream &os,
149  const PvlKeyword &keyword);
150 
152  operator double() const {
153  return toDouble(operator[](0));
154  };
156  operator int() const {
157  return toInt(operator[](0));
158  };
160  operator Isis::BigInt() const {
161  return toBigInt(operator[](0));
162  };
163 
164  operator QString() const;
165 
166  const QString &operator[](int index) const;
167  QString &operator[](int index);
168  QString unit(const int index = 0) const;
169 
170  void addComment(QString comment);
171  void addCommentWrapped(QString comment);
172 
173  void addComments(const std::vector<QString> &comments);
174 
176  int comments() const {
177  return (m_comments ? m_comments->size() : 0);
178  };
179  QString comment(const int index) const;
180  void clearComment();
181 
187  bool operator==(const PvlKeyword &key) const {
188  if(!m_name && !key.m_name) return true;
189  if(!m_name || !key.m_name) return false;
190 
191  return (stringEqual(m_name, key.m_name));
192  };
193 
199  bool operator!=(const PvlKeyword &key) const {
200  return !(*this == key);
201  };
202 
203  bool isEquivalent(QString string1, int index = 0) const;
204 
210  void setWidth(int width) {
211  m_width = width;
212  };
213 
219  void setIndent(int indent) {
220  m_indent = indent;
221  };
222 
224  int width() const {
225  return m_width;
226  };
227 
229  int indent() const {
230  return m_indent;
231  };
232 
234 
235  void setFormat(PvlFormat *formatter);
236  PvlFormat *format();
237 
238  static bool stringEqual(const QString &string1,
239  const QString &string2);
240 
241 
242  static QString readLine(std::istream &is, bool insideComment);
243 
244  static bool readCleanKeyword(QString keyword,
245  std::vector< QString > &keywordComments,
246  QString &keywordName,
247  std::vector< std::pair<QString, QString> >
248  &keywordValues);
249 
250  static QString readValue(QString &keyword, bool &quoteProblem);
251  static QString readValue(QString &keyword, bool &quoteProblem,
252  const std::vector< std::pair<char, char> > &
253  otherDelimiters);
254 
255  const PvlKeyword &operator=(const PvlKeyword &other);
256 
258  void validateKeyword(PvlKeyword & pvlKwrd, QString psValueType="", PvlKeyword* pvlKwrdRange=NULL);
259 
260  protected:
261  QString reform(const QString &value) const;
262  QString toPvl(const QString &value) const;
263  QString toIPvl(const QString &value) const;
264  std::ostream &writeWithWrap(std::ostream &os,
265  const QString &textToWrite,
266  int startColumn,
267  PvlFormat &format) const;
268 
271 
272  private:
274  char * m_name;
275 
284  QVarLengthArray<QString, 1> m_values;
285 
287  std::vector<QString> *m_units;
288 
290  std::vector<QString> *m_comments;
291 
292  void init();
293 
294  void writeSpaces(std::ostream &, int) const;
295 
300  int m_width;
305  int m_indent;
306  };
307 };
308 
309 #endif
310 
long long int BigInt
Big int.
Definition: Constants.h:65
PvlKeyword & operator+=(QString value)
Adds a value.
Definition: PvlKeyword.cpp:301
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:373
Parse and return elements of a Pvl sequence.
Definition: PvlSequence.h:64
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:578
void clear()
Clears all values and units for this PvlKeyword object.
Definition: PvlKeyword.cpp:307
std::ostream & writeWithWrap(std::ostream &os, const QString &textToWrite, int startColumn, PvlFormat &format) const
Wraps output so that length doesn&#39;t exceed the character limit.
Definition: PvlKeyword.cpp:627
void setIndent(int indent)
Sets the indent level when outputted(for formatting)
Definition: PvlKeyword.h:219
int indent() const
Returns the current indent level.
Definition: PvlKeyword.h:229
PvlKeyword()
Constructs a blank PvlKeyword object.
Definition: PvlKeyword.cpp:38
Formats a Pvl name value pair to Isis standards.
Definition: PvlFormat.h:124
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:108
void setName(QString name)
Sets the keyword name.
Definition: PvlKeyword.cpp:136
static QString readLine(std::istream &is, bool insideComment)
This method reads one line of data from the input stream.
Definition: PvlKeyword.cpp:1719
void validateKeyword(PvlKeyword &pvlKwrd, QString psValueType="", PvlKeyword *pvlKwrdRange=NULL)
Validate Keyword for type and required values.
Definition: PvlKeyword.cpp:1889
void setWidth(int width)
The width of the longest keyword name (for formatting)
Definition: PvlKeyword.h:210
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
Definition: PvlKeyword.cpp:551
BigInt toBigInt(const QString &string)
Global function to convert from a string to a "big" integer.
Definition: IString.cpp:130
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
bool isNamed(QString name) const
Determines whether two PvlKeywords have the same name or not.
Definition: PvlKeyword.h:126
const QString & operator[](int index) const
Gets value for this object at specified index.
Definition: PvlKeyword.cpp:356
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:1118
QString toPvl(const QString &value) const
Converts a value to PVL format.
Definition: PvlKeyword.cpp:526
void addComment(QString comment)
Add a comment to the PvlKeyword.
Definition: PvlKeyword.cpp:392
bool operator!=(const PvlKeyword &key) const
Returns true of the keyword names do not match.
Definition: PvlKeyword.h:199
int size() const
Returns the number of values stored in this keyword.
Definition: PvlKeyword.h:141
QString toIPvl(const QString &value) const
Converts a value to iPVL format.
Definition: PvlKeyword.cpp:498
PvlFormat * format()
Get the current PvlFormat or create one.
Definition: PvlKeyword.cpp:912
void clearComment()
Clears the current comments.
Definition: PvlKeyword.cpp:444
static QString readValue(QString &keyword, bool &quoteProblem)
Definition: PvlKeyword.cpp:1562
QString comment(const int index) const
Return a comment at the specified index.
Definition: PvlKeyword.cpp:457
A single keyword-value pair.
Definition: PvlKeyword.h:98
bool isNull(const int index=0) const
Decides whether a value is null or not at a given index.
Definition: PvlKeyword.cpp:118
friend std::istream & operator>>(std::istream &is, PvlKeyword &result)
Read in a keyword.
Definition: PvlKeyword.cpp:925
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:474
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:1139
void setUnits(QString units)
Sets the unit of measure for all current values if any exist.
Definition: PvlKeyword.cpp:182
friend std::ostream & operator<<(std::ostream &os, const PvlKeyword &keyword)
Write out the keyword.
Definition: PvlKeyword.cpp:1781
bool operator==(const PvlKeyword &key) const
Returns true of the keyword names match.
Definition: PvlKeyword.h:187
QString name() const
Returns the keyword name.
Definition: PvlKeyword.h:114
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
PvlFormat * m_formatter
Formatter object.
Definition: PvlKeyword.h:270
int comments() const
Returns the number of lines of comments associated with this keyword.
Definition: PvlKeyword.h:176
~PvlKeyword()
Destructs a PvlKeyword object.
Definition: PvlKeyword.cpp:80
PvlKeyword & operator=(QString value)
Sets new values.
Definition: PvlKeyword.cpp:247
void setValue(QString value, QString unit="")
Sets new values.
Definition: PvlKeyword.cpp:171
int width() const
Returns the current set longest keyword name.
Definition: PvlKeyword.h:224
void addCommentWrapped(QString comment)
Automatically wraps and adds long comments to the PvlKeyword.
Definition: PvlKeyword.cpp:426
void setFormat(PvlFormat *formatter)
Set the PvlFormatter used to format the keyword name and value(s)
Definition: PvlKeyword.cpp:901
void addValue(QString value, QString unit="")
Adds a value with units.
Definition: PvlKeyword.cpp:268