MADARA  3.4.1
madara::utility::NamedVectorCombinator Class Reference

A helper class for combining named vectors of strings into vectors of unique strings. More...

#include <NamedVectorCombinator.h>

Public Member Functions

 NamedVectorCombinator ()=default
 Constructor. More...
 
void add (const std::string &name, const std::string &input)
 Adds a vector of strings to the mapped vectors with a specific name. More...
 
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. More...
 
void from_file (const std::string &name, const std::string &filename)
 Reads a file containing strings separated by newlines into a named vector. More...
 
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. More...
 

Private Attributes

std::map< std::string, std::vector< std::string > > named_vectors_
 the mapping of named lists to their contents More...
 

Detailed Description

A helper class for combining named vectors of strings into vectors of unique strings.

Definition at line 24 of file NamedVectorCombinator.h.

Constructor & Destructor Documentation

◆ NamedVectorCombinator()

madara::utility::NamedVectorCombinator::NamedVectorCombinator ( )
default

Constructor.

Member Function Documentation

◆ add() [1/2]

void madara::utility::NamedVectorCombinator::add ( const std::string &  name,
const std::string &  input 
)
inline

Adds a vector of strings to the mapped vectors with a specific name.

Parameters
namethe name of the mapped vector to import into
inputa string containing newline-delimited strings to import

Definition at line 48 of file NamedVectorCombinator.h.

◆ add() [2/2]

void madara::utility::NamedVectorCombinator::add ( const std::string &  name,
const std::vector< std::string > &  strings 
)
inline

Adds a vector of strings to the mapped vectors with a specific name.

Parameters
namethe name of the mapped vector to import into
stringsa vector of strings to associate with the name

Definition at line 59 of file NamedVectorCombinator.h.

◆ from_file()

void madara::utility::NamedVectorCombinator::from_file ( const std::string &  name,
const std::string &  filename 
)
inline

Reads a file containing strings separated by newlines into a named vector.

Parameters
namethe name of the mapped vector to import into
filenamethe name of the file to read in the newline-delimited strings

Definition at line 38 of file NamedVectorCombinator.h.

◆ merge()

void madara::utility::NamedVectorCombinator::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 
)
inline

Merges named vectors into a result vector.

This is a useful function for building prefix lists for CheckpointSettings and other classes that have vectors of strings.

Parameters
named_vectorsa vector of named entities that you want to merge. Each string should exist in the known map by first calling from_file to create the lists
resultthe result of the merge
throw_on_missingif true, throw an exception if the named entity does not exist
make_uniqueif true, make sure the resulting merge is unique
clear_firstif true, clear the result before inserting
Exceptions
exceptions::NameExceptionif throw_on_missing and named vector contains an unknown mapping, throw this exception

Definition at line 80 of file NamedVectorCombinator.h.

Member Data Documentation

◆ named_vectors_

std::map<std::string, std::vector<std::string> > madara::utility::NamedVectorCombinator::named_vectors_
private

the mapping of named lists to their contents

Definition at line 131 of file NamedVectorCombinator.h.


The documentation for this class was generated from the following file: