diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-02-04 00:08:00 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-05-24 12:23:59 +0100 |
| commit | bfb8c684886592f325f85c490d9f0aafd7056734 (patch) | |
| tree | 53b7690652c8e963faf4417af8472d509fb880f7 /src/lib/dkdm_wrapper.cc | |
| parent | c94d763e07d9e7b029091e1ea64ba4f7758b3d5b (diff) | |
Missing files.
Diffstat (limited to 'src/lib/dkdm_wrapper.cc')
| -rw-r--r-- | src/lib/dkdm_wrapper.cc | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/lib/dkdm_wrapper.cc b/src/lib/dkdm_wrapper.cc new file mode 100644 index 000000000..316a0581e --- /dev/null +++ b/src/lib/dkdm_wrapper.cc @@ -0,0 +1,93 @@ +/* + Copyright (C) 2017 Carl Hetherington <cth@carlh.net> + + 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 <http://www.gnu.org/licenses/>. + +*/ + +#include "compose.hpp" +#include "dkdm_wrapper.h" +#include "dcpomatic_assert.h" +#include <libxml++/libxml++.h> +#include <boost/foreach.hpp> + +using std::string; +using std::list; +using boost::shared_ptr; +using boost::dynamic_pointer_cast; + +shared_ptr<DKDMBase> +DKDMBase::read (cxml::ConstNodePtr node) +{ + if (node->name() == "DKDM") { + return shared_ptr<DKDM> (new DKDM (dcp::EncryptedKDM (node->content ()))); + } else if (node->name() == "DKDMGroup") { + shared_ptr<DKDMGroup> group (new DKDMGroup (node->string_attribute ("Name"))); + BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children()) { + shared_ptr<DKDMBase> c = read (i); + if (c) { + group->add (c); + } + } + return group; + } + + return shared_ptr<DKDMBase> (); +} + +string +DKDM::name () const +{ + return String::compose ("%1 (%2)", _dkdm.content_title_text(), _dkdm.cpl_id()); +} + +void +DKDM::as_xml (xmlpp::Element* node) const +{ + node->add_child("DKDM")->add_child_text (_dkdm.as_xml ()); +} + +void +DKDMGroup::as_xml (xmlpp::Element* node) const +{ + xmlpp::Element* f = node->add_child("DKDMGroup"); + f->set_attribute ("Name", _name); + BOOST_FOREACH (shared_ptr<DKDMBase> i, _children) { + i->as_xml (f); + } +} + +void +DKDMGroup::add (shared_ptr<DKDMBase> child) +{ + DCPOMATIC_ASSERT (child); + _children.push_back (child); +} + +void +DKDMGroup::remove (shared_ptr<DKDMBase> child) +{ + for (list<shared_ptr<DKDMBase> >::iterator i = _children.begin(); i != _children.end(); ++i) { + if (*i == child) { + _children.erase (i); + return; + } + shared_ptr<DKDMGroup> g = dynamic_pointer_cast<DKDMGroup> (*i); + if (g) { + g->remove (child); + } + } +} |
