diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-04-17 23:34:36 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-04-17 23:34:36 +0000 |
| commit | 6679f5cffa9d35a23b76605ddfbf3257f882b6ee (patch) | |
| tree | c8e41854a60b64e8569939bca6b827807175ef9a /general/Ini.cpp | |
| parent | 05980e883719b1c8ebde1bd2fcbf4f8c16df7ad6 (diff) | |
[FIX] Frac -> Fraction
[FIX] ImageCache and Ini removed
[FIX] Fraction/Point widgets moved to pokemodr
[FIX] Copy ctors made for pokemod classes
[FIX] Ctors in pokemod fixed
[FIX] Copyright headers fixed in pokemodr
[FIX] PokeModr updated to new API and fixed in some places
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@99 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'general/Ini.cpp')
| -rw-r--r-- | general/Ini.cpp | 174 |
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(); -} |
