USGS

Isis 3.0 Object Programmers' Reference

Home

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