summaryrefslogtreecommitdiffstats
path: root/general/Ini.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'general/Ini.cpp')
-rw-r--r--general/Ini.cpp174
1 files changed, 0 insertions, 174 deletions
diff --git a/general/Ini.cpp b/general/Ini.cpp
deleted file mode 100644
index 859dc59b..00000000
--- a/general/Ini.cpp
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-// Qt includes
-#include <QDir>
-#include <QStringList>
-#include <QTextStream>
-
-// Header include
-#include "Ini.h"
-
-Ini::Ini()
-{
-}
-
-Ini::Ini(const QString& fileName) throw(Exception)
-{
- load(fileName);
-}
-
-void Ini::load(const QString& fileName) throw(Exception)
-{
- QFile fin(fileName);
- if (!fin.exists())
- throw(OpenException("Ini", fileName));
- load(fin);
- fin.close();
-}
-
-void Ini::load(QFile& fin) throw(InvalidException)
-{
- QTextStream file(&fin);
- QString line = file.readLine();
- QString field;
- QString value;
- int pos;
- m_fields.clear();
- while (!file.atEnd())
- {
- pos = line.indexOf('=');
- if (pos == INT_MAX)
- throw(InvalidException("Ini", fin.fileName()));
- field = line.mid(0, pos - 1);
- value = line.mid(pos + 1, line.length() - pos);
- if (field.isEmpty())
- throw(InvalidException("Ini", fin.fileName()));
- m_fields[field] = value;
- line = file.readLine();
- }
-}
-
-void Ini::save(const QString& fileName) const throw(Exception)
-{
- QStringList path = fileName.split(QDir::separator(), QString::SkipEmptyParts);
- path.removeLast();
- if (!QDir().mkpath(path.join("/")))
- throw(DirException("Ini", path.join("/")));
- QFile fout(fileName);
- if (!fout.open(QIODevice::WriteOnly))
- throw(OpenException("Ini", fileName));
- save(fout);
- fout.close();
-}
-
-void Ini::save(QFile& file) const
-{
- QTextStream fout(&file);
- foreach (QString field, m_fields)
- fout << field << '=' << m_fields[field] << '\n';
- fout << '\n';
-}
-
-void Ini::addField(const QString& field, const bool value)
-{
- m_fields[field] = value ? "true" : "false";
-}
-
-void Ini::addField(const QString& field, const unsigned char value)
-{
- m_fields[field] = QString::number(value);
-}
-
-void Ini::addField(const QString& field, const int value)
-{
- m_fields[field] = QString::number(value);
-}
-
-void Ini::addField(const QString& field, const double value)
-{
- m_fields[field] = QString::number(value);
-}
-
-void Ini::addField(const QString& field, const QString& value)
-{
- m_fields[field] = value;
-}
-
-void Ini::getValue(const QString& field, bool& value, const bool defaultValue)
-{
- if (!m_fields.contains(field))
- {
- value = defaultValue;
- return;
- }
- value = (m_fields[field] == "true") ? true : ((m_fields[field] == "false") ? false : defaultValue);
-}
-
-void Ini::getValue(const QString& field, unsigned char& value, const unsigned char defaultValue)
-{
- if (!m_fields.contains(field))
- {
- value = defaultValue;
- return;
- }
- bool ok;
- unsigned temp;
- temp = m_fields[field].toUInt(&ok);
- value = (ok && (temp <= UCHAR_MAX)) ? temp : defaultValue;
-}
-
-void Ini::getValue(const QString& field, int& value, const int defaultValue)
-{
- if (!m_fields.contains(field))
- {
- value = defaultValue;
- return;
- }
- bool ok;
- value = m_fields[field].toInt(&ok);
- if (!ok)
- value = defaultValue;
-}
-
-void Ini::getValue(const QString& field, double& value, const double defaultValue)
-{
- if (!m_fields.contains(field))
- {
- value = defaultValue;
- return;
- }
- bool ok;
- value = m_fields[field].toDouble(&ok);
- if (!ok)
- value = defaultValue;
-}
-
-void Ini::getValue(const QString& field, QString& value, const QString& defaultValue)
-{
- if (!m_fields.contains(field))
- {
- value = defaultValue;
- return;
- }
- value = m_fields[field];
-}
-
-QStringList Ini::fields() const
-{
- return m_fields.keys();
-}