From 6679f5cffa9d35a23b76605ddfbf3257f882b6ee Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 17 Apr 2008 23:34:36 +0000 Subject: [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 --- general/Ini.cpp | 174 -------------------------------------------------------- 1 file changed, 174 deletions(-) delete mode 100644 general/Ini.cpp (limited to 'general/Ini.cpp') 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 - * - * 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 . - */ - -// Qt includes -#include -#include -#include - -// 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(); -} -- cgit