2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG 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 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG 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.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
22 #include "help_repository.h"
23 #include "help_sink.h"
25 #include <common/except.h>
27 #include <boost/range/adaptor/filtered.hpp>
28 #include <boost/algorithm/string.hpp>
33 namespace caspar { namespace core {
35 typedef std::pair<std::wstring, help_item_describer> help_item;
37 struct help_repository::impl
39 std::vector<std::pair<help_item, std::set<std::wstring>>> items;
41 static void help(const help_repository& self, help_item item, help_sink& sink)
43 sink.begin_item(item.first);
44 item.second(sink, self);
50 help_repository::help_repository()
55 void help_repository::register_item(std::set<std::wstring> tags, std::wstring name, help_item_describer describer)
57 impl_->items.push_back(std::make_pair(help_item(name, describer), tags));
60 void help_repository::help(std::set<std::wstring> tags, help_sink& sink) const
62 for (auto& item : impl_->items)
64 if (std::includes(item.second.begin(), item.second.end(), tags.begin(), tags.end()))
65 impl::help(*this, item.first, sink);
69 void help_repository::help(std::set<std::wstring> tags, std::wstring name, help_sink& sink) const
71 auto found = impl_->items | boost::adaptors::filtered([&](const std::pair<help_item, std::set<std::wstring>>& item)
73 return boost::iequals(item.first.first, name) && std::includes(
74 item.second.begin(), item.second.end(),
75 tags.begin(), tags.end());
79 CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Could not find help item " + name));
81 for (auto& item : found)
83 if (std::includes(item.second.begin(), item.second.end(), tags.begin(), tags.end()))
84 impl::help(*this, item.first, sink);