1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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_
24 * @file tcLandsatMetaData.h
25 * @brief Landsat metadata file.
30 #include <QStringList>
35 /** Landsat metadata file.
36 * This aims to be generic enough to read both Landsat 5 and Landsat 7 metadata files.
38 class tcLandsatMetaData
46 /// Nice wrapper class.
50 * Constructors + destructor
53 /// Load metadata from a file.
54 tcLandsatMetaData(QFile
& file
);
57 virtual ~tcLandsatMetaData();
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;
85 tcLandsatMetaData
* group(const QString
& name
) const;
88 tcLandsatMetaData
* object(const QString
& name
, int index
) const;
91 QVariant
value(const QString
& name
) const;
100 QHash
<QString
, tcLandsatMetaData
*> m_groups
;
103 QHash
<QString
, QList
<tcLandsatMetaData
*> > m_objects
;
106 QHash
<QString
, QVariant
> m_values
;
109 /// Nice wrapper class.
110 class tcLandsatMetaData::Reference
115 * Constructors + destructor
118 /// Primary constructor.
119 Reference(tcLandsatMetaData
* metaData
= 0)
120 : m_metaData(metaData
)
128 /// Return whether the reference is valid
131 return 0 != m_metaData
;
134 /// Return whether the reference is valid
135 operator bool() const
140 /// Find if a group exists.
141 bool hasGroup(const QString
& name
) const
145 return m_metaData
->hasGroup(name
);
150 /// Find if an object exists.
151 int hasObject(const QString
& name
) const
155 return m_metaData
->numObjects(name
);
160 /// Find if a value exists.
161 bool hasValue(const QString
& name
) const
165 return m_metaData
->hasValue(name
);
170 /// Get a reference to a group.
171 Reference
operator () (const QString
& name
) const
175 return m_metaData
->group(name
);
180 /// Get a reference to an object.
181 Reference
operator () (const QString
& name
, int index
) const
185 return m_metaData
->object(name
, index
);
191 * We get an error when using string literals without this extra
192 * definition. oh well.
194 QVariant
operator [] (const char* name
) const
198 return m_metaData
->value(name
);
204 QVariant
operator [] (const QString
& name
) const
208 return m_metaData
->value(name
);
219 /// Meta data object.
220 tcLandsatMetaData
* m_metaData
;