Isis 3 Programmer Reference
PvlFormat.h
1 #ifndef PvlFormat_h
2 #define PvlFormat_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 #include <map>
10 #include <string>
11 
12 #include "Pvl.h"
13 
14 #include "PvlKeyword.h"
15 
16 namespace Isis {
17 
19  enum KeywordType { NoTypeKeyword,
20  StringKeyword,
21  BoolKeyword,
22  IntegerKeyword,
23  RealKeyword,
24  OctalKeyword,
25  HexKeyword,
26  BinaryKeyword,
27  EnumKeyword
28  };
29 
38  inline KeywordType toKeywordType(const QString type) {
39 
40  QString t(type);
41  t = t.remove(QRegExp("[\\w_-\"'")).toUpper();
42 
43  if(t == "STRING") return StringKeyword;
44  else if(t == "BOOL") return BoolKeyword;
45  else if(t == "INTEGER") return IntegerKeyword;
46  else if(t == "REAL") return RealKeyword;
47  else if(t == "OCTAL") return OctalKeyword;
48  else if(t == "HEX") return HexKeyword;
49  else if(t == "BINARY") return BinaryKeyword;
50  else if(t == "ENUM") return EnumKeyword;
51  return NoTypeKeyword;
52  }
53 
108  class PvlFormat {
109 
110  public:
111 
112  PvlFormat();
113  PvlFormat(const QString &file);
114  PvlFormat(Pvl &keymap);
115  virtual ~PvlFormat() {};
116 
117  void add(const QString &file);
118  void add(Pvl &keymap);
119 
127  void setCharLimit(const unsigned int limit) {
128  m_charLimit = limit;
129  };
130 
138  unsigned int charLimit() const {
139  return m_charLimit;
140  };
141 
142  virtual QString formatValue(const PvlKeyword &keyword,
143  int valueIndex = 0);
144  virtual QString formatName(const PvlKeyword &keyword);
145  virtual QString formatEnd(const QString name,
146  const PvlKeyword &keyword);
147  virtual QString formatEOL() {
148  return "\n";
149  }
150 
151  virtual KeywordType type(const PvlKeyword &keyword);
152  virtual int accuracy(const PvlKeyword &keyword);
153 
154  protected:
155 
156  virtual QString addQuotes(const QString value);
157  bool isSingleUnit(const PvlKeyword &keyword);
158 
159  QString m_keywordMapFile;
160  Pvl m_keywordMap;
161 
163  unsigned int m_charLimit;
164 
165  private:
166  void init();
167  };
168 };
169 
170 #endif
171 
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::PvlFormat
Formats a Pvl name value pair to Isis standards.
Definition: PvlFormat.h:108
Isis::PvlFormat::m_charLimit
unsigned int m_charLimit
Maximum number of characters on a single line of a keyword value.
Definition: PvlFormat.h:163
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::KeywordType
KeywordType
The different types of keywords that can be formatted.
Definition: PvlFormat.h:19
Isis::toKeywordType
KeywordType toKeywordType(const QString type)
Convert a string representing a type of keyword to the corresponding enumeration.
Definition: PvlFormat.h:38
Isis::PvlFormat::setCharLimit
void setCharLimit(const unsigned int limit)
Sets the maximum number of characters in a keyword value that can be printed to a line before it wrap...
Definition: PvlFormat.h:127
Isis::PvlFormat::init
void init()
Clears all PvlFormat data.
Definition: PvlFormat.cpp:56
Isis::PvlFormat::isSingleUnit
bool isSingleUnit(const PvlKeyword &keyword)
Returns true if the units are the same for all value in the keyword otherwise it returns false.
Definition: PvlFormat.cpp:307
Isis::PvlFormat::charLimit
unsigned int charLimit() const
Retrieves the maximum number of characters in a keyword value that can be printed to a line before it...
Definition: PvlFormat.h:138
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16