43 AddTable(transFile.expanded());
51 PvlTranslationTable::PvlTranslationTable(std::istream &istr) {
56 PvlTranslationTable::PvlTranslationTable() {
66 void PvlTranslationTable::AddTable(
const QString &transFile) {
67 p_trnsTbl.read(
FileName(transFile).expanded());
77 void PvlTranslationTable::AddTable(std::istream &transStm) {
78 transStm >> p_trnsTbl;
80 for(
int i = 0; i < p_trnsTbl.groups(); i++) {
81 PvlGroup currGrp = p_trnsTbl.group(i);
84 QString message =
"Unable to find InputKey for group ["
85 + currGrp.
name() +
"] in file [" +
86 p_trnsTbl.fileName() +
"]";
92 vector< pair<QString, int> > validKeywords;
94 validKeywords.push_back(pair<QString, int>(
"Translation", 2));
95 validKeywords.push_back(pair<QString, int>(
"OutputName", 1));
96 validKeywords.push_back(pair<QString, int>(
"InputGroup", -1));
97 validKeywords.push_back(pair<QString, int>(
"InputPosition", -1));
98 validKeywords.push_back(pair<QString, int>(
"OutputPosition", -1));
99 validKeywords.push_back(pair<QString, int>(
"Auto", 0));
100 validKeywords.push_back(pair<QString, int>(
"Optional", 0));
101 validKeywords.push_back(pair<QString, int>(
"InputKey", 1));
102 validKeywords.push_back(pair<QString, int>(
"InputDefault", -1));
104 for(
int j = 0; j < currGrp.
keywords(); j++) {
105 bool validKeyword =
false;
106 bool keywordSizeMismatch =
false;
112 !validKeyword && key < (int)validKeywords.size();
116 if(currKey.
name() == validKeywords[key].first) {
119 if(validKeywords[key].second == -1) {
120 if(currKey.
size() > 0) {
125 else if(currKey.
size() == validKeywords[key].second) {
129 keywordSizeMismatch =
true;
137 if(!keywordSizeMismatch) {
138 QString message =
"Keyword [" + currKey.
name();
139 message +=
"] is not a valid keyword.";
140 message +=
" Error in file [" + p_trnsTbl.fileName() +
"]" ;
145 QString message =
"Keyword [" + currKey.
name();
146 message +=
"] does not have the correct number of elements.";
147 message +=
" Error in file [" + p_trnsTbl.fileName() +
"]" ;
168 QString PvlTranslationTable::Translate(
const QString nName,
169 const QString fValue)
const {
170 if(!p_trnsTbl.hasGroup(nName)) {
171 QString msg =
"Unable to find translation group [" +
172 nName +
"] in file [" + p_trnsTbl.fileName() +
"]";
177 const PvlGroup &tgrp = p_trnsTbl.findGroup(nName);
180 QString tmpFValue = fValue;
181 if(tmpFValue.isEmpty()) {
183 tmpFValue = (QString) tgrp[
"InputDefault"];
186 QString msg =
"No value or default value to translate for ";
187 msg +=
"translation group [";
189 msg +=
"] in file [" + p_trnsTbl.
fileName() +
"]";
199 while(it != tgrp.
end()) {
201 if((QString) key[1] == tmpFValue) {
204 else if((QString) key[1] ==
"*") {
205 if((QString) key[0] ==
"*") {
216 QString msg =
"Unable to find a translation value for [" +
217 nName +
", " + fValue +
"] in file [" +
218 p_trnsTbl.fileName() +
"]";
235 PvlKeyword PvlTranslationTable::InputGroup(
const QString nName,
236 const int inst)
const {
238 if(!p_trnsTbl.hasGroup(nName)) {
239 QString msg =
"Unable to find translation group [" +
240 nName +
"] in file [" + p_trnsTbl.fileName() +
"]";
244 const PvlGroup &transGrp = p_trnsTbl.findGroup(nName);
252 int currentInstance = 0;
255 if(inst == 0 && it == transGrp.
end()) {
261 while(it != transGrp.
end()) {
267 if(result.
size() == 1 && result[0].contains(
",")) {
268 QString msg =
"Keyword [InputPosition] cannot have a comma [,] in ";
269 msg +=
" the value [";
277 if(currentInstance == inst) {
284 it = transGrp.
findKeyword(
"InputPosition", it + 1, transGrp.
end());
311 QString PvlTranslationTable::InputKeywordName(
const QString nName)
const {
313 if(!p_trnsTbl.hasGroup(nName)) {
314 QString msg =
"Unable to find translation group [" +
315 nName +
"] in file [" + p_trnsTbl.fileName() +
"]";
320 if(tgrp.
hasKeyword(
"InputKey"))
return tgrp[
"InputKey"];
335 QString PvlTranslationTable::InputDefault(
const QString nName)
const {
337 if(!p_trnsTbl.hasGroup(nName)) {
338 QString msg =
"Unable to find translation group [" +
339 nName +
"] in file [" + p_trnsTbl.
fileName() +
"]";
344 if(tgrp.
hasKeyword(
"InputDefault"))
return tgrp[
"InputDefault"];
349 bool PvlTranslationTable::IsAuto(
const QString nName) {
350 if(!p_trnsTbl.hasGroup(nName)) {
351 QString msg =
"Unable to find translation group [" + nName +
352 "] in file [" + p_trnsTbl.
fileName() +
"]";
362 bool PvlTranslationTable::IsOptional(
const QString nName) {
363 if(!p_trnsTbl.hasGroup(nName)) {
364 QString msg =
"Unable to find translation group [" + nName +
365 "] in file [" + p_trnsTbl.
fileName() +
"]";
366 throw IException(IException::Programmer, msg,
_FILEINFO_);
376 const QString nName) {
377 if(!p_trnsTbl.hasGroup(nName)) {
378 QString msg =
"Unable to find translation group [" +
379 nName +
"] in file [" + p_trnsTbl.fileName() +
"]";
380 throw IException(IException::Programmer, msg,
_FILEINFO_);
385 QString msg =
"Unable to find translation keyword [OutputPostion] in [" +
386 nName +
"] in file [" + p_trnsTbl.
fileName() +
"]";
387 throw IException(IException::Programmer, msg,
_FILEINFO_);
391 return tgrp[
"OutputPosition"];
395 QString PvlTranslationTable::OutputName(
const QString nName) {
396 if(!p_trnsTbl.hasGroup(nName)) {
397 QString msg =
"Unable to find translation group [" + nName +
398 "] in file [" + p_trnsTbl.
fileName() +
"]";
399 throw IException(IException::Programmer, msg,
_FILEINFO_);
404 return tgrp[
"OutputName"];
PvlKeywordIterator end()
Return the ending iterator.
int size() const
Returns the number of values stored in this keyword.
File name manipulation and expansion.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
PvlKeywordIterator begin()
Return the beginning iterator.
QString fileName() const
Returns the filename used to initialise the Pvl object.
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
QString name() const
Returns the keyword name.
A single keyword-value pair.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
QList< PvlKeyword >::const_iterator ConstPvlKeywordIterator
The const keyword iterator.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
QString name() const
Returns the container name.