12#include "IException.h" 
   16#include "PvlTranslationTable.h" 
  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() + 
"]";
 
  119      for (
int j = 0; j < currGroup.keywords(); j++) {
 
  120        bool validKeyword = 
false;
 
  121        bool keywordSizeMismatch = 
false;
 
  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() + 
"]" ;
 
  160            QString message = 
"Keyword [" + currKey.name();
 
  161            message += 
"] does not have the correct number of elements.";
 
  162            message += 
" Error in file [" + p_trnsTbl.fileName() + 
"]" ;
 
 
  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() + 
"]";
 
  238                                      translationGroup.begin(),
 
  239                                      translationGroup.end());
 
  241    while (it != translationGroup.end()) {
 
  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 [" +
 
 
  286                                             const int inst)
 const {
 
  293                                      translationGroup.begin(),
 
  294                                      translationGroup.end());
 
  296    int currentInstance = 0;
 
  299    if (inst == 0 && it == translationGroup.end()) {
 
  305    while (it != translationGroup.end()) {
 
  311      if (result.
size() == 1 && result[0].contains(
",")) {
 
  312        QString msg = 
"Keyword [InputPosition] cannot have a comma [,] in ";
 
  313        msg += 
" the value [";
 
  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() + 
"]";
 
  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() + 
"]";
 
  545    return p_trnsTbl.
findGroup(translationGroupName);
 
 
File name manipulation and expansion.
 
@ 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.
 
QString fileName() const
Returns the filename used to initialise the Pvl object.
 
QList< PvlKeyword >::const_iterator ConstPvlKeywordIterator
The const keyword iterator.
 
Contains multiple PvlContainers.
 
Container for cube-like labels.
 
void read(const QString &file)
Loads PVL information from a stream.
 
A single keyword-value pair.
 
QString name() const
Returns the keyword name.
 
int size() const
Returns the number of values stored in this keyword.
 
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
 
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
 
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.