Isis 3 Programmer Reference
PvlObject.h
Go to the documentation of this file.
1 #ifndef PvlObject_h
2 #define PvlObject_h
3 
25 #include <algorithm>
26 
27 #include "PvlContainer.h"
28 #include "PvlGroup.h"
29 
30 #include <QMetaType>
31 
32 template<typename T> class QList;
33 
34 namespace Isis {
74  class PvlObject : public Isis::PvlContainer {
75  public:
76  PvlObject();
77  PvlObject(const QString &name);
78  PvlObject(const PvlObject &other);
79 
80  friend std::ostream &operator<<(std::ostream &os, Isis::PvlObject &object);
81  friend std::istream &operator>>(std::istream &is, PvlObject &result);
82 
87  int groups() const {
88  return m_groups.size();
89  };
90 
91  PvlGroup &group(const int index);
92  const PvlGroup &group(const int index) const;
93 
96  typedef QList<Isis::PvlGroup>::const_iterator ConstPvlGroupIterator;
97 
98 
104  return m_groups.begin();
105  };
106 
107 
112  ConstPvlGroupIterator beginGroup() const {
113  return m_groups.begin();
114  };
115 
116 
122  return m_groups.end();
123  };
124 
125 
130  ConstPvlGroupIterator endGroup() const {
131  return m_groups.end();
132  };
133 
134 
142  PvlGroupIterator beg,
144  Isis::PvlGroup temp(name);
145  return std::find(beg, end, temp);
146  }
147 
148 
155  ConstPvlGroupIterator findGroup(const QString &name,
156  ConstPvlGroupIterator beg,
157  ConstPvlGroupIterator end) const {
158  Isis::PvlGroup temp(name);
159  return std::find(beg, end, temp);
160  }
161 
162 
166  enum FindOptions {
171  };
172 
173  // The using statements below are used to make the PvlContainer's version
174  // of FindKeyword and HasKeyword visible to other code that otherwise would not be
175  // able to see those versions.
177 
178 
179  PvlKeyword &findKeyword(const QString &kname,
180  FindOptions opts);
181 
182 
184 
185 
186  bool hasKeyword(const QString &kname,
187  FindOptions opts) const;
188 
189  Isis::PvlGroup &findGroup(const QString &name,
190  FindOptions opts = None);
191 
192  const Isis::PvlGroup &findGroup(const QString &name,
193  FindOptions opts = None) const;
199  m_groups.push_back(group);
200  //m_groups[m_groups.size()-1].SetFileName(FileName());
201  };
202 
203  using PvlContainer::operator+=;
204  void operator+= (const Isis::PvlGroup &group) {
205  addGroup(group);
206  }
207  void operator+= (const Isis::PvlObject &obj) {
208  addObject(obj);
209  }
210 
211  void deleteGroup(const QString &name);
212 
213  void deleteGroup(const int index);
214 
215 
222  bool hasGroup(const QString &name) const {
223  if(findGroup(name, beginGroup(), endGroup()) == endGroup()) return false;
224  return true;
225  }
226 
231  int objects() const {
232  return m_objects.size();
233  };
234 
235  PvlObject &object(const int index);
236  const PvlObject &object(const int index) const;
237 
240  typedef QList<PvlObject>::const_iterator ConstPvlObjectIterator;
241 
242 
248  return m_objects.begin();
249  };
250 
251 
256  ConstPvlObjectIterator beginObject() const {
257  return m_objects.begin();
258  };
259 
260 
266  return m_objects.end();
267  };
268 
269 
274  ConstPvlObjectIterator endObject() const {
275  return m_objects.end();
276  };
277 
278 
287  PvlObjectIterator beg,
289  PvlObject temp(name);
290  return std::find(beg, end, temp);
291  }
292 
293 
301  ConstPvlObjectIterator findObject(const QString &name,
302  ConstPvlObjectIterator beg,
303  ConstPvlObjectIterator end) const {
304  PvlObject temp(name);
305  return std::find(beg, end, temp);
306  }
307 
308 
309  PvlObject &findObject(const QString &name,
310  FindOptions opts = None);
311 
312  const PvlObject &findObject(const QString &name,
313  FindOptions opts = None) const;
314 
319  void addObject(const PvlObject &object) {
320  m_objects.push_back(object);
321  m_objects[m_objects.size()-1].setFileName(fileName());
322  }
323 
324  void deleteObject(const QString &name);
325  void deleteObject(const int index);
326 
327 
335  bool hasObject(const QString &name) const {
336  if(findObject(name, beginObject(), endObject()) == endObject()) return false;
337  return true;
338  }
339 
340 
347  bool operator==(const PvlObject &object) const {
348  return PvlKeyword::stringEqual(object.name(), this->name());
349  }
350 
351 
353  void clear() {
355  m_objects.clear();
356  m_groups.clear();
357  }
358 
359  const PvlObject &operator=(const PvlObject &other);
360 
362  void validateObject(PvlObject & pPvlObj);
363 
364  private:
369  };
370 }
371 
373 
374 #endif
PvlObject & object(const int index)
Return the object at the specified index.
Definition: PvlObject.cpp:460
FindOptions
A collection of options to use when finding.
Definition: PvlObject.h:166
PvlKeywordIterator end()
Return the ending iterator.
Definition: PvlContainer.h:208
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
const PvlObject & operator=(const PvlObject &other)
This is an assignment operator.
Definition: PvlObject.cpp:792
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
PvlObjectIterator endObject()
Returns the index of the ending object.
Definition: PvlObject.h:265
Contains more than one keyword-value pair.
Definition: PvlContainer.h:63
void clear()
Remove everything from the current PvlObject.
Definition: PvlObject.h:353
ConstPvlObjectIterator beginObject() const
Returns the const index of the beginning object.
Definition: PvlObject.h:256
int objects() const
Returns the number of objects.
Definition: PvlObject.h:231
PvlGroupIterator endGroup()
Returns the ending group index.
Definition: PvlObject.h:121
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:286
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:198
Search child objects.
Definition: PvlObject.h:170
Q_DECLARE_METATYPE(Isis::Cube *)
This allows Cube *&#39;s to be stored in a QVariant.
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
Definition: PvlObject.h:222
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
Definition: PvlKeyword.cpp:551
void validateObject(PvlObject &pPvlObj)
Validate Object.
Definition: PvlObject.cpp:812
QList< PvlGroup > m_groups
A vector of PvlGroups contained in the current PvlObject.
Definition: PvlObject.h:367
void deleteGroup(const QString &name)
Remove a group from the current PvlObject.
Definition: PvlObject.cpp:379
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
Definition: PvlObject.cpp:207
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not...
Definition: PvlObject.h:335
void addObject(const PvlObject &object)
Add a PvlObject.
Definition: PvlObject.h:319
ConstPvlObjectIterator findObject(const QString &name, ConstPvlObjectIterator beg, ConstPvlObjectIterator end) const
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:301
QString name() const
Returns the container name.
Definition: PvlContainer.h:77
QList< PvlObject > m_objects
A vector of PvlObjects contained in the current PvlObject.
Definition: PvlObject.h:365
QList< PvlObject >::iterator PvlObjectIterator
The counter for objects.
Definition: PvlObject.h:239
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
Definition: PvlObject.cpp:148
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
Search only the current level.
Definition: PvlObject.h:168
ConstPvlObjectIterator endObject() const
Returns the const index of the ending object.
Definition: PvlObject.h:274
A single keyword-value pair.
Definition: PvlKeyword.h:98
ConstPvlGroupIterator endGroup() const
Returns the const ending group index.
Definition: PvlObject.h:130
friend std::istream & operator>>(std::istream &is, PvlObject &result)
This method reads a PvlObject from the input stream.
Definition: PvlObject.cpp:676
void deleteObject(const QString &name)
Remove an object from the current PvlObject.
Definition: PvlObject.cpp:337
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:423
QList< Isis::PvlGroup >::iterator PvlGroupIterator
The counter for groups.
Definition: PvlObject.h:95
QString fileName() const
Returns the filename used to initialise the Pvl object.
Definition: PvlContainer.h:246
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:87
ConstPvlGroupIterator findGroup(const QString &name, ConstPvlGroupIterator beg, ConstPvlGroupIterator end) const
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:155
bool operator==(const PvlObject &object) const
Compares two PvlObjects.
Definition: PvlObject.h:347
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
PvlObjectIterator beginObject()
Returns the index of the beginning object.
Definition: PvlObject.h:247
friend std::ostream & operator<<(std::ostream &os, Isis::PvlObject &object)
Outputs the PvlObject data to a specified output stream.
Definition: PvlObject.cpp:494
void clear()
Clears PvlKeywords.
Definition: PvlContainer.h:105
PvlObject()
Creates a blank PvlObject.
Definition: PvlObject.cpp:40
ConstPvlGroupIterator beginGroup() const
Returns the beginning group index.
Definition: PvlObject.h:112
PvlGroupIterator beginGroup()
Returns the beginning group index.
Definition: PvlObject.h:103