std::shared_ptr
[dcpomatic.git] / src / lib / dkdm_wrapper.h
1 /*
2     Copyright (C) 2017 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 <dcp/encrypted_kdm.h>
22 #include <libcxml/cxml.h>
23 #include <memory>
24
25
26 namespace xmlpp {
27         class Element;
28 }
29
30 class DKDMGroup;
31
32 class DKDMBase : public std::enable_shared_from_this<DKDMBase>
33 {
34 public:
35         virtual ~DKDMBase () {}
36         virtual std::string name () const = 0;
37         virtual void as_xml (xmlpp::Element *) const = 0;
38
39         static std::shared_ptr<DKDMBase> read (cxml::ConstNodePtr node);
40
41         std::shared_ptr<DKDMGroup> parent () const {
42                 return _parent;
43         }
44
45         void set_parent (std::shared_ptr<DKDMGroup> parent) {
46                 _parent = parent;
47         }
48
49 private:
50         std::shared_ptr<DKDMGroup> _parent;
51 };
52
53 class DKDM : public DKDMBase
54 {
55 public:
56         explicit DKDM (dcp::EncryptedKDM k)
57                 : _dkdm (k)
58         {}
59
60         std::string name () const;
61         void as_xml (xmlpp::Element *) const;
62
63         dcp::EncryptedKDM dkdm () const {
64                 return _dkdm;
65         }
66
67 private:
68         dcp::EncryptedKDM _dkdm;
69 };
70
71 class DKDMGroup : public DKDMBase
72 {
73 public:
74         explicit DKDMGroup (std::string name)
75                 : _name (name)
76         {}
77
78         std::string name () const {
79                 return _name;
80         }
81
82         void as_xml (xmlpp::Element *) const;
83
84         std::list<std::shared_ptr<DKDMBase> > children () const {
85                 return _children;
86         }
87
88         void add (std::shared_ptr<DKDMBase> child, std::shared_ptr<DKDM> previous = std::shared_ptr<DKDM> ());
89         void remove (std::shared_ptr<DKDMBase> child);
90
91 private:
92         std::string _name;
93         std::list<std::shared_ptr<DKDMBase> > _children;
94 };