Isis 3 Programmer Reference
LabelTranslationManager.cpp
Go to the documentation of this file.
1 
22 #include "PvlTranslationTable.h"
23 
24 #include "IException.h"
25 #include "IString.h"
27 #include "Message.h"
28 #include "Pvl.h"
29 #include "PvlContainer.h"
30 #include "PvlGroup.h"
31 #include "PvlKeyword.h"
32 #include "PvlObject.h"
33 
34 using namespace std;
35 namespace Isis {
36 
40  LabelTranslationManager::LabelTranslationManager()
42  }
43 
44 
52  AddTable(transFile);
53  }
54 
55 
64  AddTable(transStrm);
65  }
66 
67 
72  }
73 
74 
85  void LabelTranslationManager::Auto(Pvl &outputLabel) {
86  // Attempt to translate every group in the translation table
87  for(int i = 0; i < TranslationTable().groups(); i++) {
89  if(IsAuto(g.name())) {
90  try {
91  PvlContainer *con = CreateContainer(g.name(), outputLabel);
92  (*con) += DoTranslation(g.name());
93  }
94  catch(IException &e) {
95  if(!IsOptional(g.name())) {
96  throw e;//??? is this needed???
97  }
98  }
99  }
100  }
101  }
102 
103 
115  PvlContainer *LabelTranslationManager::CreateContainer(const QString translationGroupName,
116  Pvl &pvl) {
117 
118  // Get the array of Objects/Groups from the OutputName keyword
119  PvlKeyword np = OutputPosition(translationGroupName);
120 
121  PvlObject *obj = &pvl;
122 
123  // Look at every pair in the output position
124  for(int c = 0; c < np.size(); c += 2) {
125  // If this pair is an object
126  if(np[c].toUpper() == "OBJECT") {
127  // If the object doesn't exist create it
128  if(!obj->hasObject(np[c+1])) {
129  obj->addObject(np[c+1]);
130  }
131  obj = &(obj->findObject(np[c+1]));
132  }
133  // If this pair is a group
134  else if(np[c].toUpper() == "GROUP") {
135  // If the group doesn't exist create it
136  if(!obj->hasGroup(np[c+1])) {
137  obj->addGroup(np[c+1]);
138  }
139  return (PvlContainer *) & (obj->findGroup(np[c+1]));
140 
141  }
142  }
143 
144  return (PvlContainer *) obj;
145  }
146 
147 
160  PvlKeyword outputKeyword( outputName, Translate(outputName) );
161  return outputKeyword;
162  }
163 
164 
188 
189  QStringList parsedSpecification;
190 
191  try {
192  QStringList typeSplit = specification.split("@", QString::SkipEmptyParts);
193  QStringList barSplit = specification.split("|", QString::SkipEmptyParts);
194 
195  if (typeSplit.size() == 2) { //handle tag@elementname|value
196  if (typeSplit[0].toLower() != "att" &&
197  typeSplit[0].toLower() != "tag" &&
198  typeSplit[0].toLower() != "new") {
199  QString msg = "Dependency type specification [" + typeSplit[0] +
200  "] is invalid. Valid types are [att], [tag] and [new]";
202  }
203  parsedSpecification.append(typeSplit[0].toLower());
204 
205  QStringList nameValueSplit = typeSplit[1].split("|", QString::SkipEmptyParts);
206  if (nameValueSplit.size() == 2) {
207  parsedSpecification.append(nameValueSplit);
208  }
209  else if (nameValueSplit.size() == 1) {
210  parsedSpecification.append(nameValueSplit);
211  }
212  else { //nameValueSplit is an unexpected value
213  QString msg = "Malformed dependency specification [" + specification + "].";
215  }
216  }
217  else if (barSplit.size() == 2) { //handle elementname|value
218  parsedSpecification = barSplit;
219  }
220  else if (barSplit.size() == 1 && typeSplit.size() == 1) { //handle value with no "@" or "|" characters
221  parsedSpecification = barSplit;
222  }
223  else { //nameValueSplit is an unexpected value
224  QString msg = " [" + specification + "] has unexpected number of '@' or '|' delimiters";
226  }
227  }
228 
229  catch (IException &e) {
230  QString msg = "Malformed dependency specification [" + specification + "].";
232  }
233 
234  return parsedSpecification;
235 }
236 
237 } // end namespace isis
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
Contains more than one keyword-value pair.
Definition: PvlContainer.h:63
LabelTranslationManager()
Constructs a default LabelTranslationManager.
virtual QStringList parseSpecification(QString specification) const
Parses and validates a dependency specification.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:286
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:198
PvlKeyword OutputPosition(const QString translationGroupName)
Retrieves the OutputPosition PvlKeyword for the translation group with the given name.
Namespace for the standard library.
bool hasGroup(const QString &name) const
Returns a boolean value based on whether the object has the specified group or not.
Definition: PvlObject.h:222
virtual PvlContainer * CreateContainer(const QString translationGroupName, Pvl &pvl)
Creates all parent PVL containers for an output keyword.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
virtual void Auto(Pvl &outputLabel)
Automatically translate all the output names tagged as Auto in the translation table If a output name...
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not...
Definition: PvlObject.h:335
void addObject(const PvlObject &object)
Add a PvlObject.
Definition: PvlObject.h:319
QString name() const
Returns the container name.
Definition: PvlContainer.h:77
void AddTable(std::istream &transStm)
Adds the contents of a translation table to the searchable groups/keys Also performs a verification...
virtual PvlKeyword DoTranslation(const QString translationGroupName)
Translate the requested output name to output values using the input name and values or default value...
int size() const
Returns the number of values stored in this keyword.
Definition: PvlKeyword.h:141
Pvl & TranslationTable()
Protected accessor for pvl translation table passed into class.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A single keyword-value pair.
Definition: PvlKeyword.h:98
Container for cube-like labels.
Definition: Pvl.h:135
virtual ~LabelTranslationManager()
Destroys the LabelTranslationManager object.
PvlGroup & group(const int index)
Return the group at the specified index.
Definition: PvlObject.cpp:423
Internalizes a translation table.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
bool IsOptional(const QString translationGroupName)
Determines whether the translation group is optional.
int groups() const
Returns the number of groups contained.
Definition: PvlObject.h:87
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
bool IsAuto(const QString translationGroupName)
Determines whether the given group should be automatically translated.