USGS

Isis 3.0 Object Programmers' Reference

Home

PvlObject.h

Go to the documentation of this file.
00001 #ifndef PvlObject_h
00002 #define PvlObject_h
00003 
00025 #include <algorithm>
00026 #include "PvlContainer.h"
00027 #include "PvlGroup.h"
00028 
00029 
00030 template<typename T> class QList;
00031 
00032 namespace Isis {
00067   class PvlObject : public Isis::PvlContainer {
00068     public:
00069       PvlObject();
00070       PvlObject(const QString &name);
00071       PvlObject(const PvlObject &other);
00072 
00073       friend std::ostream &operator<<(std::ostream &os, Isis::PvlObject &object);
00074       friend std::istream &operator>>(std::istream &is, PvlObject &result);
00075 
00080       int Groups() const {
00081         return p_groups.size();
00082       };
00083 
00084       PvlGroup &Group(const int index);
00085       const PvlGroup &Group(const int index) const;
00086 
00088       typedef QList<Isis::PvlGroup>::iterator PvlGroupIterator;
00089       typedef QList<Isis::PvlGroup>::const_iterator ConstPvlGroupIterator;
00090 
00091 
00096       PvlGroupIterator BeginGroup() {
00097         return p_groups.begin();
00098       };
00099 
00100 
00105       ConstPvlGroupIterator BeginGroup() const {
00106         return p_groups.begin();
00107       };
00108 
00109 
00114       PvlGroupIterator EndGroup() {
00115         return p_groups.end();
00116       };
00117 
00118 
00123       ConstPvlGroupIterator EndGroup() const {
00124         return p_groups.end();
00125       };
00126 
00127 
00134       PvlGroupIterator FindGroup(const QString &name,
00135                                  PvlGroupIterator beg,
00136                                  PvlGroupIterator end) {
00137         Isis::PvlGroup temp(name);
00138         return std::find(beg, end, temp);
00139       }
00140 
00141 
00148       ConstPvlGroupIterator FindGroup(const QString &name,
00149                                       ConstPvlGroupIterator beg,
00150                                       ConstPvlGroupIterator end) const {
00151         Isis::PvlGroup temp(name);
00152         return std::find(beg, end, temp);
00153       }
00154 
00155 
00159       enum FindOptions {
00161         None,
00163         Traverse
00164       };
00165 
00166       // The using statements below are used to make the PvlContainer's version
00167       // of FindKeyword and HasKeyword vissible to other code that otherwise would not be
00168       // able to see those versions.
00169       using PvlContainer::FindKeyword;
00170 
00171 
00172       PvlKeyword &FindKeyword(const QString &kname,
00173                               FindOptions opts);
00174 
00175 
00176       using PvlContainer::HasKeyword;
00177 
00178 
00179       bool HasKeyword(const QString &kname,
00180                       FindOptions opts) const;
00181 
00182       Isis::PvlGroup &FindGroup(const QString &name,
00183                                 FindOptions opts = None);
00184 
00185       const Isis::PvlGroup &FindGroup(const QString &name,
00186                                       FindOptions opts = None) const;
00191       void AddGroup(const Isis::PvlGroup &group) {
00192         p_groups.push_back(group);
00193         //p_groups[p_groups.size()-1].SetFileName(FileName());
00194       };
00195 
00196       using PvlContainer::operator+=;
00197       void operator+= (const Isis::PvlGroup &group) {
00198         AddGroup(group);
00199       }
00200       void operator+= (const Isis::PvlObject &obj) {
00201         AddObject(obj);
00202       }
00203 
00204       void DeleteGroup(const QString &name);
00205 
00206       void DeleteGroup(const int index);
00207 
00208 
00215       bool HasGroup(const QString &name) const {
00216         if(FindGroup(name, BeginGroup(), EndGroup()) == EndGroup()) return false;
00217         return true;
00218       }
00219 
00224       int Objects() const {
00225         return p_objects.size();
00226       };
00227 
00228       PvlObject &Object(const int index);
00229       const PvlObject &Object(const int index) const;
00230 
00232       typedef QList<PvlObject>::iterator PvlObjectIterator;
00233       typedef QList<PvlObject>::const_iterator ConstPvlObjectIterator;
00234 
00235 
00240       PvlObjectIterator BeginObject() {
00241         return p_objects.begin();
00242       };
00243 
00244 
00249       ConstPvlObjectIterator BeginObject() const {
00250         return p_objects.begin();
00251       };
00252 
00253 
00258       PvlObjectIterator EndObject() {
00259         return p_objects.end();
00260       };
00261 
00262 
00267       ConstPvlObjectIterator EndObject() const {
00268         return p_objects.end();
00269       };
00270 
00271 
00279       PvlObjectIterator FindObject(const QString &name,
00280                                    PvlObjectIterator beg,
00281                                    PvlObjectIterator end) {
00282         PvlObject temp(name);
00283         return std::find(beg, end, temp);
00284       }
00285 
00286 
00294       ConstPvlObjectIterator FindObject(const QString &name,
00295                                         ConstPvlObjectIterator beg,
00296                                         ConstPvlObjectIterator end) const {
00297         PvlObject temp(name);
00298         return std::find(beg, end, temp);
00299       }
00300 
00301 
00302       PvlObject &FindObject(const QString &name,
00303                             FindOptions opts = None);
00304 
00305       const PvlObject &FindObject(const QString &name,
00306                                   FindOptions opts = None) const;
00307 
00312       void AddObject(const PvlObject &object) {
00313         p_objects.push_back(object);
00314         p_objects[p_objects.size()-1].SetFileName(FileName());
00315       }
00316 
00317       void DeleteObject(const QString &name);
00318       void DeleteObject(const int index);
00319 
00320 
00328       bool HasObject(const QString &name) const {
00329         if(FindObject(name, BeginObject(), EndObject()) == EndObject()) return false;
00330         return true;
00331       }
00332 
00333 
00340       bool operator==(const PvlObject &object) const {
00341         return PvlKeyword::StringEqual(object.Name(), this->Name());
00342       }
00343 
00344 
00346       void Clear() {
00347         Isis::PvlContainer::Clear();
00348         p_objects.clear();
00349         p_groups.clear();
00350       }
00351 
00352       const PvlObject &operator=(const PvlObject &other);
00353       
00355       void ValidateObject(PvlObject & pPvlObj);
00356       
00357     private:
00358       QList<PvlObject> p_objects;    
00360       QList<PvlGroup> p_groups;
00362   };
00363 }
00364 
00365 #endif