summaryrefslogtreecommitdiffstats
path: root/sigscript
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-02-05 20:10:56 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-02-05 20:10:56 -0500
commit377ba703ae26fab07102724de5d45303e952f1ab (patch)
treeab6084aff07ec2aa169baa492497f09b179610af /sigscript
parentab94363681983a50af565145ca249f7fe1c0ea55 (diff)
downloadsigen-377ba703ae26fab07102724de5d45303e952f1ab.tar.gz
sigen-377ba703ae26fab07102724de5d45303e952f1ab.tar.xz
sigen-377ba703ae26fab07102724de5d45303e952f1ab.zip
Fixed hasValueOfType in Config
Diffstat (limited to 'sigscript')
-rw-r--r--sigscript/Config.h15
-rw-r--r--sigscript/Global.h11
2 files changed, 16 insertions, 10 deletions
diff --git a/sigscript/Config.h b/sigscript/Config.h
index eca5e708..69277e61 100644
--- a/sigscript/Config.h
+++ b/sigscript/Config.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2008-2009 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
@@ -58,7 +58,7 @@ class SIGSCRIPT_EXPORT Config : public QObject
Config(Config* parent);
Q_SCRIPTABLE QVariant value(const QString& name, const bool recursive = true) const;
- template<typename T> T valueOfType(const QString& name, const bool recursive = true) const;
+ template<typename T> bool valueOfType(const QString& name, T* value, const bool recursive = true) const;
Q_SCRIPTABLE bool hasValue(const QString& name, const bool recursive = true) const;
template<typename T> bool hasValueOfType(const QString& name, const bool recursive = true) const;
@@ -84,22 +84,25 @@ class SIGSCRIPT_EXPORT Config : public QObject
QMap<QString, Value> m_values;
};
-template<typename T> T Config::valueOfType(const QString& name, const bool recursive) const
+template<typename T> bool Config::valueOfType(const QString& name, T* value, const bool recursive) const
{
QReadLocker locker(&m_lock);
if (hasValueOfType<T>(name))
- return m_values[name].first.value<T>();
+ {
+ *value = m_values[name].first.value<T>();
+ return true;
+ }
if (recursive)
{
Config* par = m_parent;
while (par)
{
if (par->hasValue(name))
- return par->valueOfType<T>(name);
+ return par->valueOfType<T>(name, value, true);
par = par->m_parent;
}
}
- return T();
+ return false;
}
template<typename T> bool Config::hasValueOfType(const QString& name, const bool recursive) const
diff --git a/sigscript/Global.h b/sigscript/Global.h
index 9c60b170..56b50fc6 100644
--- a/sigscript/Global.h
+++ b/sigscript/Global.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2008-2009 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
@@ -38,10 +38,13 @@
#define ALLOW_OVERRIDE_SO(class, type, variable) \
if (sigmod()->singlePlayer()) \
- ALLOW_OVERRIDE(class, type, variable)
+ { \
+ ALLOW_OVERRIDE(class, type, variable); \
+ }
#define ALLOW_OVERRIDE(class, type, variable) \
- if (hasValueOfType<type>(#variable) && m_##class->variable##Check(valueOfType<type>(#variable))) \
- return valueOfType<type>(#variable)
+ type value; \
+ if (valueOfType<type>(#variable, &value) && m_##class->variable##Check(value)) \
+ return value
#endif