3 #ifndef _MADARA_FILTERS_VARIABLEMAP_H_
4 #define _MADARA_FILTERS_VARIABLEMAP_H_
44 std::vector<std::string> splitters, tokens, pivots;
46 splitters.push_back(
"->");
47 splitters.push_back(
"\n");
51 if (tokens.size() % 2 == 0)
54 for (
size_t i = 0; i + 1 < tokens.size(); i += 2)
59 if (tokens[i] ==
"" || tokens[i + 1] ==
"")
64 "VariableMapFilter::process_config: ERROR: "
65 "configuration mappings has an empty map endpoint. "
66 "Unable to process config.\n")
69 "VariableMapFilter::process_config: ERROR: "
70 "configuration mappings has an empty map endpoint. "
71 "Unable to process config.");
80 map_[tokens[i]] = {tokens[i + 1], ref};
89 "VariableMapFilter::process_config: ERROR: "
90 "configuration mappings are incorrect. tokens.size=%d."
91 "Mappings must be in 'kb_var -> new_var' format, one each line. "
92 "Unable to process config.\n",
96 "VariableMapFilter::process_config: ERROR: "
97 "configuration mappings are incorrect. Unable to process "
141 std::pair<std::string, knowledge::VariableReference>>::iterator i =
144 for (; i !=
map_.end(); ++i)
147 i->second.second = vars.
get_ref(i->first);
152 for (
auto entry :
map_)
154 records[entry.second.first] = vars.
get(entry.second.second);
165 std::map<std::string, std::pair<std::string, knowledge::VariableReference>>
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
An exception for attempting to access an invalid context1.
Abstract base class for implementing aggregate record filters via a functor interface.
Filter for mapping variables in the KB into a filter's outgoing or incoming messages.
VariableMapFilter(const std::string &filename="")
Constructor.
void read_config(const std::string &filename)
Reads a config file and processes the contents.
virtual void filter(knowledge::KnowledgeMap &records, const transport::TransportContext &, knowledge::Variables &vars)
Adds to the counter.
void process_config(const std::string &config)
Processes mappings from a config file.
virtual ~VariableMapFilter()=default
Destructor.
std::map< std::string, std::pair< std::string, knowledge::VariableReference > > map_
Map of local KB variable to a variable to add and a VariableReference to the local KB variable.
Optimized reference to a variable within the knowledge base.
Provides an interface for external functions into the MADARA KaRL variable settings.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=knowledge::KnowledgeReferenceSettings(false))
Retrieves the value of a variable.
knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=knowledge::KnowledgeReferenceSettings(false))
Retrieves the value of a variable.
Provides context about the transport.
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
::std::map< std::string, KnowledgeRecord > KnowledgeMap
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
std::string file_to_string(const std::string &filename)
Reads a file into a string.
std::string & strip_white_space(std::string &input)
Strip all whitespace.
void tokenizer(const std::string &input, const ::std::vector< std::string > &splitters, ::std::vector< std::string > &tokens, ::std::vector< std::string > &pivots)
Split a string into tokens.
Copyright(c) 2020 Galois.