Isis 3 Programmer Reference
PvlObject.h
1 #ifndef PvlObject_h
2 #define PvlObject_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 #include <algorithm>
10 
11 #include "PvlContainer.h"
12 #include "PvlGroup.h"
13 
14 #include <QMetaType>
15 
16 #include <nlohmann/json.hpp>
17 
18 
19 template<typename T> class QList;
20 
21 namespace Isis {
61  class PvlObject : public Isis::PvlContainer {
62  public:
63  PvlObject();
64  PvlObject(const QString &name);
65  PvlObject(const PvlObject &other);
66  PvlObject(const QString &name, const nlohmann::json &jsonobj);
67 
68  friend std::ostream &operator<<(std::ostream &os, Isis::PvlObject &object);
69  friend std::istream &operator>>(std::istream &is, PvlObject &result);
70 
75  int groups() const {
76  return m_groups.size();
77  };
78 
79  PvlGroup &group(const int index);
80  const PvlGroup &group(const int index) const;
81 
84  typedef QList<Isis::PvlGroup>::const_iterator ConstPvlGroupIterator;
85 
86 
92  return m_groups.begin();
93  };
94 
95 
100  ConstPvlGroupIterator beginGroup() const {
101  return m_groups.begin();
102  };
103 
104 
110  return m_groups.end();
111  };
112 
113 
118  ConstPvlGroupIterator endGroup() const {
119  return m_groups.end();
120  };
121 
122 
130  PvlGroupIterator beg,
132  Isis::PvlGroup temp(name);
133  return std::find(beg, end, temp);
134  }
135 
136 
143  ConstPvlGroupIterator findGroup(const QString &name,
144  ConstPvlGroupIterator beg,
145  ConstPvlGroupIterator end) const {
146  Isis::PvlGroup temp(name);
147  return std::find(beg, end, temp);
148  }
149 
150 
154  enum FindOptions {
158  Traverse
159  };
160 
161  // The using statements below are used to make the PvlContainer's version
162  // of FindKeyword and HasKeyword visible to other code that otherwise would not be
163  // able to see those versions.
165 
166 
167  PvlKeyword &findKeyword(const QString &kname,
168  FindOptions opts);
169 
170 
172 
173 
174  bool hasKeyword(const QString &kname,
175  FindOptions opts) const;
176 
177  Isis::PvlGroup &findGroup(const QString &name,
178  FindOptions opts = None);
179 
180  const Isis::PvlGroup &findGroup(const QString &name,
181  FindOptions opts = None) const;
187  m_groups.push_back(group);
188  //m_groups[m_groups.size()-1].SetFileName(FileName());
189  };
190 
191  using PvlContainer::operator+=;
192  void operator+= (const Isis::PvlGroup &group) {
193  addGroup(group);
194  }
195  void operator+= (const Isis::PvlObject &obj) {
196  addObject(obj);
197  }
198 
199  void deleteGroup(const QString &name);
200 
201  void deleteGroup(const int index);
202 
203 
210  bool hasGroup(const QString &name) const {
211  if(findGroup(name, beginGroup(), endGroup()) == endGroup()) return false;
212  return true;
213  }
214 
219  int objects() const {
220  return m_objects.size();
221  };
222 
223  PvlObject &object(const int index);
224  const PvlObject &object(const int index) const;
225 
228  typedef QList<PvlObject>::const_iterator ConstPvlObjectIterator;
229 
230 
236  return m_objects.begin();
237  };
238 
239 
244  ConstPvlObjectIterator beginObject() const {
245  return m_objects.begin();
246  };
247 
248 
254  return m_objects.end();
255  };
256 
257 
262  ConstPvlObjectIterator endObject() const {
263  return m_objects.end();
264  };
265 
266 
275  PvlObjectIterator beg,
277  PvlObject temp(name);
278  return std::find(beg, end, temp);
279  }
280 
281 
289  ConstPvlObjectIterator findObject(const QString &name,
290  ConstPvlObjectIterator beg,
291  ConstPvlObjectIterator end) const {
292  PvlObject temp(name);
293  return std::find(beg, end, temp);
294  }
295 
296 
297  PvlObject &findObject(const QString &name,
298  FindOptions opts = None);
299 
300  const PvlObject &findObject(const QString &name,
301  FindOptions opts = None) const;
302 
307  void addObject(const PvlObject &object) {
308  m_objects.push_back(object);
309  m_objects[m_objects.size()-1].setFileName(fileName());
310  }
311 
312  void deleteObject(const QString &name);
313  void deleteObject(const int index);
314 
315 
323  bool hasObject(const QString &name) const {
324  if(findObject(name, beginObject(), endObject()) == endObject()) return false;
325  return true;
326  }
327 
328 
335  bool operator==(const PvlObject &object) const {
336  return PvlKeyword::stringEqual(object.name(), this->name());
337  }
338 
339 
341  void clear() {
343  m_objects.clear();
344  m_groups.clear();
345  }
346 
347  const PvlObject &operator=(const PvlObject &other);
348 
350  void validateObject(PvlObject & pPvlObj);
351 
352  private:
357  };
358 }
359 
361 
362 #endif
Isis::PvlObject::clear
void clear()
Remove everything from the current PvlObject.
Definition: PvlObject.h:341
Isis::PvlObject::endGroup
PvlGroupIterator endGroup()
Returns the ending group index.
Definition: PvlObject.h:109
Isis::PvlObject::FindOptions
FindOptions
A collection of options to use when finding.
Definition: PvlObject.h:154
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::PvlObject::group
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:452
Isis::PvlContainer::clear
void clear()
Clears PvlKeywords.
Definition: PvlContainer.h:91
Isis::PvlObject::PvlGroupIterator
QList< Isis::PvlGroup >::iterator PvlGroupIterator
The counter for groups.
Definition: PvlObject.h:83
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::PvlObject::endObject
ConstPvlObjectIterator endObject() const
Returns the const index of the ending object.
Definition: PvlObject.h:262
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::PvlObject::beginObject
PvlObjectIterator beginObject()
Returns the index of the beginning object.
Definition: PvlObject.h:235
Isis::PvlObject::groups
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:75
Isis::PvlObject::endObject
PvlObjectIterator endObject()
Returns the index of the ending object.
Definition: PvlObject.h:253
Isis::PvlObject::hasGroup
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
Definition: PvlObject.h:210
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::PvlObject::objects
int objects() const
Returns the number of objects.
Definition: PvlObject.h:219
Isis::PvlObject::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::PvlObject::addObject
void addObject(const PvlObject &object)
Add a PvlObject.
Definition: PvlObject.h:307
Isis::PvlObject::object
PvlObject & object(const int index)
Return the object at the specified index.
Definition: PvlObject.cpp:489
Isis::PvlObject::operator==
bool operator==(const PvlObject &object) const
Compares two PvlObjects.
Definition: PvlObject.h:335
Isis::PvlObject::operator<<
friend std::ostream & operator<<(std::ostream &os, Isis::PvlObject &object)
Outputs the PvlObject data to a specified output stream.
Definition: PvlObject.cpp:523
Isis::PvlObject::Traverse
@ Traverse
Search child objects.
Definition: PvlObject.h:158
Isis::PvlObject::operator+=
void operator+=(const PvlKeyword &keyword)
When you use the += operator with a PvlKeyword, it will call the addKeyword() method.
Definition: PvlContainer.h:110
Isis::PvlObject::PvlObjectIterator
QList< PvlObject >::iterator PvlObjectIterator
The counter for objects.
Definition: PvlObject.h:227
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::PvlObject::findKeyword
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
Definition: PvlContainer.cpp:62
Isis::PvlObject::findGroup
ConstPvlGroupIterator findGroup(const QString &name, ConstPvlGroupIterator beg, ConstPvlGroupIterator end) const
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:143
Isis::PvlObject::operator=
const PvlObject & operator=(const PvlObject &other)
This is an assignment operator.
Definition: PvlObject.cpp:821
Isis::PvlObject::findObject
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:274
Isis::PvlObject::endGroup
ConstPvlGroupIterator endGroup() const
Returns the const ending group index.
Definition: PvlObject.h:118
Isis::PvlContainer::fileName
QString fileName() const
Returns the filename used to initialise the Pvl object.
Definition: PvlContainer.h:232
Isis::PvlContainer::name
QString name() const
Returns the container name.
Definition: PvlContainer.h:63
Isis::PvlObject::PvlObject
PvlObject()
Creates a blank PvlObject.
Definition: PvlObject.cpp:26
Isis::PvlObject::m_groups
QList< PvlGroup > m_groups
A vector of PvlGroups contained in the current PvlObject.
Definition: PvlObject.h:355
Isis::PvlObject::validateObject
void validateObject(PvlObject &pPvlObj)
Validate Object.
Definition: PvlObject.cpp:841
Isis::PvlObject::hasObject
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:323
Isis::PvlObject::None
@ None
Search only the current level.
Definition: PvlObject.h:156
Isis::PvlObject::addGroup
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:186
Isis::PvlObject::deleteObject
void deleteObject(const QString &name)
Remove an object from the current PvlObject.
Definition: PvlObject.cpp:366
Isis::PvlObject::beginGroup
PvlGroupIterator beginGroup()
Returns the beginning group index.
Definition: PvlObject.h:91
Isis::PvlObject::beginObject
ConstPvlObjectIterator beginObject() const
Returns the const index of the beginning object.
Definition: PvlObject.h:244
Isis::PvlObject::findObject
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:289
Isis::PvlContainer::findKeyword
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
Definition: PvlContainer.cpp:62
Isis::PvlContainer::end
PvlKeywordIterator end()
Return the ending iterator.
Definition: PvlContainer.h:194
Isis::PvlObject::operator>>
friend std::istream & operator>>(std::istream &is, PvlObject &result)
This method reads a PvlObject from the input stream.
Definition: PvlObject.cpp:705
Isis::PvlContainer
Contains more than one keyword-value pair.
Definition: PvlContainer.h:49
Isis::PvlObject::deleteGroup
void deleteGroup(const QString &name)
Remove a group from the current PvlObject.
Definition: PvlObject.cpp:408
Isis::PvlKeyword::stringEqual
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
Definition: PvlKeyword.cpp:535
Isis::PvlObject::m_objects
QList< PvlObject > m_objects
A vector of PvlObjects contained in the current PvlObject.
Definition: PvlObject.h:353
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(Isis::PlotWindow *)
We have plot windows as QVariant data types, so here it's enabled.
Isis::PvlObject::beginGroup
ConstPvlGroupIterator beginGroup() const
Returns the beginning group index.
Definition: PvlObject.h:100