USGS

Isis 3.0 Developer's Reference (API)

Home

PvlContainer.h

Go to the documentation of this file.
00001 #ifndef PvlContainer_h
00002 #define PvlContainer_h
00003 
00025 #include "PvlKeyword.h"
00026 
00027 template<typename T> class QList;
00028 
00029 namespace Isis {
00063   class PvlContainer {
00064     public:
00065       PvlContainer(const QString &type);
00066       PvlContainer(const QString &type, const QString &name);
00067       PvlContainer(const PvlContainer &other);
00068 
00070       void SetName(const QString &name) {
00071         p_name.SetValue(name);
00072       };
00077       inline QString Name() const {
00078         return (QString) p_name;
00079       };
00086       bool IsNamed(const QString &match) const {
00087         return PvlKeyword::StringEqual(match, (QString)p_name);
00088       }
00093       inline QString Type() const {
00094         return p_name.Name();
00095       };
00100       inline int Keywords() const {
00101         return p_keywords.size();
00102       };
00103 
00105       void Clear() {
00106         p_keywords.clear();
00107       };
00109       enum InsertMode { Append, Replace };
00115       void AddKeyword(const PvlKeyword &keyword,
00116                       const InsertMode mode = Append);
00117 
00118 
00124       void operator+= (const PvlKeyword &keyword) {
00125         AddKeyword(keyword);
00126       };
00127 
00128       PvlKeyword &FindKeyword(const QString &name);
00134       PvlKeyword &operator[](const QString &name) {
00135         return FindKeyword(name);
00136       };
00137       PvlKeyword &operator[](const int index);
00138 
00144       PvlKeyword &operator[](const char *name) {
00145         return operator[](QString(name));
00146       };
00147 
00148       const PvlKeyword &FindKeyword(const QString &name) const;
00155       const PvlKeyword &operator[](const QString &name) const {
00156         return FindKeyword(name);
00157       };
00158       const PvlKeyword &operator[](const int index) const;
00159 
00165       PvlKeyword operator[](const char *name) const {
00166         return operator[](QString(name));
00167       };
00168 
00169       bool HasKeyword(const QString &name) const;
00171       typedef QList<PvlKeyword>::iterator PvlKeywordIterator;
00172 
00174       typedef QList<PvlKeyword>::const_iterator ConstPvlKeywordIterator;
00175 
00176 
00177       PvlKeywordIterator FindKeyword(const QString &name,
00178                                      PvlKeywordIterator beg,
00179                                      PvlKeywordIterator end);
00180 
00181       ConstPvlKeywordIterator FindKeyword(const QString &name,
00182                                           ConstPvlKeywordIterator beg,
00183                                           ConstPvlKeywordIterator end) const;
00184 
00185       PvlKeywordIterator AddKeyword(const PvlKeyword &keyword,
00186                                     PvlKeywordIterator pos);
00187 
00192       PvlKeywordIterator Begin() {
00193         return p_keywords.begin();
00194       };
00195 
00200       ConstPvlKeywordIterator Begin() const {
00201         return p_keywords.begin();
00202       };
00203 
00208       PvlKeywordIterator End() {
00209         return p_keywords.end();
00210       };
00211 
00216       ConstPvlKeywordIterator End() const {
00217         return p_keywords.end();
00218       };
00219 
00220       void DeleteKeyword(const QString &name);
00221       void DeleteKeyword(const int index);
00222 
00223       bool CleanDuplicateKeywords();
00224 
00230       void operator-= (const QString &name) {
00231         DeleteKeyword(name);
00232       };
00238       void operator-= (const PvlKeyword &key) {
00239         DeleteKeyword(key.Name());
00240       };
00246       QString FileName() const {
00247         return p_filename;
00248       };
00249 
00250       void SetFormatTemplate(PvlContainer &ref) {
00251         p_formatTemplate = &ref;
00252       };
00253 
00254       bool HasFormatTemplate() {
00255         return p_formatTemplate != NULL;
00256       };
00257 
00258       PvlContainer *FormatTemplate() {
00259         return p_formatTemplate;
00260       };
00261 
00262       PvlFormat *GetFormat() {
00263         return p_name.GetFormat();
00264       }
00265       void SetFormat(PvlFormat *format) {
00266         p_name.SetFormat(format);
00267       }
00268 
00269       int Indent() {
00270         return p_name.Indent();
00271       }
00272       void SetIndent(int indent) {
00273         p_name.SetIndent(indent);
00274       }
00275 
00276       inline int Comments() const {
00277         return p_name.Comments();
00278       };
00279       QString Comment(const int index) const {
00280         return p_name.Comment(index);
00281       }
00282 
00283       void AddComment(const QString &comment) {
00284         p_name.AddComment(comment);
00285       }
00286 
00287       PvlKeyword &GetNameKeyword() {
00288         return p_name;
00289       }
00290       const PvlKeyword &GetNameKeyword() const {
00291         return p_name;
00292       }
00293 
00294       const PvlContainer &operator=(const PvlContainer &other);
00295 
00296     protected:
00297       QString p_filename;                   
00303       PvlKeyword p_name;                   
00304       QList<PvlKeyword> p_keywords; 
00308       void Init();
00309 
00315       void SetFileName(const QString &filename) {
00316         p_filename = filename;
00317       }
00318 
00319       PvlContainer *p_formatTemplate;
00320       
00322       void ValidateAllKeywords(PvlContainer &pPvlCont);
00323       
00325       void ValidateRepeatOption(PvlKeyword & pPvlTmplKwrd, PvlContainer & pPvlCont);
00326   };
00327 
00328   std::ostream &operator<<(std::ostream &os, PvlContainer &container);
00329 };
00330 
00331 #endif