7#include "LabelTranslationManager.h"
13#include "PvlContainer.h"
15#include "PvlKeyword.h"
17#include "PvlToPvlTranslationManager.h"
58 const QString &transFile)
73 std::istream &transStrm)
84 void PvlToPvlTranslationManager::SetLabel(Pvl &inputLabel) {
108 const PvlContainer *con;
112 while((grp =
InputGroup(translationGroupName, inst++)).name() !=
"") {
143 const PvlContainer *con = NULL;
150 while((grp =
InputGroup(translationGroupName, inst++)).name() !=
"") {
153 Pvl::ConstPvlKeywordIterator it = transGroup.findKeyword(
"InputKey",
158 while(it != transGroup.end()) {
159 const PvlKeyword &result = *it;
160 if(con->hasKeyword(result[0])) {
161 key.setName(
OutputName(translationGroupName));
163 for(
int v = 0; v < (*con)[(result[0])].size(); v++) {
165 (*con)[result[0]][v]),
166 (*con)[result[0]].unit(v));
171 it = transGroup.findKeyword(
"InputKey", it + 1, transGroup.end());
176 return PvlKeyword(
OutputName(translationGroupName),
208 catch(IException &e) {
233 int instanceNumber = 0;
234 PvlKeyword inputGroupKeyword =
InputGroup(translationGroupName, instanceNumber);
235 bool anInputGroupFound =
false;
237 while(inputGroupKeyword.name() !=
"") {
238 const PvlContainer *containingGroup =
GetContainer(inputGroupKeyword);
239 if(containingGroup != NULL) {
240 anInputGroupFound =
true;
243 return containingGroup->findKeyword(
InputKeywordName(translationGroupName));
248 inputGroupKeyword =
InputGroup(translationGroupName, instanceNumber);
251 if(anInputGroupFound) {
252 QString msg =
"Unable to find input keyword [" +
InputKeywordName(translationGroupName) +
253 "] for output name [" + translationGroupName +
"] in file [" +
TranslationTable().fileName() +
"]";
254 throw IException(IException::Programmer, msg, _FILEINFO_);
257 QString container =
"";
259 for(
int i = 0; i <
InputGroup(translationGroupName).size(); i++) {
260 if(i > 0) container +=
",";
262 container +=
InputGroup(translationGroupName)[i];
265 QString msg =
"Unable to find input group [" + container +
266 "] for output name [" + translationGroupName +
"] in file [" +
TranslationTable().fileName() +
"]";
267 throw IException(IException::Programmer, msg, _FILEINFO_);
286 const PvlContainer *con;
292 while((grp =
InputGroup(translationGroupName, inst++)).name() !=
"") {
307 if(inputGroup.size() == 1 &&
308 PvlKeyword::stringEqual(inputGroup[0],
"ROOT")) {
312 const PvlObject *currentObject = &
p_fLabel;
317 objectIndex < inputGroup.size() - 1;
319 if(currentObject->hasObject(inputGroup[objectIndex])) {
320 currentObject = ¤tObject->findObject(inputGroup[objectIndex]);
328 if(currentObject->hasObject(inputGroup[objectIndex])) {
329 return ¤tObject->findObject(inputGroup[objectIndex]);
331 else if(currentObject->hasGroup(inputGroup[objectIndex])) {
332 return ¤tObject->findGroup(inputGroup[objectIndex]);
LabelTranslationManager()
Constructs a default LabelTranslationManager.
virtual PvlContainer * CreateContainer(const QString translationGroupName, Pvl &pvl)
Creates all parent PVL containers for an output keyword.
virtual PvlContainer * CreateContainer(const QString translationGroupName, Pvl &pvl)
Create the requsted container and any containers above it and return a reference to the container.
virtual ~PvlToPvlTranslationManager()
Destroys the TranslationManager object.
virtual PvlKeyword DoTranslation(const QString translationGroupName)
Translate the requested output name to output values using the input name and values or default value...
virtual const PvlKeyword & InputKeyword(const QString translationGroupName) const
Returns the ith input value associated with the output name argument.
Pvl p_fLabel
A Pvl object for the input label file.
virtual const PvlContainer * GetContainer(const PvlKeyword &inputGroup) const
Return a container from the input label according tund.
virtual QString Translate(QString translationGroupName, int findex=0)
Returns a translated value.
virtual bool InputHasKeyword(const QString translationGroupName)
Indicates if the input keyword corresponding to the output name exists in the label.
PvlToPvlTranslationManager(const QString &transFile)
Constructs and initializes a TranslationManager object from given the Pvl translation file.
void Auto(Pvl &outputLabel)
Automatically translate all the output names found in the translation table If a output name does not...
bool IsOptional(const QString translationGroupName)
Determines whether the translation group is optional.
QString Translate(const QString translationGroupName, const QString inputKeyValue="") const
Translates a single output value from the given translation group name and input value.
QString OutputName(const QString translationGroupName)
Retrieves a string containing the value of the OutputName keyword for the translation group with the ...
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.
This is free and unencumbered software released into the public domain.
Namespace for the standard library.