Isis 3 Programmer Reference
LabelTranslationManager.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "PvlTranslationTable.h"
8
9#include "IException.h"
10#include "IString.h"
11#include "LabelTranslationManager.h"
12#include "Message.h"
13#include "Pvl.h"
14#include "PvlContainer.h"
15#include "PvlGroup.h"
16#include "PvlKeyword.h"
17#include "PvlObject.h"
18
19using namespace std;
20namespace Isis {
21
28
29
37 AddTable(transFile);
38 }
39
40
49 AddTable(transStrm);
50 }
51
52
59
71 // Attempt to translate every group in the translation table
72 for(int i = 0; i < TranslationTable().groups(); i++) {
74 if(IsAuto(g.name())) {
75 try {
76 PvlContainer *con = CreateContainer(g.name(), outputLabel);
77 (*con) += DoTranslation(g.name());
78 }
79 catch(IException &e) {
80 if(!IsOptional(g.name())) {
81 throw e;//??? is this needed???
82 }
83 }
84 }
85 }
86 }
87
88
100 PvlContainer *LabelTranslationManager::CreateContainer(const QString translationGroupName,
101 Pvl &pvl) {
102
103 // Get the array of Objects/Groups from the OutputName keyword
104 PvlKeyword np = OutputPosition(translationGroupName);
105
106 PvlObject *obj = &pvl;
107
108 // Look at every pair in the output position
109 for(int c = 0; c < np.size(); c += 2) {
110 // If this pair is an object
111 if(np[c].toUpper() == "OBJECT") {
112 // If the object doesn't exist create it
113 if(!obj->hasObject(np[c+1])) {
114 obj->addObject(np[c+1]);
115 }
116 obj = &(obj->findObject(np[c+1]));
117 }
118 // If this pair is a group
119 else if(np[c].toUpper() == "GROUP") {
120 // If the group doesn't exist create it
121 if(!obj->hasGroup(np[c+1])) {
122 obj->addGroup(np[c+1]);
123 }
124 return (PvlContainer *) & (obj->findGroup(np[c+1]));
125
126 }
127 }
128
129 return (PvlContainer *) obj;
130 }
131
132
145 PvlKeyword outputKeyword( outputName, Translate(outputName) );
146 return outputKeyword;
147 }
148
149
173
174 QStringList parsedSpecification;
175
176 try {
177 QStringList typeSplit = specification.split("@", QString::SkipEmptyParts);
178 QStringList barSplit = specification.split("|", QString::SkipEmptyParts);
179
180 if (typeSplit.size() == 2) { //handle tag@elementname|value
181 if (typeSplit[0].toLower() != "att" &&
182 typeSplit[0].toLower() != "tag" &&
183 typeSplit[0].toLower() != "new") {
184 QString msg = "Dependency type specification [" + typeSplit[0] +
185 "] is invalid. Valid types are [att], [tag] and [new]";
186 throw IException(IException::Programmer, msg, _FILEINFO_);
187 }
188 parsedSpecification.append(typeSplit[0].toLower());
189
190 QStringList nameValueSplit = typeSplit[1].split("|", QString::SkipEmptyParts);
191 if (nameValueSplit.size() == 2) {
192 parsedSpecification.append(nameValueSplit);
193 }
194 else if (nameValueSplit.size() == 1) {
195 parsedSpecification.append(nameValueSplit);
196 }
197 else { //nameValueSplit is an unexpected value
198 QString msg = "Malformed dependency specification [" + specification + "].";
199 throw IException(IException::Programmer, msg, _FILEINFO_);
200 }
201 }
202 else if (barSplit.size() == 2) { //handle elementname|value
203 parsedSpecification = barSplit;
204 }
205 else if (barSplit.size() == 1 && typeSplit.size() == 1) { //handle value with no "@" or "|" characters
206 parsedSpecification = barSplit;
207 }
208 else { //nameValueSplit is an unexpected value
209 QString msg = " [" + specification + "] has unexpected number of '@' or '|' delimiters";
210 throw IException(IException::Programmer,msg, _FILEINFO_);
211 }
212 }
213
214 catch (IException &e) {
215 QString msg = "Malformed dependency specification [" + specification + "].";
216 throw IException(e, IException::Programmer, msg, _FILEINFO_);
217 }
218
219 return parsedSpecification;
220}
221
222} // end namespace isis
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
virtual PvlKeyword DoTranslation(const QString translationGroupName)
Translate the requested output name to output values using the input name and values or default value...
virtual void Auto(Pvl &outputLabel)
Automatically translate all the output names tagged as Auto in the translation table If a output name...
LabelTranslationManager()
Constructs a default LabelTranslationManager.
virtual QStringList parseSpecification(QString specification) const
Parses and validates a dependency specification.
virtual PvlContainer * CreateContainer(const QString translationGroupName, Pvl &pvl)
Creates all parent PVL containers for an output keyword.
virtual ~LabelTranslationManager()
Destroys the LabelTranslationManager object.
Contains more than one keyword-value pair.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
PvlGroup & group(const int index)
Return the group at the specified index.
int groups() const
Returns the number of groups contained.
Definition PvlObject.h:75
void addObject(const PvlObject &object)
Add a PvlObject.
Definition PvlObject.h:309
Internalizes a translation table.
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.
void AddTable(std::istream &transStm)
Adds the contents of a translation table to the searchable groups/keys Also performs a verification,...
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.
Definition Apollo.h:16
Namespace for the standard library.