summaryrefslogtreecommitdiffhomepage
path: root/opentrack-compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-05-25 19:41:12 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-05-25 19:42:11 +0200
commit7fd6c9e83593f51326ea0ed745f4b22b6bb3701b (patch)
tree4ad45b624de06458a131b88adb81616cfe611e77 /opentrack-compat
parent13edf283fc5c6a35d262a13e5cbdceb8013ba81e (diff)
compat/options: konst korrektness
Diffstat (limited to 'opentrack-compat')
-rw-r--r--opentrack-compat/options.cpp22
-rw-r--r--opentrack-compat/options.hpp41
2 files changed, 38 insertions, 25 deletions
diff --git a/opentrack-compat/options.cpp b/opentrack-compat/options.cpp
index 9dcb10ab..4f8da9f7 100644
--- a/opentrack-compat/options.cpp
+++ b/opentrack-compat/options.cpp
@@ -26,7 +26,7 @@ group::group(const QString& name) : name(name)
conf->endGroup();
}
-void group::save()
+void group::save() const
{
auto s = ini_file();
s->beginGroup(name);
@@ -41,7 +41,7 @@ void group::put(const QString &s, const QVariant &d)
kvs[s] = d;
}
-bool group::contains(const QString &s)
+bool group::contains(const QString &s) const
{
return kvs.count(s) != 0;
}
@@ -120,9 +120,9 @@ void impl_bundle::store_kv(const QString &name, const QVariant &datum)
}
}
-bool impl_bundle::contains(const QString &name)
+bool impl_bundle::contains(const QString &name) const
{
- QMutexLocker l(&mtx);
+ QMutexLocker l(const_cast<QMutex*>(&mtx));
return transient.contains(name);
}
@@ -137,9 +137,9 @@ void impl_bundle::save()
emit saving();
}
-bool impl_bundle::modifiedp()
+bool impl_bundle::modifiedp() const
{
- QMutexLocker l(&mtx);
+ QMutexLocker l(const_cast<QMutex*>(&mtx));
return modified;
}
@@ -156,7 +156,7 @@ pbundle opt_singleton::bundle(const opt_singleton::k &key)
if (shared != nullptr)
return shared;
}
-
+
qDebug() << "bundle +" << key;
auto shr = std::make_shared<v>(key);
@@ -196,4 +196,12 @@ opts::~opts()
opts::opts(const QString &name) : b(bundle(name)) {}
+pbundle bundle(const QString& name)
+{
+ return detail::singleton().bundle(name);
+}
+
+
+
+// end
}
diff --git a/opentrack-compat/options.hpp b/opentrack-compat/options.hpp
index cb40b705..c15b9874 100644
--- a/opentrack-compat/options.hpp
+++ b/opentrack-compat/options.hpp
@@ -78,9 +78,9 @@ namespace options {
QString name;
public:
group(const QString& name);
- void save();
+ void save() const;
void put(const QString& s, const QVariant& d);
- bool contains(const QString& s);
+ bool contains(const QString& s) const;
static QString ini_directory();
static QString ini_filename();
static QString ini_pathname();
@@ -88,9 +88,12 @@ namespace options {
static const mem<QSettings> ini_file();
template<typename t>
- t get(const QString& k)
+ t get(const QString& k) const
{
- return qcruft_to_t<t>(kvs[k]);
+ auto value = kvs.find(k);
+ if (value != kvs.cend())
+ return qcruft_to_t<t>(value->second);
+ return t();
}
};
@@ -106,20 +109,20 @@ namespace options {
impl_bundle& operator=(const impl_bundle&) = delete;
signals:
void reloading();
- void saving();
+ void saving() const;
public:
impl_bundle(const QString& group_name);
QString name() { return group_name; }
void reload();
void store_kv(const QString& name, const QVariant& datum);
- bool contains(const QString& name);
+ bool contains(const QString& name) const;
void save();
- bool modifiedp();
-
+ bool modifiedp() const;
+
template<typename t>
- t get(const QString& name)
+ t get(const QString& name) const
{
- QMutexLocker l(&mtx);
+ QMutexLocker l(const_cast<QMutex*>(&mtx));
return transient.get<t>(name);
}
};
@@ -144,13 +147,13 @@ namespace options {
pbundle bundle(const k& key);
void bundle_decf(const k& key);
};
-
+
OPENTRACK_COMPAT_EXPORT opt_singleton& singleton();
}
-
+
using pbundle = std::shared_ptr<opt_bundle>;
-
- static inline pbundle bundle(const QString name) { return detail::singleton().bundle(name); }
+
+ pbundle bundle(const QString& name);
class OPENTRACK_COMPAT_EXPORT opt_bundle : public impl_bundle
{
@@ -166,7 +169,7 @@ namespace options {
#define DEFINE_SLOT(t) void setValue(t datum) { store(datum); }
#define DEFINE_SIGNAL(t) void valueChanged(t)
public:
- QString name() { return self_name; }
+ QString name() const { return self_name; }
base_value(pbundle b, const QString& name);
signals:
DEFINE_SIGNAL(double);
@@ -236,12 +239,14 @@ namespace options {
private:
underlying_t def;
};
-
+
struct OPENTRACK_COMPAT_EXPORT opts
{
pbundle b;
opts(const QString& name);
- ~opts();
+ opts& operator=(const opts&) = delete;
+ opts(const opts&) = delete;
+ virtual ~opts();
};
template<typename t, typename q>
@@ -383,7 +388,7 @@ namespace options {
lb->setText(v);
base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.DIRECT_CONNTYPE);
}
-
+
template<>
inline void tie_setting(value<int>& v, QTabWidget* t)
{