11b5bf6229b8713dffde89a777cd5181335136f6 from master; default colour conversions...
[dcpomatic.git] / src / lib / cinema.cc
index 7af4372f59981fe2b444a0286a829abf8bc88164..ce3077b2a041df9ab21e6600a59f4f770f78f164 100644 (file)
 
 */
 
-#include <libxml++/libxml++.h>
-#include <libcxml/cxml.h>
 #include "cinema.h"
+#include <libcxml/cxml.h>
+#include <libxml++/libxml++.h>
 
 using std::list;
 using boost::shared_ptr;
 
-Cinema::Cinema (shared_ptr<const cxml::Node> node)
+Cinema::Cinema (cxml::ConstNodePtr node)
+       : name (node->string_child ("Name"))
+       , email (node->string_child ("Email"))
 {
-       name = node->string_child ("Name");
-       email = node->string_child ("Email");
 
-       list<shared_ptr<cxml::Node> > s = node->node_children ("Screen");
-       for (list<shared_ptr<cxml::Node> >::iterator i = s.begin(); i != s.end(); ++i) {
+}
+
+/* This is necessary so that we can use shared_from_this in add_screen (which cannot be done from
+   a constructor)
+*/
+void
+Cinema::read_screens (cxml::ConstNodePtr node)
+{
+       list<cxml::NodePtr> s = node->node_children ("Screen");
+       for (list<cxml::NodePtr>::iterator i = s.begin(); i != s.end(); ++i) {
                add_screen (shared_ptr<Screen> (new Screen (*i)));
        }
 }
@@ -59,17 +67,21 @@ Cinema::remove_screen (shared_ptr<Screen> s)
        _screens.remove (s);
 }
 
-Screen::Screen (shared_ptr<const cxml::Node> node)
+Screen::Screen (cxml::ConstNodePtr node)
+       : name (node->string_child ("Name"))
 {
-       name = node->string_child ("Name");
-       certificate = shared_ptr<libdcp::Certificate> (new libdcp::Certificate (node->string_child ("Certificate")));
+       if (node->optional_string_child ("Certificate")) {
+               certificate = dcp::Certificate (node->string_child ("Certificate"));
+       }
 }
 
 void
 Screen::as_xml (xmlpp::Element* parent) const
 {
        parent->add_child("Name")->add_child_text (name);
-       parent->add_child("Certificate")->add_child_text (certificate->certificate (true));
+       if (certificate) {
+               parent->add_child("Certificate")->add_child_text (certificate->certificate (true));
+       }
 }