|
Isis 3 Programmer Reference
|
9 #include "PvlKeyword.h"
16 #include "IException.h"
18 #include "PvlTokenizer.h"
19 #include "PvlFormat.h"
42 m_internalTemplate =
false;
51 m_internalTemplate =
false;
64 QString message =
"Failed to use string: " + QString::fromStdString(str) +
"to create Pvl";
73 QString message =
"Unable to create PVL from string: " + QString::fromStdString(str);
77 QString message =
"Unable to create PVL from string: " + QString::fromStdString(str);
97 istm.open(
m_filename.toLatin1().data(), std::ios::in);
109 QString message =
"Unable to read PVL file [" + temp.
expanded() +
"]";
114 QString message =
"Unable to read PVL file [" + temp.
expanded() +
"]";
135 bool removeFormatter =
false;
136 if(format() == NULL) {
138 removeFormatter =
true;
144 ostm.open(tempName.toLatin1().data(), std::ios::out);
145 ostm.seekp(0, std::ios::beg);
154 if(
terminator() !=
"") ostm << format()->formatEOL();
158 QString message =
"Unable to write PVL to file [" + temp.
expanded() +
"]";
163 QString message =
"Unable to write PVL to file [" + temp.
expanded() +
"]";
167 if(removeFormatter) {
189 bool removeFormatter =
false;
190 if(format() == NULL) {
192 removeFormatter =
true;
198 ostm.open(tempName.toLatin1().data(), std::ios::app);
199 ostm.seekp(0, std::ios::end);
208 if(
terminator() !=
"") ostm << format()->formatEOL();
212 QString message =
"Unable to append PVL infomation to file [" +
217 if(removeFormatter) {
227 void Pvl::setFormatTemplate(
Isis::Pvl &temp) {
228 if(m_internalTemplate)
delete m_formatTemplate;
229 m_internalTemplate =
false;
230 Isis::PvlObject::setFormatTemplate(temp);
234 void Pvl::setFormatTemplate(
const QString &file) {
235 if(m_internalTemplate)
delete m_formatTemplate;
236 m_internalTemplate =
true;
251 bool removeFormatter =
false;
252 if(pvl.format() == NULL) {
254 removeFormatter =
true;
258 if(pvl.hasFormatTemplate()) outTemplate = *(
Isis::Pvl *)pvl.formatTemplate();
264 for(
int i = 0; i < outTemplate.
keywords(); i++) {
265 if(outTemplate[i].isNamed(
"Isis:PvlTemplate:File")) {
266 QString filename = outTemplate[i];
269 QString message =
"Could not open the template file [" + filename +
"]";
274 for(
int j = 0; j < include.
keywords(); j++) {
279 for(
int j = 0; j < include.
objects(); j++) {
284 for(
int j = 0; j < include.
groups(); j++) {
295 for(
int i = 0; i < outTemplate.
objects(); i++) {
301 for(
int i = 0; i < outTemplate.
groups(); i++) {
306 outTemplate = newTemp;
309 for(
int i = 0; i < pvl.comments(); i++) {
310 os << pvl.comment(i) << pvl.format()->formatEOL();
311 if(i == (pvl.comments() - 1)) os << pvl.format()->formatEOL();
323 for(
int i = 0; i < outTemplate.
objects(); i++) {
324 for(
int j = 0; j < pvl.
objects(); j++) {
326 if(numObjects == 0 && pvl.
keywords() > 0) os << pvl.format()->formatEOL();
327 pvl.
object(j).setIndent(pvl.indent());
329 pvl.
object(j).setFormat(pvl.format());
330 os << pvl.
object(j) << pvl.format()->formatEOL();
331 pvl.
object(j).setFormat(NULL);
332 pvl.
object(j).setIndent(0);
333 if(++numObjects < pvl.
objects()) os << pvl.format()->formatEOL();
338 for(
int i = 0; i < pvl.
objects(); i++) {
340 if(numObjects == 0 && pvl.
keywords() > 0) os << pvl.format()->formatEOL();
341 pvl.
object(i).setIndent(pvl.indent());
342 pvl.
object(i).setFormat(pvl.format());
343 os << pvl.
object(i) << pvl.format()->formatEOL();
344 pvl.
object(i).setFormat(NULL);
345 pvl.
object(i).setIndent(0);
346 if(++numObjects < pvl.
objects()) os << pvl.format()->formatEOL();
353 for(
int i = 0; i < outTemplate.
groups(); i++) {
354 for(
int j = 0; j < pvl.
groups(); j++) {
356 if((numGroups == 0) &&
357 (pvl.
objects() > 0 || pvl.
keywords() > 0)) os << pvl.format()->formatEOL();
358 pvl.
group(j).setIndent(pvl.indent());
359 pvl.
group(j).setFormatTemplate(outTemplate.
group(i));
360 pvl.
group(j).setFormat(pvl.format());
361 os << pvl.
group(j) << pvl.format()->formatEOL();
362 pvl.
group(j).setFormat(NULL);
363 pvl.
group(j).setIndent(0);
364 if(++numGroups < pvl.
groups()) os << pvl.format()->formatEOL();
369 for(
int i = 0; i < pvl.
groups(); i++) {
371 if((numGroups == 0) &&
372 (pvl.
objects() > 0 || pvl.
keywords() > 0)) os << pvl.format()->formatEOL();
373 pvl.
group(i).setIndent(pvl.indent());
374 pvl.
group(i).setFormat(pvl.format());
375 os << pvl.
group(i) << pvl.format()->formatEOL();
376 pvl.
group(i).setFormat(NULL);
377 pvl.
group(i).setIndent(0);
378 if(++numGroups < pvl.
groups()) os << pvl.format()->formatEOL();
386 if(removeFormatter) {
405 string msg =
"Tried to read input stream with an error state into a Pvl";
418 istream::pos_type beforeKeywordPos = is.tellg();
422 while(readKeyword != termination) {
423 for(
unsigned int errorKey = 0;
424 errorKey <
sizeof(errorKeywords) /
sizeof(
PvlKeyword);
426 if(readKeyword == errorKeywords[errorKey]) {
427 is.seekg(beforeKeywordPos, ios::beg);
429 QString msg =
"Unexpected [";
430 msg += readKeyword.
name();
431 msg +=
"] in PVL Object [ROOT]";
437 is.seekg(beforeKeywordPos);
442 else if(readKeyword ==
PvlKeyword(
"Object")) {
443 is.seekg(beforeKeywordPos);
453 beforeKeywordPos = is.tellg();
456 if(is.good() && (is.peek() < 32 || is.peek() > 126)) {
473 if(is.eof() && !is.bad()) {
478 istream::pos_type errorPos = is.tellg();
479 if((
int)errorPos == -1)
throw;
481 is.seekg(0, ios::beg);
484 if((
int)is.tellg() == -1)
throw;
486 while(is.good() && is.tellg() < errorPos) {
487 char next = is.get();
489 if(!isprint(next) && !isspace(next)) {
490 is.seekg(errorPos, ios::beg);
492 else if(next ==
'\n') {
499 msg =
"Error in PVL file on line [";
513 m_internalTemplate = other.m_internalTemplate;
531 pPvlResults=
Pvl(pPvl);
536 for(
int i=0; i<iTmplObjSize; i++) {
539 QString sObjName = pvlTmplObj.
name();
540 bool bObjFound =
false;
552 QString sOption = sObjName +
"__Required";
556 if(pvlKeyOption[0] ==
"true") {
561 if (bObjFound ==
false) {
562 QString sErrMsg =
"Object \"" + sObjName +
"\" Not Found in the Template File\n";
568 int iTmplGrpSize =
groups();
569 for(
int i=0; i<iTmplGrpSize; i++) {
572 QString sGrpName = pvlTmplGrp.
name();
573 bool bGrpFound =
false;
586 QString sOption = sGrpName +
"__Required";
589 if(pvlKeyOption[0] ==
"true") {
594 if (bGrpFound ==
false) {
595 QString sErrMsg =
"Group \"" + sGrpName +
"\" Not Found in the Template File\n";
QString m_terminator
Terminator used to signify the end of the PVL informationDefaults to "END".
QString name() const
Returns the keyword name.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
PvlGroup & group(const int index)
Return the group at the specified index.
@ Io
A type of error that occurred when performing an actual I/O operation.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Contains Pvl Groups and Pvl Objects.
A single keyword-value pair.
void append(const QString &file)
Appends PVL information to a file and handles the end of line sequence.
QString m_filename
This contains the filename used to initialize the pvl object.
void fromString(const std::string &str)
Load PVL information from a string.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
File name manipulation and expansion.
@ Unknown
A type of error that cannot be classified as any of the other error types.
int groups() const
Returns the number of groups contained.
bool fileExists() const
Returns true if the file exists; false otherwise.
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.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Container for cube-like labels.
int objects() const
Returns the number of objects.
void addObject(const PvlObject &object)
Add a PvlObject.
void write(const QString &file)
Opens and writes PVL information to a file and handles the end of line sequence.
void validatePvl(const Pvl &pPvl, Pvl &pPvlResults)
Validate a Pvl with the Template Pvl.
PvlObject & object(const int index)
Return the object at the specified index.
void init()
initializes the class
void validateAllKeywords(PvlContainer &pPvlCont)
Validate All the Keywords in a Container comparing with the Template.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Contains multiple PvlContainers.
void read(const QString &file)
Loads PVL information from a stream.
const Pvl & operator=(const Pvl &other)
This is an assignment operator.
QString terminator() const
Returns the terminator used to signify the end of the PVL informationDefaults to "END".
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 ...
const PvlObject & operator=(const PvlObject &other)
This is an assignment operator.
long long int BigInt
Big int.
void validateGroup(PvlGroup &pPvlGrp)
Validate a Group comparing with the Template Group.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
QString name() const
Returns the container name.
void validateObject(PvlObject &pPvlObj)
Validate Object.
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not.
Pvl()
Constructs an empty Pvl object.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
QString FileCreate(const QString &filename)
This error should be used when a file could not be created.
@ Programmer
This error is for when a programmer made an API call that was illegal.
Namespace for the standard library.
void deleteObject(const QString &name)
Remove an object from the current PvlObject.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
Adds specific functionality to C++ strings.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
Contains more than one keyword-value pair.
void deleteGroup(const QString &name)
Remove a group from the current PvlObject.
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
This is free and unencumbered software released into the public domain.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....