Revert "Use make_shared<>."
[dcpomatic.git] / src / lib / cinema.cc
1 /*
2     Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "cinema.h"
22 #include "screen.h"
23 #include "dcpomatic_assert.h"
24 #include <libcxml/cxml.h>
25 #include <dcp/raw_convert.h>
26 #include <libxml++/libxml++.h>
27 #include <boost/foreach.hpp>
28 #include <iostream>
29
30 using std::list;
31 using std::string;
32 using boost::shared_ptr;
33
34 Cinema::Cinema (cxml::ConstNodePtr node)
35         : name (node->string_child ("Name"))
36         , notes (node->optional_string_child("Notes").get_value_or(""))
37 {
38         BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children("Email")) {
39                 emails.push_back (i->content ());
40         }
41
42         if (node->optional_number_child<int>("UTCOffset")) {
43                 _utc_offset_hour = node->number_child<int>("UTCOffset");
44         } else {
45                 _utc_offset_hour = node->optional_number_child<int>("UTCOffsetHour").get_value_or (0);
46         }
47
48         _utc_offset_minute = node->optional_number_child<int>("UTCOffsetMinute").get_value_or (0);
49 }
50
51 /* This is necessary so that we can use shared_from_this in add_screen (which cannot be done from
52    a constructor)
53 */
54 void
55 Cinema::read_screens (cxml::ConstNodePtr node)
56 {
57         list<cxml::NodePtr> s = node->node_children ("Screen");
58         for (list<cxml::NodePtr>::iterator i = s.begin(); i != s.end(); ++i) {
59                 add_screen (shared_ptr<Screen> (new Screen (*i)));
60         }
61 }
62
63 void
64 Cinema::as_xml (xmlpp::Element* parent) const
65 {
66         parent->add_child("Name")->add_child_text (name);
67
68         BOOST_FOREACH (string i, emails) {
69                 parent->add_child("Email")->add_child_text (i);
70         }
71
72         parent->add_child("Notes")->add_child_text (notes);
73
74         parent->add_child("UTCOffsetHour")->add_child_text (dcp::raw_convert<string> (_utc_offset_hour));
75         parent->add_child("UTCOffsetMinute")->add_child_text (dcp::raw_convert<string> (_utc_offset_minute));
76
77         BOOST_FOREACH (shared_ptr<Screen> i, _screens) {
78                 i->as_xml (parent->add_child ("Screen"));
79         }
80 }
81
82 void
83 Cinema::add_screen (shared_ptr<Screen> s)
84 {
85         s->cinema = shared_from_this ();
86         _screens.push_back (s);
87 }
88
89 void
90 Cinema::remove_screen (shared_ptr<Screen> s)
91 {
92         _screens.remove (s);
93 }
94
95 void
96 Cinema::set_utc_offset_hour (int h)
97 {
98         DCPOMATIC_ASSERT (h >= -11 && h <= 12);
99         _utc_offset_hour = h;
100 }
101
102 void
103 Cinema::set_utc_offset_minute (int m)
104 {
105         DCPOMATIC_ASSERT (m >= 0 && m <= 59);
106         _utc_offset_minute = m;
107 }