42 PvlContainer::PvlContainer(
const QString &type) {
53 PvlContainer::PvlContainer(
const QString &type,
const QString &name) {
67 void PvlContainer::init() {
69 m_formatTemplate = NULL;
81 QString msg =
"PVL Keyword [" + name +
"] does not exist in [" +
82 type() +
" = " + this->name() +
"]";
83 if(m_filename.size() > 0) msg +=
" in file [" + m_filename +
"]";
99 QString msg =
"PVL Keyword [" + name +
"] does not exist in [" +
100 type() +
" = " + this->name() +
"]";
101 if(m_filename.size() > 0) msg +=
" in file [" + m_filename +
"]";
113 void PvlContainer::deleteKeyword(
const QString &name) {
116 QString msg =
"PVL Keyword [" + name +
"] does not exist in [" +
117 type() +
" = " + this->name() +
"]";
118 if(m_filename.size() > 0) msg +=
" in file [" + m_filename +
"]";
122 m_keywords.erase(key);
131 void PvlContainer::deleteKeyword(
const int index) {
132 if(index >= (
int)m_keywords.size() || index < 0) {
133 QString msg =
"The specified index is out of bounds in PVL [" +
134 type() +
" = " + name() +
"]";
135 if(m_filename.size() > 0) msg +=
" in file [" + m_filename +
"]";
140 for(
int i = 0; i < index; i++) key++;
142 m_keywords.erase(key);
152 bool PvlContainer::cleanDuplicateKeywords() {
153 bool keywordDeleted =
false;
155 for(
int index = 0; index < m_keywords.size(); index ++) {
159 if(current == *key) {
160 m_keywords.erase(key);
161 keywordDeleted =
true;
166 return keywordDeleted;
175 bool PvlContainer::hasKeyword(
const QString &name)
const {
177 if(key == end())
return false;
189 if(index < 0 || index >= (
int)m_keywords.size()) {
193 return *(m_keywords.begin() + index);
204 if(index < 0 || index >= (
int)m_keywords.size()) {
208 return *(m_keywords.begin() + index);
221 m_keywords.push_back(key);
223 else if(hasKeyword(key.
name())) {
228 m_keywords.push_back(key);
251 return (m_keywords.insert(pos, key));
264 bool removeFormatter =
false;
265 if(container.format() == NULL) {
267 removeFormatter =
true;
271 if(container.hasFormatTemplate()) outTemplate = *(container.formatTemplate());
277 for(
int i = 0; i < outTemplate.
keywords(); i++) {
278 if(outTemplate[i].isNamed(
"Isis:PvlTemplate:File")) {
279 QString filename = outTemplate[i];
281 if(!file.fileExists()) {
282 QString message =
"Could not open the template file [" + filename +
"]";
287 for(
int j = 0; j < include.keywords(); j++) {
288 if(!newTemp.hasKeyword(include[j].name()))
293 else if(!newTemp.hasKeyword(outTemplate[i].
name())) {
294 newTemp.addKeyword(outTemplate[i]);
298 outTemplate = newTemp;
302 for(
int i = 0; i < container.
keywords(); i++) {
303 if(container[i].name().length() > width) width = container[i].name().length();
310 for(
int i = 0; i < outTemplate.
keywords(); i++) {
311 for(
int j = 0; j < container.
keywords(); j++) {
312 if(outTemplate[i].name() != container[j].
name())
continue;
313 container[j].setIndent(container.indent());
314 container[j].setWidth(width);
315 container[j].setFormat(container.format());
317 if(outTemplate[i].comments() + container[j].comments() > 0) os << container.format()->formatEOL();
318 if(outTemplate[i].comments() > 0) {
319 for(
int k = 0; k < outTemplate[i].comments(); k++) {
320 for(
int l = 0; l < outTemplate[i].indent() + container[j].indent(); l++) os <<
" ";
321 os << outTemplate[i].comment(k) << container.format()->formatEOL();
325 container[j].setFormat(NULL);
326 container[j].setIndent(0);
327 container[j].setWidth(0);
328 if(++numKeywords < container.keywords()) {
330 os << container.format()->formatEOL();
336 for(
int i = 0; i < container.
keywords(); i++) {
338 container[i].setIndent(container.indent());
339 container[i].setWidth(width);
340 container[i].setFormat(container.format());
342 container[i].setFormat(NULL);
343 container[i].setIndent(0);
344 container[i].setWidth(0);
345 if(++numKeywords < container.keywords()) {
346 if(i + 1 < container.keywords() && container[i+1].comments() > 0) os << container.format()->formatEOL();
347 os << container.format()->formatEOL();
351 if(removeFormatter) {
352 delete container.format();
353 container.setFormat(NULL);
371 return find(beg, end, temp);
386 return find(beg, end, temp);
395 m_formatTemplate = other.m_formatTemplate;
413 int iTmplKeySize = keywords();
414 for(
int i=0; i<iTmplKeySize; i++) {
416 QString sKeyName = pvlTmplKwrd.
name();
417 bool bKwrdFound =
false;
421 if(sKeyName.contains(
"__Required") || sKeyName.contains(
"__Repeated") ||
422 sKeyName.contains(
"__Range") || sKeyName.contains(
"__Value") ||
423 sKeyName.contains(
"__Type")) {
429 QString sTmplKwrdRange = sKeyName +
"__Range";
430 QString sTmplKwrdValue = sKeyName +
"__Value";
431 QString sTmplKwrdType = sKeyName +
"__Type";
433 PvlKeyword pvlTmplKwrdRange, pvlTmplKwrdValue;
436 if(hasKeyword(sTmplKwrdType)) {
437 sType = findKeyword(sTmplKwrdType)[0];
440 if(hasKeyword(sTmplKwrdRange)) {
441 pvlTmplKwrdRange = findKeyword(sTmplKwrdRange);
445 else if(hasKeyword(sTmplKwrdValue)) {
446 pvlTmplKwrdValue = findKeyword(sTmplKwrdValue);
457 QString sOption = sKeyName +
"__Required";
458 if(hasKeyword(sOption)) {
459 PvlKeyword pvlKeyOption = findKeyword(sOption);
460 if(pvlKeyOption[0] ==
"true") {
465 if (bKwrdFound ==
false) {
466 QString sErrMsg =
"Keyword \"" + sKeyName +
"\" Not Found in the Template File\n";
471 validateRepeatOption(pvlTmplKwrd, pPvlCont);
488 QString sTmplKeyName = pPvlTmplKwrd.
name();
491 QString sType = sTmplKeyName +
"__Type";
492 QString sValueType =
"";
493 if(hasKeyword(sType)) {
494 sValueType = findKeyword(sType)[0];
496 QString sRepeatOption = sTmplKeyName +
"__Repeated";
498 if(hasKeyword(sRepeatOption)) {
499 PvlKeyword pvlKeyOption = findKeyword(sRepeatOption);
500 if(pvlKeyOption[0] ==
"true") {
506 for(
int j=(iKeySize-1); j>=0; j--) {
508 QString sKeyName = pvlKwrd.
name();
509 if(sTmplKeyName == sKeyName) {