MADARA  3.4.1
FragmentsToFilesFilter.h
Go to the documentation of this file.
1 #ifndef _MADARA_FILTERS_FRAGMENTS_TO_FILES_FILTER_H_
2 #define _MADARA_FILTERS_FRAGMENTS_TO_FILES_FILTER_H_
3 
4 #ifndef BOOST_NO_CXX11_SCOPED_ENUMS
5 #define BOOST_NO_CXX11_SCOPED_ENUMS
6 #endif
7 
8 #include <string>
9 #include <vector>
12 #include "madara/utility/Utility.h"
17 #include "madara/MadaraExport.h"
18 
19 namespace madara
20 {
21 namespace filters
22 {
30 {
31 public:
36 
40  virtual ~FragmentsToFilesFilter() = default;
41 
46  MADARA_EXPORT virtual void filter(knowledge::KnowledgeMap& records,
48 
55  inline void set_dir_mapping(
56  const std::string& variable_prefix, const std::string& directory)
57  {
60  "FragmentsToFilesFilter::set_dir_mapping: "
61  "attempting to map %s -> %s\n",
62  variable_prefix.c_str(), directory.c_str())
63 
64  if (variable_prefix != "" && directory != "")
65  {
66  map_[variable_prefix] = directory;
67  }
68  }
69 
75  inline std::string get_dir_mapping(const std::string& variable_prefix)
76  {
77  auto found = map_.find(variable_prefix);
78 
79  if (found != map_.end())
80  {
81  return found->second;
82  }
83  else
84  {
85  return "";
86  }
87  }
88 
93  inline void enable_clear_fragments(void)
94  {
95  clear_fragments_ = true;
96  }
97 
102  inline void disable_clear_fragments(void)
103  {
104  clear_fragments_ = false;
105  }
106 
109 
111  std::map<std::string, std::string> map_;
112 };
113 }
114 }
115 
116 #endif // _MADARA_FILTERS_FRAGMENTS_TO_FILES_FILTER_H_
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
Abstract base class for implementing aggregate record filters via a functor interface.
Receives fragments and saves them to files.
std::map< std::string, std::string > map_
map of variable prefixes to directories
bool clear_fragments_
if true, clear fragments after sent to file
std::string get_dir_mapping(const std::string &variable_prefix)
Gets the directory associated with the variable prefix.
void enable_clear_fragments(void)
Enables the clear fragments flag.
void set_dir_mapping(const std::string &variable_prefix, const std::string &directory)
Sets a mapping between a variable prefix and a directory.
void disable_clear_fragments(void)
Disables the clear fragments flag.
virtual MADARA_EXPORT void filter(knowledge::KnowledgeMap &records, const transport::TransportContext &, knowledge::Variables &)
Filters the fragments and converts them to files.
virtual ~FragmentsToFilesFilter()=default
Destructor.
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
Provides context about the transport.
constexpr string_t string
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
Definition: GetRecord.h:121
::std::map< std::string, KnowledgeRecord > KnowledgeMap
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
Copyright(c) 2020 Galois.