cpvoids program to copy voids from one HGT dataset to another
[tecorrec.git] / geo / tcLandsatMetaData.h
blob13debcdf04797fe056fbdfa7f84f39b57c6ba7c2
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 #ifndef _tcLandsatMetaData_h_
21 #define _tcLandsatMetaData_h_
23 /**
24 * @file tcLandsatMetaData.h
25 * @brief Landsat metadata file.
28 #include <QHash>
29 #include <QString>
30 #include <QStringList>
31 #include <QVariant>
33 class QFile;
35 /** Landsat metadata file.
36 * This aims to be generic enough to read both Landsat 5 and Landsat 7 metadata files.
38 class tcLandsatMetaData
40 public:
43 * Types
46 /// Nice wrapper class.
47 class Reference;
50 * Constructors + destructor
53 /// Load metadata from a file.
54 tcLandsatMetaData(QFile& file);
56 /// Destructor.
57 virtual ~tcLandsatMetaData();
60 * Accessors
63 /// Get the list of group names.
64 QStringList groupNames() const;
66 /// Get the list of object names.
67 QStringList objectNames() const;
69 /// Get the number of objects with a particular name.
70 int numObjects(const QString& name) const;
72 /// Get the list of value names.
73 QStringList valueNames() const;
75 /// Find whether a certain group exists.
76 bool hasGroup(const QString& name) const;
78 /// Find whether a certain object exists.
79 bool hasObject(const QString& name) const;
81 /// Find whether a certain value exists.
82 bool hasValue(const QString& name) const;
84 /// Access a group.
85 tcLandsatMetaData* group(const QString& name) const;
87 /// Access an object.
88 tcLandsatMetaData* object(const QString& name, int index) const;
90 /// Access a value.
91 QVariant value(const QString& name) const;
93 private:
96 * Variables
99 /// Hash of groups.
100 QHash<QString, tcLandsatMetaData*> m_groups;
102 /// Hash of objects.
103 QHash<QString, QList<tcLandsatMetaData*> > m_objects;
105 /// Hash of values.
106 QHash<QString, QVariant> m_values;
109 /// Nice wrapper class.
110 class tcLandsatMetaData::Reference
112 public:
115 * Constructors + destructor
118 /// Primary constructor.
119 Reference(tcLandsatMetaData* metaData = 0)
120 : m_metaData(metaData)
125 * Accessors
128 /// Return whether the reference is valid
129 bool isValid() const
131 return 0 != m_metaData;
134 /// Return whether the reference is valid
135 operator bool() const
137 return isValid();
140 /// Find if a group exists.
141 bool hasGroup(const QString& name) const
143 if (isValid())
145 return m_metaData->hasGroup(name);
147 return false;
150 /// Find if an object exists.
151 int hasObject(const QString& name) const
153 if (isValid())
155 return m_metaData->numObjects(name);
157 return false;
160 /// Find if a value exists.
161 bool hasValue(const QString& name) const
163 if (isValid())
165 return m_metaData->hasValue(name);
167 return false;
170 /// Get a reference to a group.
171 Reference operator () (const QString& name) const
173 if (isValid())
175 return m_metaData->group(name);
177 return 0;
180 /// Get a reference to an object.
181 Reference operator () (const QString& name, int index) const
183 if (isValid())
185 return m_metaData->object(name, index);
187 return 0;
190 /** Get a value.
191 * We get an error when using string literals without this extra
192 * definition. oh well.
194 QVariant operator [] (const char* name) const
196 if (isValid())
198 return m_metaData->value(name);
200 return QVariant();
203 /// Get a value.
204 QVariant operator [] (const QString& name) const
206 if (isValid())
208 return m_metaData->value(name);
210 return QVariant();
213 private:
216 * Variables
219 /// Meta data object.
220 tcLandsatMetaData* m_metaData;
223 #endif