Isis 3 Programmer Reference
PvlObject.h
1#ifndef PvlObject_h
2#define PvlObject_h
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
19template<typename T> class QList;
20
21namespace Isis {
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
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
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
192
193 using PvlContainer::operator+=;
194 void operator+= (const Isis::PvlGroup &group) {
196 }
197 void operator+= (const Isis::PvlObject &obj) {
198 addObject(obj);
199 }
200
201 void deleteGroup(const QString &name);
202
203 void deleteGroup(const int index);
204
205
212 bool hasGroup(const QString &name) const {
213 if(findGroup(name, beginGroup(), endGroup()) == endGroup()) return false;
214 return true;
215 }
216
221 int objects() const {
222 return m_objects.size();
223 };
224
225 PvlObject &object(const int index);
226 const PvlObject &object(const int index) const;
227
230 typedef QList<PvlObject>::const_iterator ConstPvlObjectIterator;
231
232
238 return m_objects.begin();
239 };
240
241
246 ConstPvlObjectIterator beginObject() const {
247 return m_objects.begin();
248 };
249
250
256 return m_objects.end();
257 };
258
259
264 ConstPvlObjectIterator endObject() const {
265 return m_objects.end();
266 };
267
268
279 PvlObject temp(name);
280 return std::find(beg, end, temp);
281 }
282
283
291 ConstPvlObjectIterator findObject(const QString &name,
292 ConstPvlObjectIterator beg,
293 ConstPvlObjectIterator end) const {
294 PvlObject temp(name);
295 return std::find(beg, end, temp);
296 }
297
298
299 PvlObject &findObject(const QString &name,
300 FindOptions opts = None);
301
302 const PvlObject &findObject(const QString &name,
303 FindOptions opts = None) const;
304
309 void addObject(const PvlObject &object) {
310 m_objects.push_back(object);
311 m_objects[m_objects.size()-1].setFileName(fileName());
312 }
313
314 void deleteObject(const QString &name);
315 void deleteObject(const int index);
316
317
325 bool hasObject(const QString &name) const {
326 if(findObject(name, beginObject(), endObject()) == endObject()) return false;
327 return true;
328 }
329
330
337 bool operator==(const PvlObject &object) const {
338 return PvlKeyword::stringEqual(object.name(), this->name());
339 }
340
341
343 void clear() {
345 m_objects.clear();
346 m_groups.clear();
347 }
348
349 const PvlObject &operator=(const PvlObject &other);
350
352 void validateObject(PvlObject & pPvlObj);
353
354 private:
355 QList<PvlObject> m_objects;
357 QList<PvlGroup> m_groups;
359 };
360}
361
362Q_DECLARE_METATYPE(Isis::PvlObject);
363
364#endif
Contains more than one keyword-value pair.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
void clear()
Clears PvlKeywords.
QString fileName() const
Returns the filename used to initialise the Pvl object.
PvlKeywordIterator end()
Return the ending iterator.
QString name() const
Returns the container name.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
A single keyword-value pair.
Definition PvlKeyword.h:87
static bool stringEqual(const QString &string1, const QString &string2)
Checks to see if two QStrings are equal.
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
PvlObjectIterator beginObject()
Returns the index of the beginning object.
Definition PvlObject.h:237
ConstPvlGroupIterator findGroup(const QString &name, ConstPvlGroupIterator beg, ConstPvlGroupIterator end) const
Find a group with the specified name, within these indexes.
Definition PvlObject.h:143
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 ...
PvlGroupIterator beginGroup()
Returns the beginning group index.
Definition PvlObject.h:91
const PvlObject & operator=(const PvlObject &other)
This is an assignment operator.
friend std::istream & operator>>(std::istream &is, PvlObject &result)
This method reads a PvlObject from the input stream.
friend std::ostream & operator<<(std::ostream &os, Isis::PvlObject &object)
Outputs the PvlObject data to a specified output stream.
QList< Isis::PvlGroup >::iterator PvlGroupIterator
The counter for groups.
Definition PvlObject.h:83
PvlGroup & group(const int index)
Return the group at the specified index.
ConstPvlGroupIterator beginGroup() const
Returns the beginning group index.
Definition PvlObject.h:100
PvlObject()
Creates a blank PvlObject.
Definition PvlObject.cpp:27
QList< PvlGroup > m_groups
A vector of PvlGroups contained in the current PvlObject.
Definition PvlObject.h:357
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:325
int groups() const
Returns the number of groups contained.
Definition PvlObject.h:75
void addLogGroup(Isis::PvlGroup &group)
Add a group to the object and report it to the log/terminal.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition PvlObject.h:276
void deleteObject(const QString &name)
Remove an object from the current PvlObject.
int objects() const
Returns the number of objects.
Definition PvlObject.h:221
QList< PvlObject >::iterator PvlObjectIterator
The counter for objects.
Definition PvlObject.h:229
PvlObject & object(const int index)
Return the object at the specified index.
ConstPvlGroupIterator endGroup() const
Returns the const ending group index.
Definition PvlObject.h:118
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
Definition PvlObject.h:212
void clear()
Remove everything from the current PvlObject.
Definition PvlObject.h:343
FindOptions
A collection of options to use when finding.
Definition PvlObject.h:154
@ Traverse
Search child objects.
Definition PvlObject.h:158
@ None
Search only the current level.
Definition PvlObject.h:156
QList< PvlObject > m_objects
A vector of PvlObjects contained in the current PvlObject.
Definition PvlObject.h:355
void addObject(const PvlObject &object)
Add a PvlObject.
Definition PvlObject.h:309
PvlObjectIterator endObject()
Returns the index of the ending object.
Definition PvlObject.h:255
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
void validateObject(PvlObject &pPvlObj)
Validate Object.
ConstPvlObjectIterator endObject() const
Returns the const index of the ending object.
Definition PvlObject.h:264
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition PvlObject.h:186
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:291
void deleteGroup(const QString &name)
Remove a group from the current PvlObject.
PvlGroupIterator endGroup()
Returns the ending group index.
Definition PvlObject.h:109
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition PvlObject.h:129
ConstPvlObjectIterator beginObject() const
Returns the const index of the beginning object.
Definition PvlObject.h:246
bool operator==(const PvlObject &object) const
Compares two PvlObjects.
Definition PvlObject.h:337
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16