Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <string> 7 : #include <unordered_set> 8 : #include <vector> 9 : 10 : #include "DataStructures/DataBox/TagName.hpp" 11 : #include "Options/Context.hpp" 12 : #include "Options/ParseError.hpp" 13 : #include "Utilities/Algorithm.hpp" 14 : #include "Utilities/StdHelpers.hpp" 15 : #include "Utilities/TMPL.hpp" 16 : 17 : namespace db { 18 : 19 : /*! 20 : * \brief Validate that the selected names are a subset of the given tags. 21 : * 22 : * The possible choices for the selection are the `db::tag_name`s of the `Tags`. 23 : * 24 : * \tparam Tags List of possible tags. 25 : * \param selected_names Names to validate. 26 : * \param context Options context for error reporting. 27 : */ 28 : template <typename Tags> 29 1 : void validate_selection(const std::vector<std::string>& selected_names, 30 : const Options::Context& context) { 31 : using ::operator<<; 32 : std::unordered_set<std::string> valid_names{}; 33 : tmpl::for_each<Tags>([&valid_names](auto tag_v) { 34 : using tag = tmpl::type_from<std::decay_t<decltype(tag_v)>>; 35 : valid_names.insert(db::tag_name<tag>()); 36 : }); 37 : for (const auto& name : selected_names) { 38 : if (valid_names.find(name) == valid_names.end()) { 39 : PARSE_ERROR(context, "Invalid selection: " << name 40 : << ". Possible choices are: " 41 : << valid_names << "."); 42 : } 43 : if (alg::count(selected_names, name) != 1) { 44 : PARSE_ERROR(context, name << " specified multiple times"); 45 : } 46 : } 47 : } 48 : 49 : } // namespace db