42 PvlTranslationTable::PvlTranslationTable(
FileName transFile) {
52 PvlTranslationTable::PvlTranslationTable(std::istream &istr) {
60 PvlTranslationTable::PvlTranslationTable() {
67 PvlTranslationTable::~PvlTranslationTable() {
78 Pvl &PvlTranslationTable::TranslationTable() {
90 const Pvl &PvlTranslationTable::TranslationTable()
const {
100 void PvlTranslationTable::AddTable(
const QString &transFile) {
118 void PvlTranslationTable::AddTable(std::istream &transStm) {
119 transStm >> p_trnsTbl;
123 vector< pair<QString, int> > validKeywordSizes = validKeywords();
125 for (
int i = 0; i < p_trnsTbl.groups(); i++) {
126 PvlGroup currGroup = p_trnsTbl.group(i);
129 QString message =
"Unable to find InputKey for group [" 130 + currGroup.
name() +
"] in file [" +
131 p_trnsTbl.fileName() +
"]";
135 for (
int j = 0; j < currGroup.
keywords(); j++) {
136 bool validKeyword =
false;
137 bool keywordSizeMismatch =
false;
143 !validKeyword && key < (int)validKeywordSizes.size();
147 if (currKey.
name() == validKeywordSizes[key].first) {
150 if (validKeywordSizes[key].second == -1) {
151 if (currKey.
size() > 0) {
156 else if (currKey.
size() == validKeywordSizes[key].second) {
160 keywordSizeMismatch =
true;
168 if (!keywordSizeMismatch) {
169 QString message =
"Keyword [" + currKey.
name();
170 message +=
"] is not a valid keyword.";
171 message +=
" Error in file [" + p_trnsTbl.fileName() +
"]" ;
176 QString message =
"Keyword [" + currKey.
name();
177 message +=
"] does not have the correct number of elements.";
178 message +=
" Error in file [" + p_trnsTbl.fileName() +
"]" ;
195 vector< pair<QString, int> > PvlTranslationTable::validKeywords()
const {
197 vector< pair<QString, int> > validKeywords;
198 validKeywords.push_back(pair<QString, int>(
"Translation", 2));
199 validKeywords.push_back(pair<QString, int>(
"OutputName", 1));
200 validKeywords.push_back(pair<QString, int>(
"InputGroup", -1));
201 validKeywords.push_back(pair<QString, int>(
"InputPosition", -1));
202 validKeywords.push_back(pair<QString, int>(
"OutputPosition", -1));
203 validKeywords.push_back(pair<QString, int>(
"Auto", 0));
204 validKeywords.push_back(pair<QString, int>(
"Optional", 0));
205 validKeywords.push_back(pair<QString, int>(
"InputKey", 1));
206 validKeywords.push_back(pair<QString, int>(
"InputDefault", -1));
207 validKeywords.push_back(pair<QString, int>(
"InputKeyDependencies", -1));
209 return validKeywords;
232 QString PvlTranslationTable::Translate(
const QString translationGroupName,
233 const QString inputKeyValue)
const {
235 const PvlGroup &translationGroup = findTranslationGroup(translationGroupName);
238 QString tmpFValue = inputKeyValue;
239 if (tmpFValue.isEmpty()) {
240 if (translationGroup.
hasKeyword(
"InputDefault")) {
241 tmpFValue = (QString) translationGroup[
"InputDefault"];
244 QString msg =
"No value or default value to translate for ";
245 msg +=
"translation group [";
246 msg += translationGroupName;
247 msg +=
"] in file [" + p_trnsTbl.
fileName() +
"]";
254 translationGroup.
begin(),
255 translationGroup.
end());
257 while (it != translationGroup.
end()) {
261 if (QString::compare((QString) key[1], tmpFValue, Qt::CaseInsensitive) == 0) {
264 else if ((QString) key[1] ==
"*") {
265 if ((QString) key[0] ==
"*") {
273 it = translationGroup.
findKeyword(
"Translation", it + 1, translationGroup.
end());
276 QString msg =
"Unable to find a translation value for [" +
277 translationGroupName +
", " + inputKeyValue +
"] in file [" +
278 p_trnsTbl.fileName() +
"]";
301 PvlKeyword PvlTranslationTable::InputGroup(
const QString translationGroupName,
302 const int inst)
const {
304 const PvlGroup &translationGroup = findTranslationGroup(translationGroupName);
309 translationGroup.
begin(),
310 translationGroup.
end());
312 int currentInstance = 0;
315 if (inst == 0 && it == translationGroup.
end()) {
321 while (it != translationGroup.
end()) {
327 if (result.
size() == 1 && result[0].contains(
",")) {
328 QString msg =
"Keyword [InputPosition] cannot have a comma [,] in ";
329 msg +=
" the value [";
337 if (currentInstance == inst) {
344 it = translationGroup.
findKeyword(
"InputPosition", it + 1, translationGroup.
end());
376 QString PvlTranslationTable::InputKeywordName(
const QString translationGroupName)
const {
378 const PvlGroup &translationGroup = findTranslationGroup(translationGroupName);
380 if (translationGroup.
hasKeyword(
"InputKey"))
return translationGroup[
"InputKey"];
398 QString PvlTranslationTable::InputDefault(
const QString translationGroupName)
const {
400 const PvlGroup &translationGroup = findTranslationGroup(translationGroupName);
402 if (translationGroup.
hasKeyword(
"InputDefault"))
return translationGroup[
"InputDefault"];
423 bool PvlTranslationTable::hasInputDefault(
const QString translationGroupName) {
425 const PvlGroup &translationGroup = findTranslationGroup(translationGroupName);
427 if (translationGroup.
hasKeyword(
"InputDefault"))
return true;
448 bool PvlTranslationTable::IsAuto(
const QString translationGroupName) {
450 const PvlGroup &translationGroup = findTranslationGroup(translationGroupName);
452 if (translationGroup.
hasKeyword(
"Auto"))
return true;
473 bool PvlTranslationTable::IsOptional(
const QString translationGroupName) {
475 const PvlGroup &translationGroup = findTranslationGroup(translationGroupName);
477 if (translationGroup.
hasKeyword(
"Optional"))
return true;
499 PvlKeyword PvlTranslationTable::OutputPosition(
const QString translationGroupName) {
501 const PvlGroup &translationGroup = findTranslationGroup(translationGroupName);
503 if (!translationGroup.
hasKeyword(
"OutputPosition")) {
504 QString msg =
"Unable to find translation keyword [OutputPostion] in [" +
505 translationGroupName +
"] in file [" + p_trnsTbl.fileName() +
"]";
510 return translationGroup[
"OutputPosition"];
527 QString PvlTranslationTable::OutputName(
const QString translationGroupName) {
529 const PvlGroup &translationGroup = findTranslationGroup(translationGroupName);
531 if (translationGroup.
hasKeyword(
"OutputName")) {
532 return translationGroup[
"OutputName"];
554 const PvlGroup &PvlTranslationTable::findTranslationGroup(
const QString translationGroupName)
const {
555 if (!p_trnsTbl.hasGroup(translationGroupName)) {
556 QString msg =
"Unable to find translation group [" + translationGroupName +
557 "] in file [" + p_trnsTbl.
fileName() +
"]";
561 return p_trnsTbl.findGroup(translationGroupName);
int keywords() const
Returns the number of keywords contained in the PvlContainer.
PvlKeywordIterator end()
Return the ending iterator.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
File name manipulation and expansion.
PvlKeywordIterator begin()
Return the beginning iterator.
Namespace for the standard library.
QString name() const
Returns the container name.
int size() const
Returns the number of values stored in this keyword.
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
A single keyword-value pair.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Container for cube-like labels.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
QString fileName() const
Returns the filename used to initialise the Pvl object.
QString name() const
Returns the keyword name.
Namespace for ISIS/Bullet specific routines.
QList< PvlKeyword >::const_iterator ConstPvlKeywordIterator
The const keyword iterator.
void read(const QString &file)
Loads PVL information from a stream.