USGS

Isis 3.0 Object Programmers' Reference

Home

CubeAttribute.h
Go to the documentation of this file.
1 #ifndef CubeAttribute_h
2 #define CubeAttribute_h
3 
26 #include <typeinfo>
27 
28 #include <QDebug>
29 #include <QStringList>
30 
31 #include "Cube.h"
32 #include "Endian.h"
33 #include "FileName.h"
34 #include "IException.h"
35 #include "PixelType.h"
36 
37 
38 namespace Isis {
50 
57  };
58 
59 
68  inline QString LabelAttachmentName(LabelAttachment labelType) {
69  if(labelType == AttachedLabel) return "Attached";
70  if(labelType == DetachedLabel) return "Detached";
71  if(labelType == ExternalLabel) return "External";
72 
73  QString msg = "Invalid label attachment type [" + QString(labelType) + "]";
75  }
76 
77 
86  inline LabelAttachment LabelAttachmentEnumeration(const QString &labelType) {
87  QString temp = labelType.toUpper();
88  if(temp == "ATTACHED") return AttachedLabel;
89  if(temp == "DETACHED") return DetachedLabel;
90  if(temp == "External") return ExternalLabel;
91 
92  QString msg = "Invalid label attachment type string [" + labelType + "]";
94  }
95 
96 
97 
133  template<typename ChildClass> class CubeAttribute {
134  public:
135 
137  CubeAttribute(QList< bool (ChildClass::*)(QString) const > testers) {
138  m_attributeTypeTesters = testers;
139  }
140 
141 
153  CubeAttribute(QList< bool (ChildClass::*)(QString) const > testers,
154  const FileName &fileName) {
155  m_attributeTypeTesters = testers;
156  setAttributes(fileName);
157  }
158 
159 
161  virtual ~CubeAttribute() {
162  }
163 
164 
173  QString toString() const {
174  QString result;
175 
176  if (!m_attributes.isEmpty())
177  result = "+" + m_attributes.join("+");
178 
179  return result;
180  }
181 
182 
193  void addAttribute(QString attribute) {
194  QString upcaseAtt = attribute.toUpper();
195 
196  if (attribute.contains("+")) {
198  "Individual attributes (for example, BSQ) cannot contain the '+' "
199  "character because that is used to denote the separation of individual "
200  "attributes",
201  _FILEINFO_);
202  }
203 
204  // Verify this attribute is legal
205  bool legal = false;
206  bool (ChildClass::*tester)(QString) const;
207  foreach (tester, m_attributeTypeTesters) {
208  if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
209  if (legal) {
211  QObject::tr("Attribute [%1] is ambiguous").arg(attribute),
212  _FILEINFO_);
213  }
214 
215  legal = true;
216  }
217  }
218 
219  if (!legal) {
221  QObject::tr("Attribute [%1] is not recognized").arg(attribute),
222  _FILEINFO_);
223  }
224 
225  m_attributes.append(attribute);
226  }
227 
228 
237  void addAttributes(const FileName &fileNameWithAtts) {
238  addAttributes(fileNameWithAtts.attributes());
239  }
240 
241 
250  void addAttributes(const char *attributesString) {
251  addAttributes(QString(attributesString));
252  }
253 
254 
263  void addAttributes(const QString &attributesString) {
264  setAttributes(toString() + "+" + attributesString);
265  }
266 
267 
277  void setAttributes(const FileName &fileName) {
278  QStringList attributes = fileName.attributes().split("+", QString::SkipEmptyParts);
279 
280  m_attributes.clear();
281  foreach (QString attribute, attributes)
282  addAttribute(attribute);
283  }
284 
285 
286  protected:
295  QStringList attributeList(bool (ChildClass::*tester)(QString) const) const {
296  QStringList relevantAttributes;
297 
298  foreach (QString attribute, m_attributes) {
299  QString upcaseAtt = attribute.toUpper();
300  if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
301  relevantAttributes.append(upcaseAtt);
302  }
303  }
304 
305  return relevantAttributes;
306  }
307 
308 
320  void setAttribute(QString newValue, bool (ChildClass::*tester)(QString) const) {
321  QMutableListIterator<QString> it(m_attributes);
322 
323  bool found = false;
324  while (it.hasNext()) {
325  QString &attribute = it.next();
326 
327  QString upcaseAtt = attribute.toUpper();
328  if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
329  if (found || newValue == "") {
330  // already found one (remove the duplicate) or just deleting it
331  it.remove();
332  }
333  else {
334  // modify existing attribute value
335  attribute = newValue;
336  }
337 
338  found = true;
339  }
340  }
341 
342  // Attribute doesn't exist, add it
343  if (!found && newValue != "") {
344  m_attributes.append(newValue);
345  }
346  }
347 
348  private:
355 
364  };
365 
366 
394  class CubeAttributeInput : public CubeAttribute<CubeAttributeInput> {
395 
396  public:
397 
400 
401 
411  CubeAttributeInput(const FileName &fileName);
412 
413 
416 
417 
419  std::vector<QString> bands() const;
420 
432  QString bandsString() const;
433 
435  void setBands(const std::vector<QString> &bands);
436 
438 
439  private:
440  bool isBandRange(QString attribute) const;
441 
442  static QString toString(const std::vector<QString> &bands);
444 
445  private:
446  std::vector<QString> m_bands;
447  };
448 
449 
484  class CubeAttributeOutput : public CubeAttribute<CubeAttributeOutput> {
485 
486  public:
487 
490 
503  CubeAttributeOutput(const FileName &fileName);
504 
505 
508 
509 
511  bool propagatePixelType() const;
512 
514  bool propagateMinimumMaximum() const;
515 
517  Cube::Format fileFormat() const;
518 
520  QString fileFormatString() const;
521 
523  void setFileFormat(Cube::Format fmt);
524 
526  ByteOrder byteOrder() const;
527 
529  QString byteOrderString() const;
530 
532  void setByteOrder(ByteOrder order);
533 
535  double minimum() const;
536 
538  double maximum() const;
539 
541  void setMinimum(double min);
542 
544  void setMaximum(double max);
545 
547  PixelType pixelType() const;
548 
550  void setPixelType(PixelType type);
551 
553  void setLabelAttachment(LabelAttachment attachment);
554 
555  LabelAttachment labelAttachment() const;
556 
558 
559 
560  private:
561  bool isByteOrder(QString attribute) const;
562  bool isFileFormat(QString attribute) const;
563  bool isLabelAttachment(QString attribute) const;
564  bool isPixelType(QString attribute) const;
565  bool isRange(QString attribute) const;
566 
567  static QString toString(Cube::Format);
568 
575  enum RangeType {
578  };
579 
581  };
582 };
583 
584 #endif