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 ***************************************************************************/
21 * @file tcLandsatMetaData.cpp
22 * @brief Landsat metadata file.
25 #include "tcLandsatMetaData.h"
33 * Constructors + destructor
36 /// Load metadata from a file.
37 tcLandsatMetaData::tcLandsatMetaData(QFile
& file
)
39 static QRegExp
regexp("^\\s*(\\w+)\\s*=\\s*(\"(.*)\"|(\\S(.*\\S)?))\\s*$");
40 static QRegExp
end("^\\s*END\\s*$");
41 static QRegExp
blank("^\\s*$");
44 QByteArray line
= file
.readLine();
45 if (regexp
.exactMatch(line
))
47 QString name
= regexp
.cap(1);
51 if (m_groups
.contains(name
))
53 delete m_groups
[name
];
54 qDebug() << "Landsat meta data has conflicting groups:" << line
;
56 tcLandsatMetaData
* newMeta
= new tcLandsatMetaData(file
);
57 m_groups
[name
] = newMeta
;
59 else if ("END_GROUP" == name
)
66 QString valueStr
= regexp
.cap(3);
67 if (valueStr
.isEmpty())
69 valueStr
= regexp
.cap(4);
71 double d
= valueStr
.toDouble(&ok
);
85 m_values
[name
] = value
;
88 else if (end
.exactMatch(line
))
92 else if (blank
.exactMatch(line
))
97 qDebug() << "Parsing error reading landsat meta data:" << line
;
103 tcLandsatMetaData::~tcLandsatMetaData()
111 /// Get the list of group names.
112 QStringList
tcLandsatMetaData::groupNames() const
114 return m_groups
.keys();
117 /// Get the list of value names.
118 QStringList
tcLandsatMetaData::valueNames() const
120 return m_values
.keys();
124 tcLandsatMetaData
& tcLandsatMetaData::operator () (const QString
& name
) const
126 Q_ASSERT(m_groups
.contains(name
));
127 return *m_groups
[name
];
131 QVariant
tcLandsatMetaData::operator [] (const QString
& name
) const
133 if (m_values
.contains(name
))
135 return m_values
[name
];