11#include "PvlContainer.h"
14#include "IException.h"
53 m_formatTemplate = NULL;
65 QString msg =
"PVL Keyword [" +
name +
"] does not exist in [" +
83 QString msg =
"PVL Keyword [" +
name +
"] does not exist in [" +
100 QString msg =
"PVL Keyword [" +
name +
"] does not exist in [" +
101 type() +
" = " + this->
name() +
"]";
116 if(index >= (
int)
m_keywords.size() || index < 0) {
117 QString msg =
"The specified index is out of bounds in PVL [" +
124 for(
int i = 0; i < index; i++) key++;
137 bool keywordDeleted =
false;
139 for(
int index = 0; index <
m_keywords.size(); index ++) {
143 if(current == *key) {
145 keywordDeleted =
true;
150 return keywordDeleted;
161 if(key ==
end())
return false;
173 if(index < 0 || index >= (
int)
m_keywords.size()) {
188 if(index < 0 || index >= (
int)
m_keywords.size()) {
248 bool removeFormatter =
false;
249 if(container.format() == NULL) {
251 removeFormatter =
true;
255 if(container.hasFormatTemplate()) outTemplate = *(container.formatTemplate());
261 for(
int i = 0; i < outTemplate.keywords(); i++) {
262 if(outTemplate[i].isNamed(
"Isis:PvlTemplate:File")) {
263 QString filename = outTemplate[i];
265 if(!file.fileExists()) {
266 QString message =
"Could not open the template file [" + filename +
"]";
271 for(
int j = 0; j < include.
keywords(); j++) {
272 if(!newTemp.hasKeyword(include[j].
name()))
273 newTemp.addKeyword(include[j]);
277 else if(!newTemp.hasKeyword(outTemplate[i].name())) {
278 newTemp.addKeyword(outTemplate[i]);
282 outTemplate = newTemp;
286 for(
int i = 0; i < container.keywords(); i++) {
287 if(container[i].name().length() > width) width = container[i].name().length();
294 for(
int i = 0; i < outTemplate.keywords(); i++) {
295 for(
int j = 0; j < container.keywords(); j++) {
296 if(outTemplate[i].name() != container[j].name())
continue;
297 container[j].setIndent(container.indent());
298 container[j].setWidth(width);
299 container[j].setFormat(container.format());
301 if(outTemplate[i].comments() + container[j].comments() > 0) os << container.format()->formatEOL();
302 if(outTemplate[i].comments() > 0) {
303 for(
int k = 0; k < outTemplate[i].comments(); k++) {
304 for(
int l = 0; l < outTemplate[i].indent() + container[j].indent(); l++) os <<
" ";
305 os << outTemplate[i].comment(k) << container.format()->formatEOL();
309 container[j].setFormat(NULL);
310 container[j].setIndent(0);
311 container[j].setWidth(0);
312 if(++numKeywords < container.keywords()) {
314 os << container.format()->formatEOL();
320 for(
int i = 0; i < container.keywords(); i++) {
321 if(outTemplate.hasKeyword(container[i].name()))
continue;
322 container[i].setIndent(container.indent());
323 container[i].setWidth(width);
324 container[i].setFormat(container.format());
326 container[i].setFormat(NULL);
327 container[i].setIndent(0);
328 container[i].setWidth(0);
329 if(++numKeywords < container.keywords()) {
330 if(i + 1 < container.keywords() && container[i+1].comments() > 0) os << container.format()->formatEOL();
331 os << container.format()->formatEOL();
335 if(removeFormatter) {
336 delete container.format();
337 container.setFormat(NULL);
355 return find(beg,
end, temp);
370 return find(beg,
end, temp);
379 m_formatTemplate = other.m_formatTemplate;
398 for(
int i=0; i<iTmplKeySize; i++) {
400 QString sKeyName = pvlTmplKwrd.
name();
401 bool bKwrdFound =
false;
405 if(sKeyName.contains(
"__Required") || sKeyName.contains(
"__Repeated") ||
406 sKeyName.contains(
"__Range") || sKeyName.contains(
"__Value") ||
407 sKeyName.contains(
"__Type")) {
411 if(pPvlCont.hasKeyword(sKeyName)) {
412 PvlKeyword & pvlKwrd = pPvlCont.findKeyword(sKeyName);
413 QString sTmplKwrdRange = sKeyName +
"__Range";
414 QString sTmplKwrdValue = sKeyName +
"__Value";
415 QString sTmplKwrdType = sKeyName +
"__Type";
417 PvlKeyword pvlTmplKwrdRange, pvlTmplKwrdValue;
426 pvlTmplKwrd.validateKeyword(pvlKwrd, sType, &pvlTmplKwrdRange);
431 pvlTmplKwrd.validateKeyword(pvlKwrd, sType, &pvlTmplKwrdValue);
434 pvlTmplKwrd.validateKeyword(pvlKwrd, sType);
436 pPvlCont.deleteKeyword(pvlKwrd.name());
441 QString sOption = sKeyName +
"__Required";
444 if(pvlKeyOption[0] ==
"true") {
449 if (bKwrdFound ==
false) {
450 QString sErrMsg =
"Keyword \"" + sKeyName +
"\" Not Found in the Template File\n";
472 QString sTmplKeyName = pPvlTmplKwrd.name();
475 QString sType = sTmplKeyName +
"__Type";
476 QString sValueType =
"";
480 QString sRepeatOption = sTmplKeyName +
"__Repeated";
484 if(pvlKeyOption[0] ==
"true") {
489 int iKeySize = pPvlCont.keywords();
490 for(
int j=(iKeySize-1); j>=0; j--) {
492 QString sKeyName = pvlKwrd.
name();
493 if(sTmplKeyName == sKeyName) {
494 pPvlTmplKwrd.validateKeyword(pvlKwrd, sValueType);
495 pPvlCont.deleteKeyword(pvlKwrd.name());
File name manipulation and expansion.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Programmer
This error is for when a programmer made an API call that was illegal.
@ Io
A type of error that occurred when performing an actual I/O operation.
Contains more than one keyword-value pair.
PvlContainer(const QString &type)
Constructs a PvlContainer object with a type.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
bool cleanDuplicateKeywords()
Removes keywords from the container that have BOTH the same name and value.
const PvlContainer & operator=(const PvlContainer &other)
This is an assignment operator.
QList< PvlKeyword >::iterator PvlKeywordIterator
The keyword iterator.
void init()
Sets the filename to blank.
QString m_filename
This contains the filename used to initialize the pvl object.
void validateRepeatOption(PvlKeyword &pPvlTmplKwrd, PvlContainer &pPvlCont)
Validate the Repeat Option for a Keyword.
PvlKeywordIterator begin()
Return the beginning iterator.
QList< PvlKeyword >::const_iterator ConstPvlKeywordIterator
The const keyword iterator.
PvlKeyword m_name
This is the name keyword.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
PvlKeywordIterator end()
Return the ending iterator.
void setName(const QString &name)
Set the name of the container.
InsertMode
Contains both modes: Append or Replace.
PvlKeyword & operator[](const QString &name)
When you use the [] operator with a (string) name, it will call the findKeyword() method.
QString name() const
Returns the container name.
QString type() const
Returns the container type.
void validateAllKeywords(PvlContainer &pPvlCont)
Validate All the Keywords in a Container comparing with the Template.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
void deleteKeyword(const QString &name)
Remove a specified keyword.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
QList< PvlKeyword > m_keywords
This is the vector of PvlKeywords the container is holding.
Container for cube-like labels.
A single keyword-value pair.
void setName(QString name)
Sets the keyword name.
QString name() const
Returns the keyword name.
char * m_name
The keyword's name... This is a c-string for memory efficiency.
QString ArraySubscriptNotInRange(int index)
This error should be used when an Isis object or application is checking array bounds and the legal r...
This is free and unencumbered software released into the public domain.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Namespace for the standard library.