Add a load of explicit keywords.
[dcpomatic.git] / src / lib / content_part.h
1
2 /*
3     Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
4
5     This file is part of DCP-o-matic.
6
7     DCP-o-matic is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     DCP-o-matic is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
19
20 */
21
22 #ifndef DCPOMATIC_CONTENT_PART_H
23 #define DCPOMATIC_CONTENT_PART_H
24
25 #include "content.h"
26 #include <boost/weak_ptr.hpp>
27 #include <boost/thread/mutex.hpp>
28
29 class Content;
30 class Film;
31
32 class ContentPart
33 {
34 public:
35         explicit ContentPart (Content* parent)
36                 : _parent (parent)
37         {}
38
39 protected:
40         template <class T>
41         void
42         maybe_set (T& member, T new_value, int property) const
43         {
44                 {
45                         boost::mutex::scoped_lock lm (_mutex);
46                         if (member == new_value) {
47                                 return;
48                         }
49                         member = new_value;
50                 }
51                 _parent->signal_changed (property);
52         }
53
54         template <class T>
55         void
56         maybe_set (boost::optional<T>& member, T new_value, int property) const
57         {
58                 {
59                         boost::mutex::scoped_lock lm (_mutex);
60                         if (member && member.get() == new_value) {
61                                 return;
62                         }
63                         member = new_value;
64                 }
65                 _parent->signal_changed (property);
66         }
67
68         Content* _parent;
69         mutable boost::mutex _mutex;
70 };
71
72 #endif