USGS

Isis 3.0 Developer's Reference (API)

Home

PvlKeyword.h

Go to the documentation of this file.
00001 #ifndef PvlKeyword_h
00002 #define PvlKeyword_h
00003 
00025 #include <vector>
00026 #include <map>
00027 #include <iostream>
00028 
00029 #include <QVariant>
00030 #include <QVarLengthArray>
00031 
00032 #include "iString.h"
00033 #include "Constants.h"
00034 
00035 namespace Isis {
00036   class PvlSequence;
00037   class PvlFormat;
00038 
00094   class PvlKeyword {
00095     public:
00096       PvlKeyword();
00097       PvlKeyword(const std::string &name);
00098       PvlKeyword(const std::string &name, const Isis::iString value,
00099                  const std::string unit = "");
00100       PvlKeyword(const PvlKeyword &other);
00101       ~PvlKeyword();
00102 
00103       void SetName(const std::string &name);
00104 
00110       std::string Name() const {
00111         if(p_name)
00112           return p_name;
00113         else
00114           return "";
00115       };
00122       bool IsNamed(const std::string &name) const {
00123         return StringEqual(name, Name());
00124       };
00125 
00126       void SetValue(const Isis::iString value, const std::string unit = "");
00127 
00128       void SetUnits(const iString &units);
00129       void SetUnits(const iString &value, const iString &units);
00130 
00131       PvlKeyword &operator=(const Isis::iString value);
00132 
00133       void AddValue(const Isis::iString value, const std::string unit = "");
00134       PvlKeyword &operator+=(const Isis::iString value);
00135 
00137       int Size() const {
00138         return p_values.size();
00139       };
00140       bool IsNull(const int index = 0) const;
00141       void Clear();
00142 
00143       friend std::istream &operator>>(std::istream &is, PvlKeyword &result);
00144       friend std::ostream &operator<<(std::ostream &os,
00145                                       const PvlKeyword &keyword);
00146 
00148       operator double() const {
00149         return (double) operator[](0);
00150       };
00152       operator int() const {
00153         return (int) operator[](0);
00154       };
00156       operator Isis::BigInt() const {
00157         return (Isis::BigInt) operator[](0);
00158       };
00160       operator std::string() const {
00161         return (std::string) operator[](0);
00162       };
00163 
00164       operator QString() const;
00165 
00166       const Isis::iString &operator[](const int index) const;
00167       Isis::iString &operator[](const int index);
00168       std::string Unit(const int index = 0) const;
00169 
00170       void AddComment(const std::string &comment);
00171       void AddCommentWrapped(const std::string &comment);
00172 
00173       void AddComments(const std::vector<std::string> &comments);
00174 
00176       int Comments() const {
00177         return (p_comments ? p_comments->size() : 0);
00178       };
00179       std::string Comment(const int index) const;
00180       void ClearComments();
00181 
00187       bool operator==(const PvlKeyword &key) const {
00188         if(!p_name && !key.p_name) return true;
00189         if(!p_name || !key.p_name) return false;
00190 
00191         return (StringEqual(p_name, key.p_name));
00192       };
00193 
00199       bool operator!=(const PvlKeyword &key) const {
00200         return !(*this == key);
00201       };
00202 
00203       bool IsEquivalent(const std::string &string1, int index = 0) const;
00204 
00210       void SetWidth(int width) {
00211         p_width = width;
00212       };
00213 
00219       void SetIndent(int indent) {
00220         p_indent = indent;
00221       };
00222 
00224       int Width() const {
00225         return p_width;
00226       };
00227 
00229       int Indent() const {
00230         return p_indent;
00231       };
00232 
00233       PvlKeyword &operator=(Isis::PvlSequence &seq);
00234 
00235       void SetFormat(PvlFormat *formatter);
00236       PvlFormat *GetFormat();
00237 
00238       static bool StringEqual(const std::string &string1,
00239                               const std::string &string2);
00240 
00241 
00242       static std::string ReadLine(std::istream &is, bool insideComment);
00243 
00244       static bool ReadCleanKeyword(std::string keyword,
00245                                    std::vector< std::string > &keywordComments,
00246                                    std::string &keywordName,
00247                                    std::vector< std::pair<std::string, std::string> >
00248                                    &keywordValues);
00249 
00250       static std::string ReadValue(std::string &keyword, bool &quoteProblem);
00251       static std::string ReadValue(std::string &keyword, bool &quoteProblem,
00252                                    const std::vector< std::pair<char, char> > &
00253                                    otherDelimiters);
00254 
00255       const PvlKeyword &operator=(const PvlKeyword &other);
00256 
00258       void ValidateKeyword(PvlKeyword & pvlKwrd, std::string psValueType="", PvlKeyword* pvlKwrdRange=NULL);
00259 
00260     protected:
00261       std::string Reform(const std::string &value) const;
00262       std::string ToPvl(const std::string &value) const;
00263       std::string ToIPvl(const std::string &value) const;
00264       std::ostream &WriteWithWrap(std::ostream &os,
00265                                   const std::string &textToWrite,
00266                                   int startColumn,
00267                                   PvlFormat &format) const;
00268 
00270       PvlFormat *p_formatter;
00271 
00272     private:
00274       char * p_name;
00275 
00284       QVarLengthArray<Isis::iString, 1> p_values;
00285 
00287       std::vector<std::string> *p_units;
00288 
00290       std::vector<std::string> *p_comments;
00291 
00292       void Init();
00293 
00294       void WriteSpaces(std::ostream &, int) const;
00295 
00300       int p_width;
00305       int p_indent;
00306   };
00307 };
00308 
00309 #endif
00310