diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-04-13 17:09:33 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-05-18 11:50:29 +0100 |
| commit | 7749e3cc9ac7b51c2a77ee4f2c3c99e381747716 (patch) | |
| tree | 418045669301470f11371032615bb7bcfbf8ef86 /src/lib/content_part.h | |
| parent | 775ae0e37bbec115d742feade0adc614a9a2301c (diff) | |
Add maybe_set to ContentPart.
Diffstat (limited to 'src/lib/content_part.h')
| -rw-r--r-- | src/lib/content_part.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/content_part.h b/src/lib/content_part.h index 9ee26cbdb..dbc523239 100644 --- a/src/lib/content_part.h +++ b/src/lib/content_part.h @@ -20,6 +20,7 @@ #ifndef DCPOMATIC_CONTENT_PART_H #define DCPOMATIC_CONTENT_PART_H +#include "content.h" #include <boost/weak_ptr.hpp> #include <boost/thread/mutex.hpp> @@ -35,6 +36,34 @@ public: {} protected: + template <class T> + void + maybe_set (T& member, T new_value, int property) const + { + { + boost::mutex::scoped_lock lm (_mutex); + if (member == new_value) { + return; + } + member = new_value; + } + _parent->signal_changed (property); + } + + template <class T> + void + maybe_set (boost::optional<T>& member, T new_value, int property) const + { + { + boost::mutex::scoped_lock lm (_mutex); + if (member && member.get() == new_value) { + return; + } + member = new_value; + } + _parent->signal_changed (property); + } + Content* _parent; boost::weak_ptr<const Film> _film; mutable boost::mutex _mutex; |
