56 m_internalTemplate =
false;
65 m_internalTemplate =
false;
83 istm.open(
m_filename.toLatin1().data(), std::ios::in);
95 QString message =
"Unable to read PVL file [" + temp.expanded() +
"]";
100 QString message =
"Unable to read PVL file [" + temp.expanded() +
"]";
121 bool removeFormatter =
false;
122 if(format() == NULL) {
124 removeFormatter =
true;
129 QString tempName(temp.expanded());
130 ostm.open(tempName.toLatin1().data(), std::ios::out);
131 ostm.seekp(0, std::ios::beg);
140 if(
terminator() !=
"") ostm << format()->formatEOL();
144 QString message =
"Unable to write PVL to file [" + temp.expanded() +
"]";
149 QString message =
"Unable to write PVL to file [" + temp.expanded() +
"]";
153 if(removeFormatter) {
175 bool removeFormatter =
false;
176 if(format() == NULL) {
178 removeFormatter =
true;
183 QString tempName(temp.expanded());
184 ostm.open(tempName.toLatin1().data(), std::ios::app);
185 ostm.seekp(0, std::ios::end);
194 if(
terminator() !=
"") ostm << format()->formatEOL();
198 QString message =
"Unable to append PVL infomation to file [" +
199 temp.expanded() +
"]";
203 if(removeFormatter) {
213 void Pvl::setFormatTemplate(
Isis::Pvl &temp) {
214 if(m_internalTemplate)
delete m_formatTemplate;
215 m_internalTemplate =
false;
216 Isis::PvlObject::setFormatTemplate(temp);
220 void Pvl::setFormatTemplate(
const QString &file) {
221 if(m_internalTemplate)
delete m_formatTemplate;
222 m_internalTemplate =
true;
237 bool removeFormatter =
false;
238 if(pvl.format() == NULL) {
240 removeFormatter =
true;
244 if(pvl.hasFormatTemplate()) outTemplate = *(
Isis::Pvl *)pvl.formatTemplate();
250 for(
int i = 0; i < outTemplate.
keywords(); i++) {
251 if(outTemplate[i].isNamed(
"Isis:PvlTemplate:File")) {
252 QString filename = outTemplate[i];
254 if(!file.fileExists()) {
255 QString message =
"Could not open the template file [" + filename +
"]";
260 for(
int j = 0; j < include.keywords(); j++) {
265 for(
int j = 0; j < include.objects(); j++) {
266 if(!newTemp.
hasObject(include.object(j).name()))
270 for(
int j = 0; j < include.groups(); j++) {
271 if(!newTemp.
hasGroup(include.group(j).name()))
281 for(
int i = 0; i < outTemplate.
objects(); i++) {
287 for(
int i = 0; i < outTemplate.
groups(); i++) {
292 outTemplate = newTemp;
295 for(
int i = 0; i < pvl.comments(); i++) {
296 os << pvl.comment(i) << pvl.format()->formatEOL();
297 if(i == (pvl.comments() - 1)) os << pvl.format()->formatEOL();
309 for(
int i = 0; i < outTemplate.
objects(); i++) {
310 for(
int j = 0; j < pvl.
objects(); j++) {
312 if(numObjects == 0 && pvl.
keywords() > 0) os << pvl.format()->formatEOL();
313 pvl.
object(j).setIndent(pvl.indent());
315 pvl.
object(j).setFormat(pvl.format());
316 os << pvl.
object(j) << pvl.format()->formatEOL();
317 pvl.
object(j).setFormat(NULL);
318 pvl.
object(j).setIndent(0);
319 if(++numObjects < pvl.
objects()) os << pvl.format()->formatEOL();
324 for(
int i = 0; i < pvl.
objects(); i++) {
326 if(numObjects == 0 && pvl.
keywords() > 0) os << pvl.format()->formatEOL();
327 pvl.
object(i).setIndent(pvl.indent());
328 pvl.
object(i).setFormat(pvl.format());
329 os << pvl.
object(i) << pvl.format()->formatEOL();
330 pvl.
object(i).setFormat(NULL);
331 pvl.
object(i).setIndent(0);
332 if(++numObjects < pvl.
objects()) os << pvl.format()->formatEOL();
339 for(
int i = 0; i < outTemplate.
groups(); i++) {
340 for(
int j = 0; j < pvl.
groups(); j++) {
342 if((numGroups == 0) &&
343 (pvl.
objects() > 0 || pvl.
keywords() > 0)) os << pvl.format()->formatEOL();
344 pvl.
group(j).setIndent(pvl.indent());
345 pvl.
group(j).setFormatTemplate(outTemplate.
group(i));
346 pvl.
group(j).setFormat(pvl.format());
347 os << pvl.
group(j) << pvl.format()->formatEOL();
348 pvl.
group(j).setFormat(NULL);
349 pvl.
group(j).setIndent(0);
350 if(++numGroups < pvl.
groups()) os << pvl.format()->formatEOL();
355 for(
int i = 0; i < pvl.
groups(); i++) {
357 if((numGroups == 0) &&
358 (pvl.
objects() > 0 || pvl.
keywords() > 0)) os << pvl.format()->formatEOL();
359 pvl.
group(i).setIndent(pvl.indent());
360 pvl.
group(i).setFormat(pvl.format());
361 os << pvl.
group(i) << pvl.format()->formatEOL();
362 pvl.
group(i).setFormat(NULL);
363 pvl.
group(i).setIndent(0);
364 if(++numGroups < pvl.
groups()) os << pvl.format()->formatEOL();
372 if(removeFormatter) {
391 string msg =
"Tried to read input stream with an error state into a Pvl";
404 istream::pos_type beforeKeywordPos = is.tellg();
408 while(readKeyword != termination) {
409 for(
unsigned int errorKey = 0;
410 errorKey <
sizeof(errorKeywords) /
sizeof(
PvlKeyword);
412 if(readKeyword == errorKeywords[errorKey]) {
413 is.seekg(beforeKeywordPos, ios::beg);
415 QString msg =
"Unexpected [";
416 msg += readKeyword.
name();
417 msg +=
"] in PVL Object [ROOT]";
423 is.seekg(beforeKeywordPos);
428 else if(readKeyword ==
PvlKeyword(
"Object")) {
429 is.seekg(beforeKeywordPos);
439 beforeKeywordPos = is.tellg();
442 if(is.good() && (is.peek() < 32 || is.peek() > 126)) {
459 if(is.eof() && !is.bad()) {
464 istream::pos_type errorPos = is.tellg();
465 if((
int)errorPos == -1)
throw;
467 is.seekg(0, ios::beg);
470 if((
int)is.tellg() == -1)
throw;
472 while(is.good() && is.tellg() < errorPos) {
473 char next = is.get();
475 if(!isprint(next) && !isspace(next)) {
476 is.seekg(errorPos, ios::beg);
478 else if(next ==
'\n') {
485 msg =
"Error in PVL file on line [";
486 msg +=
IString((Isis::BigInt)lineNumber);
499 m_internalTemplate = other.m_internalTemplate;
517 pPvlResults=
Pvl(pPvl);
522 for(
int i=0; i<iTmplObjSize; i++) {
525 QString sObjName = pvlTmplObj.
name();
526 bool bObjFound =
false;
538 QString sOption = sObjName +
"__Required";
542 if(pvlKeyOption[0] ==
"true") {
547 if (bObjFound ==
false) {
548 QString sErrMsg =
"Object \"" + sObjName +
"\" Not Found in the Template File\n";
554 int iTmplGrpSize =
groups();
555 for(
int i=0; i<iTmplGrpSize; i++) {
558 QString sGrpName = pvlTmplGrp.
name();
559 bool bGrpFound =
false;
572 QString sOption = sGrpName +
"__Required";
575 if(pvlKeyOption[0] ==
"true") {
580 if (bGrpFound ==
false) {
581 QString sErrMsg =
"Group \"" + sGrpName +
"\" Not Found in the Template File\n";
PvlObject & object(const int index)
Return the object at the specified index.
QString FileCreate(const QString &filename)
This error should be used when a file could not be created.
const PvlObject & operator=(const PvlObject &other)
This is an assignment operator.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Contains more than one keyword-value pair.
File name manipulation and expansion.
void validateAllKeywords(PvlContainer &pPvlCont)
Validate All the Keywords in a Container comparing with the Template.
QString terminator() const
Returns the terminator used to signify the end of the PVL informationDefaults to "END".
void init()
initializes the class
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
QString m_terminator
Terminator used to signify the end of the PVL informationDefaults to "END".
void append(const QString &file)
Appends PVL information to a file and handles the end of line sequence.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
void validateObject(PvlObject &pPvlObj)
Validate Object.
This error is for when a programmer made an API call that was illegal.
A type of error that occurred when performing an actual I/O operation.
void deleteGroup(const QString &name)
Remove a group from the current PvlObject.
void validateGroup(PvlGroup &pPvlGrp)
Validate a Group comparing with the Template Group.
QString m_filename
This contains the filename used to initialize the pvl object.
void addObject(const PvlObject &object)
Add a PvlObject.
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 ...
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
QString name() const
Returns the keyword name.
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
int objects() const
Returns the number of objects.
A type of error that could only have occurred due to a mistake on the user's part (e...
A single keyword-value pair.
A type of error that cannot be classified as any of the other error types.
void validatePvl(const Pvl &pPvl, Pvl &pPvlResults)
Validate a Pvl with the Template Pvl.
Container for cube-like labels.
Pvl()
Constructs an empty Pvl object.
void deleteObject(const QString &name)
Remove an object from the current PvlObject.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
const Pvl & operator=(const Pvl &other)
This is an assignment operator.
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not...
int groups() const
Returns the number of groups contained.
PvlGroup & group(const int index)
Return the group at the specified index.
Adds specific functionality to C++ strings.
QString FileOpen(const QString &filename)
This error should be used when a file could not be opened.
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
void write(const QString &file)
Opens and writes PVL information to a file and handles the end of line sequence.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Contains Pvl Groups and Pvl Objects.
void read(const QString &file)
Loads PVL information from a stream.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
QString name() const
Returns the container name.