]> git.sesse.net Git - casparcg/blob - core/help/help_repository.cpp
Fix a few Clang warnings.
[casparcg] / core / help / help_repository.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Helge Norberg, helge.norberg@svt.se
20 */
21
22 #include "help_repository.h"
23 #include "help_sink.h"
24
25 #include <common/except.h>
26
27 #include <boost/range/adaptor/filtered.hpp>
28 #include <boost/algorithm/string.hpp>
29
30 #include <algorithm>
31 #include <utility>
32
33 namespace caspar { namespace core {
34
35 typedef std::pair<std::wstring, help_item_describer> help_item;
36
37 struct help_repository::impl
38 {
39         std::vector<std::pair<help_item, std::set<std::wstring>>> items;
40
41         static void help(const help_repository& self, help_item item, help_sink& sink)
42         {
43                 sink.begin_item(item.first);
44                 item.second(sink, self);
45                 sink.end_item();
46         }
47 };
48
49
50 help_repository::help_repository()
51         : impl_(new impl)
52 {
53 }
54
55 void help_repository::register_item(std::set<std::wstring> tags, std::wstring name, help_item_describer describer)
56 {
57         impl_->items.push_back(std::make_pair(help_item(name, describer), tags));
58 }
59
60 void help_repository::help(std::set<std::wstring> tags, help_sink& sink) const
61 {
62         for (auto& item : impl_->items)
63         {
64                 if (std::includes(item.second.begin(), item.second.end(), tags.begin(), tags.end()))
65                         impl::help(*this, item.first, sink);
66         }
67 }
68
69 void help_repository::help(std::set<std::wstring> tags, std::wstring name, help_sink& sink) const
70 {
71         auto found = impl_->items | boost::adaptors::filtered([&](const std::pair<help_item, std::set<std::wstring>>& item)
72         {
73                 return boost::iequals(item.first.first, name) && std::includes(
74                                 item.second.begin(), item.second.end(),
75                                 tags.begin(), tags.end());
76         });
77
78         if (found.empty())
79                 CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Could not find help item " + name));
80
81         for (auto& item : found)
82         {
83                 if (std::includes(item.second.begin(), item.second.end(), tags.begin(), tags.end()))
84                         impl::help(*this, item.first, sink);
85         }
86 }
87
88 }}