Move Math constants into class (to be consistent with other constants), tested against minGW / gcc 4.7.2 and fixed various issues (mainly initializer lists, unused variables). BlackMisc compiles now in MinGW, but still issues (especially with qDebug() friend methods)

This commit is contained in:
Klaus Basan
2013-04-29 16:00:41 +02:00
parent 7c7ca2dfae
commit c6426a0759
48 changed files with 1034 additions and 920 deletions

View File

@@ -10,229 +10,229 @@
namespace BlackMisc
{
CValue::CValue() : _type(CONFIG_UNKOWN), _value(""), _int_value(0),
_bool_value(false), _double_value(0.0)
{
CValue::CValue() : m_bool_value(false), m_double_value(0.0), m_int_value(0),
m_type(CONFIG_UNKOWN), m_value("")
{
}
CValue::CValue(const QString &value) : m_bool_value(false), m_double_value(0.0), m_int_value(0),
m_type(CONFIG_UNKOWN), m_value(value)
{
init();
}
void CValue::init()
{
bool result = false;
qint32 int_value = 0;
double double_value = 0.0;
int_value = m_value.toInt(&result);
if (result)
{
m_type = CONFIG_INT;
m_int_value = int_value;
m_double_value = int_value;
m_bool_value = false;
return;
}
CValue::CValue (const QString& value) : _type(CONFIG_UNKOWN), _value(value), _int_value(0),
_bool_value(false), _double_value(0.0)
double_value = m_value.toDouble(&result);
if (result)
{
init();
m_type = CONFIG_DOUBLE;
m_int_value = 0;
m_double_value = double_value;
m_bool_value = false;
return;
}
void CValue::init()
if (m_value.compare("false", Qt::CaseInsensitive) == 0)
{
bool result = false;
qint32 int_value = 0;
double double_value = 0.0;
int_value = _value.toInt( &result );
if (result)
{
_type = CONFIG_INT;
_int_value = int_value;
_double_value = int_value;
_bool_value = false;
return;
}
double_value = _value.toDouble( &result );
if (result)
{
_type = CONFIG_DOUBLE;
_int_value = 0;
_double_value = double_value;
_bool_value = false;
return;
}
if ( _value.compare("false", Qt::CaseInsensitive) == 0)
{
_type = CONFIG_BOOL;
_int_value = 0;
_double_value = 0.0;
_bool_value = false;
return;
}
if ( _value.compare("true", Qt::CaseInsensitive) == 0)
{
_type = CONFIG_BOOL;
_int_value = 0;
_double_value = 0.0;
_bool_value = true;
return;
}
_type = CONFIG_STRING;
_int_value = 0;
_double_value = 0.0;
_bool_value = false;
m_type = CONFIG_BOOL;
m_int_value = 0;
m_double_value = 0.0;
m_bool_value = false;
return;
}
qint32 CValue::asInt( bool* ok )
if (m_value.compare("true", Qt::CaseInsensitive) == 0)
{
bool result = true;
if ( _type != CONFIG_INT )
{
result = false;
}
if (ok != NULL)
*ok = result;
return _int_value;
m_type = CONFIG_BOOL;
m_int_value = 0;
m_double_value = 0.0;
m_bool_value = true;
return;
}
double CValue::asDouble( bool* ok )
{
bool result = true;
if ( _type != CONFIG_DOUBLE )
{
result = false;
}
m_type = CONFIG_STRING;
m_int_value = 0;
m_double_value = 0.0;
m_bool_value = false;
}
if (ok != NULL)
*ok = result;
return _double_value;
qint32 CValue::asInt(bool *ok)
{
bool result = true;
if (m_type != CONFIG_INT)
{
result = false;
}
bool CValue::asBool( bool* ok )
{
bool result = true;
if ( _type != CONFIG_BOOL )
{
result = false;
}
if (ok != NULL)
*ok = result;
return m_int_value;
}
if (ok != NULL)
*ok = result;
return _bool_value;
double CValue::asDouble(bool *ok)
{
bool result = true;
if (m_type != CONFIG_DOUBLE)
{
result = false;
}
CConfig::CConfig(IContext &context, const QString& filename, const QString& separator, bool /*isRelative*/)
: m_context(context), m_configfile(filename), m_separator(separator)
if (ok != NULL)
*ok = result;
return m_double_value;
}
bool CValue::asBool(bool *ok)
{
bool result = true;
if (m_type != CONFIG_BOOL)
{
result = false;
}
bool CConfig::load()
if (ok != NULL)
*ok = result;
return m_bool_value;
}
CConfig::CConfig(IContext &context, const QString &filename, const QString &separator, bool /*isRelative*/)
: m_context(context), m_configfile(filename), m_separator(separator)
{
}
bool CConfig::load()
{
return load(m_configfile);
}
bool CConfig::load(const QString &filename)
{
m_configfile = filename;
m_value_map.clear();
if (m_configfile.isEmpty())
{
return load(m_configfile);
bError(m_context) << "Can't open emtpy config file!";
return false;
}
bool CConfig::load(const QString& filename)
QFile input(m_configfile);
if (!input.open(QIODevice::ReadOnly))
{
m_configfile = filename;
m_value_map.clear();
if (m_configfile.isEmpty())
{
bError(m_context) << "Can't open emtpy config file!";
return false;
}
QFile input (m_configfile);
if ( !input.open(QIODevice::ReadOnly))
{
bError(m_context) << "Failed to open config file !" << m_configfile;
input.close();
return false;
}
bool error = false;
quint32 no_line = 0;
QTextStream instream(&input);
while ( !instream.atEnd() )
{
++no_line;
QString line = instream.readLine();
// Remove any whitespace from the start and end
line = line.trimmed();
// Search for the comment operator and discard it
int pos = line.indexOf( QChar('#') );
if ( pos != -1 )
line = line.left(pos).trimmed();
// Check if we have a empty line
if ( line.isEmpty() )
continue;
// Separate between key and value
QStringList tags = line.split(m_separator);
if ( tags.count() != 2)
{
bWarning(m_context) << "Could not parse line " << no_line << " in file " << m_configfile << "!";
error = true;
continue;
}
QString key = tags[0].trimmed();
CValue value = CValue( tags[1].trimmed() );
setValue (key, value);
}
bError(m_context) << "Failed to open config file !" << m_configfile;
input.close();
return !error;
return false;
}
void CConfig::setValue(const QString &key, const CValue &value)
{
if ( contains(key) )
update(key, value);
else
add(key, value);
}
bool error = false;
quint32 no_line = 0;
CValue CConfig::value(const QString &key) const
{
if (m_value_map.contains(key))
return m_value_map.value(key);
else
return CValue();
}
QTextStream instream(&input);
bool CConfig::contains(const QString &key) const
while (!instream.atEnd())
{
return m_value_map.contains(key);
}
++no_line;
void CConfig::remove(const QString &key)
{
m_value_map.remove(key);
}
QString line = instream.readLine();
void CConfig::add(const QString &key, const CValue &value)
{
// Paranoid...
if ( contains(key) )
// Remove any whitespace from the start and end
line = line.trimmed();
// Search for the comment operator and discard it
int pos = line.indexOf(QChar('#'));
if (pos != -1)
line = line.left(pos).trimmed();
// Check if we have a empty line
if (line.isEmpty())
continue;
// Separate between key and value
QStringList tags = line.split(m_separator);
if (tags.count() != 2)
{
update(key, value);
}
else
{
m_value_map.insert(key, value);
bWarning(m_context) << "Could not parse line " << no_line << " in file " << m_configfile << "!";
error = true;
continue;
}
QString key = tags[0].trimmed();
CValue value = CValue(tags[1].trimmed());
setValue(key, value);
}
void CConfig::update(const QString &key, const CValue &value)
{
m_value_map[key] = value;
}
input.close();
return !error;
}
void CConfig::display()
void CConfig::setValue(const QString &key, const CValue &value)
{
if (contains(key))
update(key, value);
else
add(key, value);
}
CValue CConfig::value(const QString &key) const
{
if (m_value_map.contains(key))
return m_value_map.value(key);
else
return CValue();
}
bool CConfig::contains(const QString &key) const
{
return m_value_map.contains(key);
}
void CConfig::remove(const QString &key)
{
m_value_map.remove(key);
}
void CConfig::add(const QString &key, const CValue &value)
{
// Paranoid...
if (contains(key))
{
TValueMap::const_iterator it;
for (it = m_value_map.begin(); it != m_value_map.end(); ++it)
{
CValue value = it.value();
bDebug(m_context) << "Key: " << it.key() << " - Value: " << value.asString();
}
update(key, value);
}
else
{
m_value_map.insert(key, value);
}
}
void CConfig::update(const QString &key, const CValue &value)
{
m_value_map[key] = value;
}
void CConfig::display()
{
TValueMap::const_iterator it;
for (it = m_value_map.begin(); it != m_value_map.end(); ++it)
{
CValue value = it.value();
bDebug(m_context) << "Key: " << it.key() << " - Value: " << value.asString();
}
}
} //! namespace BlackMisc