summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Glöckner <cgloeckner@freenet.de>2016-03-31 10:12:20 +0200
committerChristian Glöckner <cgloeckner@freenet.de>2016-03-31 10:12:20 +0200
commitfb944022b0e727007420d30ff84d28974fb5f38e (patch)
treeebb44bac3598eb648d241c2ff8af47f5d45454c4 /src
parente526594e983659858ce55027cdd06489cdf8af57 (diff)
Cleanup on Synced Settings Header
Diffstat (limited to 'src')
-rw-r--r--src/syncedsettings.h128
1 files changed, 56 insertions, 72 deletions
diff --git a/src/syncedsettings.h b/src/syncedsettings.h
index f83847c..eb8e66e 100644
--- a/src/syncedsettings.h
+++ b/src/syncedsettings.h
@@ -28,85 +28,69 @@
#include <mutex>
-// type trait helper
+template <typename T> class Group;
-template <typename T, typename... Types>
-struct pack_contains;
+template <typename T> class Accessor
+{
+private:
+ std::lock_guard<std::mutex> lock;
-template <typename T, typename... Types>
-struct pack_contains<T, T, Types...>
- : std::true_type {
-};
+public:
+ Accessor(Group<T>& parent)
+ : lock{parent.mutex}
+ , data{parent.data}
+ {
+ }
-template <typename T, typename Head, typename... Types>
-struct pack_contains<T, Head, Types...>
- : pack_contains<T, Types...> {
+ T& data;
};
-template <typename T>
-struct pack_contains<T>
- : std::false_type {
-};
+template <typename T> class Group
+{
+private:
+ friend class Accessor<T>;
-// --------------------------------------------------------------------
+ mutable std::mutex mutex;
+ T data;
-template <typename T>
-class Group;
+public:
+ Group()
+ : mutex{}
+ , data{}
+ {
+ }
-template <typename T>
-class Accessor {
- private:
- std::lock_guard<std::mutex> lock;
-
- public:
- Accessor(Group<T>& parent)
- : lock{parent.mutex}
- , data{parent.data} {
- }
-
- T& data;
-};
+ Group(T const& data)
+ : mutex{}
+ , data{data}
+ {
+ }
+
+ Group(T&& data)
+ : mutex{}
+ , data{std::move(data)}
+ {
+ }
+
+ Group(Group<T> const& other)
+ : mutex{}
+ , data{}
+ {
+ std::lock_guard<std::mutex> lock{other.mutex};
+ data = other.data;
+ }
+
+ Group(Group<T>&& other)
+ : mutex{}
+ , data{}
+ {
+ std::lock_guard<std::mutex> lock{other.mutex};
+ std::swap(data, other.data);
+ }
-template <typename T>
-class Group {
- private:
- friend class Accessor<T>;
-
- mutable std::mutex mutex;
- T data;
-
- public:
- Group()
- : mutex{}
- , data{} {
- }
-
- Group(T const & data)
- : mutex{}
- , data{data} {
- }
-
- Group(T&& data)
- : mutex{}
- , data{std::move(data)} {
- }
-
- Group(Group<T> const & other)
- : mutex{}
- , data{} {
- std::lock_guard<std::mutex> lock{other.mutex};
- data = other.data;
- }
-
- Group(Group<T>&& other)
- : mutex{}
- , data{} {
- std::lock_guard<std::mutex> lock{other.mutex};
- std::swap(data, other.data);
- }
-
- operator T() const {
- std::lock_guard<std::mutex> lock{mutex};
- return data;
- }
+ operator T() const
+ {
+ std::lock_guard<std::mutex> lock{mutex};
+ return data;
+ }
};