1 #ifndef _MADARA_UTILITY_NAMED_VECTOR_COMBINATOR_H_
2 #define _MADARA_UTILITY_NAMED_VECTOR_COMBINATOR_H_
60 const std::vector<std::string>& strings)
80 inline void merge(
const std::vector<std::string> & named_vectors,
81 std::vector<std::string> & result,
bool throw_on_missing =
true,
82 bool make_unique =
true,
bool clear_first =
true)
84 std::set<std::string> unique_list;
91 for(
auto name : named_vectors)
100 result.end(), found->second.begin(), found->second.end());
105 unique_list.insert(found->second.begin(), found->second.end());
108 else if(throw_on_missing)
110 std::stringstream buffer;
111 buffer <<
"madara::utility::NamedVectorCombinator: ";
112 buffer << name <<
" could not be found in mapped named vectors.";
120 result.insert(result.end(), unique_list.begin(), unique_list.end());
An exception for setting an invalid name in MADARA.
A helper class for combining named vectors of strings into vectors of unique strings.
void add(const std::string &name, const std::string &input)
Adds a vector of strings to the mapped vectors with a specific name.
std::map< std::string, std::vector< std::string > > named_vectors_
the mapping of named lists to their contents
void merge(const std::vector< std::string > &named_vectors, std::vector< std::string > &result, bool throw_on_missing=true, bool make_unique=true, bool clear_first=true)
Merges named vectors into a result vector.
void from_file(const std::string &name, const std::string &filename)
Reads a file containing strings separated by newlines into a named vector.
void add(const std::string &name, const std::vector< std::string > &strings)
Adds a vector of strings to the mapped vectors with a specific name.
NamedVectorCombinator()=default
Constructor.
Provides utility functions and classes for common tasks and needs.
std::string file_to_string(const std::string &filename)
Reads a file into a string.
std::vector< std::string > string_to_vector(const std::string &input, const std::string delimiter="\n", bool strip_whitespace=true)
Splits a string into a vector of strings by delimiter.
Copyright(c) 2020 Galois.