12#include "IException.h"
16#include "PvlTranslationTable.h"
85 p_trnsTbl.read(FileName(transFile).expanded());
103 transStm >> p_trnsTbl;
107 vector< pair<QString, int> > validKeywordSizes =
validKeywords();
109 for (
int i = 0; i < p_trnsTbl.groups(); i++) {
110 PvlGroup currGroup = p_trnsTbl.group(i);
112 if (!currGroup.hasKeyword(
"InputKey")) {
113 QString message =
"Unable to find InputKey for group ["
114 + currGroup.name() +
"] in file [" +
115 p_trnsTbl.fileName() +
"]";
116 throw IException(IException::User, message, _FILEINFO_);
119 for (
int j = 0; j < currGroup.keywords(); j++) {
120 bool validKeyword =
false;
121 bool keywordSizeMismatch =
false;
123 const PvlKeyword &currKey = currGroup[j];
127 !validKeyword && key < (int)validKeywordSizes.size();
131 if (currKey.name() == validKeywordSizes[key].first) {
134 if (validKeywordSizes[key].second == -1) {
135 if (currKey.size() > 0) {
140 else if (currKey.size() == validKeywordSizes[key].second) {
144 keywordSizeMismatch =
true;
152 if (!keywordSizeMismatch) {
153 QString message =
"Keyword [" + currKey.name();
154 message +=
"] is not a valid keyword.";
155 message +=
" Error in file [" + p_trnsTbl.fileName() +
"]" ;
157 throw IException(IException::User, message, _FILEINFO_);
160 QString message =
"Keyword [" + currKey.name();
161 message +=
"] does not have the correct number of elements.";
162 message +=
" Error in file [" + p_trnsTbl.fileName() +
"]" ;
164 throw IException(IException::User, message, _FILEINFO_);
182 validKeywords.push_back(pair<QString, int>(
"Translation", 2));
183 validKeywords.push_back(pair<QString, int>(
"OutputName", 1));
184 validKeywords.push_back(pair<QString, int>(
"InputGroup", -1));
185 validKeywords.push_back(pair<QString, int>(
"InputPosition", -1));
186 validKeywords.push_back(pair<QString, int>(
"OutputPosition", -1));
190 validKeywords.push_back(pair<QString, int>(
"InputDefault", -1));
191 validKeywords.push_back(pair<QString, int>(
"InputKeyDependencies", -1));
217 const QString inputKeyValue)
const {
222 QString tmpFValue = inputKeyValue;
223 if (tmpFValue.isEmpty()) {
224 if (translationGroup.hasKeyword(
"InputDefault")) {
225 tmpFValue = (QString) translationGroup[
"InputDefault"];
228 QString msg =
"No value or default value to translate for ";
229 msg +=
"translation group [";
230 msg += translationGroupName;
231 msg +=
"] in file [" + p_trnsTbl.fileName() +
"]";
232 throw IException(IException::Programmer, msg, _FILEINFO_);
237 Pvl::ConstPvlKeywordIterator it = translationGroup.findKeyword(
"Translation",
238 translationGroup.begin(),
239 translationGroup.end());
241 while (it != translationGroup.end()) {
242 const PvlKeyword &key = *it;
245 if (QString::compare((QString) key[1], tmpFValue, Qt::CaseInsensitive) == 0) {
248 else if ((QString) key[1] ==
"*") {
249 if ((QString) key[0] ==
"*") {
257 it = translationGroup.findKeyword(
"Translation", it + 1, translationGroup.end());
260 QString msg =
"Unable to find a translation value for [" +
261 translationGroupName +
", " + inputKeyValue +
"] in file [" +
262 p_trnsTbl.fileName() +
"]";
264 throw IException(IException::Programmer, msg, _FILEINFO_);
286 const int inst)
const {
292 Pvl::ConstPvlKeywordIterator it = translationGroup.findKeyword(
"InputPosition",
293 translationGroup.begin(),
294 translationGroup.end());
296 int currentInstance = 0;
299 if (inst == 0 && it == translationGroup.end()) {
300 PvlKeyword root(
"InputPosition");
305 while (it != translationGroup.end()) {
306 const PvlKeyword &result = *it;
311 if (result.size() == 1 && result[0].contains(
",")) {
312 QString msg =
"Keyword [InputPosition] cannot have a comma [,] in ";
313 msg +=
" the value [";
316 throw IException(IException::Programmer, msg, _FILEINFO_);
321 if (currentInstance == inst) {
328 it = translationGroup.findKeyword(
"InputPosition", it + 1, translationGroup.end());
364 if (translationGroup.hasKeyword(
"InputKey"))
return translationGroup[
"InputKey"];
386 if (translationGroup.hasKeyword(
"InputDefault"))
return translationGroup[
"InputDefault"];
411 if (translationGroup.hasKeyword(
"InputDefault"))
return true;
436 if (translationGroup.hasKeyword(
"Auto"))
return true;
461 if (translationGroup.hasKeyword(
"Optional"))
return true;
487 if (!translationGroup.hasKeyword(
"OutputPosition")) {
488 QString msg =
"Unable to find translation keyword [OutputPostion] in [" +
489 translationGroupName +
"] in file [" + p_trnsTbl.fileName() +
"]";
490 throw IException(IException::Programmer, msg, _FILEINFO_);
494 return translationGroup[
"OutputPosition"];
515 if (translationGroup.hasKeyword(
"OutputName")) {
516 return translationGroup[
"OutputName"];
539 if (!p_trnsTbl.hasGroup(translationGroupName)) {
540 QString msg =
"Unable to find translation group [" + translationGroupName +
541 "] in file [" + p_trnsTbl.fileName() +
"]";
542 throw IException(IException::Programmer, msg, _FILEINFO_);
545 return p_trnsTbl.findGroup(translationGroupName);
PvlTranslationTable()
Construct an empty PvlTranslationTable.
bool IsOptional(const QString translationGroupName)
Determines whether the translation group is optional.
PvlKeyword OutputPosition(const QString translationGroupName)
Retrieves the OutputPosition PvlKeyword for the translation group with the given name.
virtual std::vector< std::pair< QString, int > > validKeywords() const
Returns a vector of valid keyword names and their sizes.
const PvlGroup & findTranslationGroup(const QString translationGroupName) const
Searches for translation group with the given name.
QString Translate(const QString translationGroupName, const QString inputKeyValue="") const
Translates a single output value from the given translation group name and input value.
bool hasInputDefault(const QString translationGroupName)
Determines whether the given group has a default input value.
virtual ~PvlTranslationTable()
Destroys the PvlTranslationTable object.
QString OutputName(const QString translationGroupName)
Retrieves a string containing the value of the OutputName keyword for the translation group with the ...
void AddTable(std::istream &transStm)
Adds the contents of a translation table to the searchable groups/keys Also performs a verification,...
virtual QString InputKeywordName(const QString translationGroupName) const
Returns the input keyword name from the translation table corresponding to the output name argument.
virtual PvlKeyword InputGroup(const QString translationGroupName, const int inst=0) const
Returns the input group name from the translation table corresponding to the output name argument.
bool IsAuto(const QString translationGroupName)
Determines whether the given group should be automatically translated.
Pvl & TranslationTable()
Protected accessor for pvl translation table passed into class.
QString InputDefault(const QString translationGroupName) const
Returns the input default value from the translation table corresponding to the output name argument.
This is free and unencumbered software released into the public domain.
Namespace for the standard library.