summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-12-30 08:27:50 +0100
committerStanislaw Halik <sthalik@misaki.pl>2013-12-30 08:27:50 +0100
commit598a7ebfb4672ab96a5f0b8693cfab3d954ea6a6 (patch)
tree1ff0111bae88ab78ab7da70cdb508bf160d85420
parent40d5a72739ff9f650e05c3193a60a6bbcd2ea69c (diff)
impl default value
-rw-r--r--facetracknoir/options.hpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/facetracknoir/options.hpp b/facetracknoir/options.hpp
index ef3437ad..49367831 100644
--- a/facetracknoir/options.hpp
+++ b/facetracknoir/options.hpp
@@ -79,6 +79,10 @@ namespace options {
{
map[s] = d;
}
+ bool contains(const QString& s)
+ {
+ return map.contains(s);
+ }
};
class bundle {
@@ -106,6 +110,10 @@ namespace options {
modified = true;
transient.put(name, datum);
}
+ bool contains(const QString& name)
+ {
+ return transient.contains(name);
+ }
template<typename T>
T get(QString& name) {
transient.get<T>(name);
@@ -131,13 +139,18 @@ namespace options {
template<typename T>
class value : public QCruft {
private:
- const QString self_name;
+ QString self_name;
pbundle b;
public:
- value(const pbundle& b, const QString& name) :
+ value(const pbundle& b, const QString& name, T def) :
self_name(name),
b(b)
{
+ if (!b->contains(name))
+ {
+ QVariant cruft(def);
+ b->store(self_name, cruft);
+ }
}
operator T() { return b->get<T>(self_name); }
T& operator=(const T& datum) {