/* Copyright (C) 2017-2021 Carl Hetherington This file is part of DCP-o-matic. DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with DCP-o-matic. If not, see . */ #include #include #include namespace xmlpp { class Element; } class DKDMGroup; class DKDMBase : public std::enable_shared_from_this { public: virtual ~DKDMBase() {} virtual std::string name() const = 0; virtual void as_xml(xmlpp::Element *) const = 0; /** @return true if this thing is, or contains, any actual DKDM */ virtual bool contains_dkdm() const = 0; virtual std::vector all_dkdms() const = 0; static std::shared_ptr read(cxml::ConstNodePtr node); std::shared_ptr parent() const { return _parent; } void set_parent(std::shared_ptr parent) { _parent = parent; } private: std::shared_ptr _parent; }; class DKDM : public DKDMBase { public: explicit DKDM(dcp::EncryptedKDM k) : _dkdm(k) {} std::string name() const override; void as_xml(xmlpp::Element *) const override; bool contains_dkdm() const override { return true; } std::vector all_dkdms() const override { return { _dkdm }; } dcp::EncryptedKDM dkdm() const { return _dkdm; } private: dcp::EncryptedKDM _dkdm; }; class DKDMGroup : public DKDMBase { public: explicit DKDMGroup(std::string name) : _name(name) {} std::string name() const override { return _name; } void as_xml(xmlpp::Element *) const override; bool contains_dkdm() const override; std::vector all_dkdms() const override; std::list> children() const { return _children; } void add(std::shared_ptr child, std::shared_ptr previous = std::shared_ptr()); void remove(std::shared_ptr child); bool contains(std::string dkdm_id) const; private: std::string _name; std::list> _children; };