MADARA  3.4.1
Map.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_CONTAINERS_MAP_H_
3 #define _MADARA_CONTAINERS_MAP_H_
4 
5 #include <vector>
6 #include <map>
7 #include <string>
8 #include "madara/LockType.h"
12 #include "BaseContainer.h"
13 
22 namespace madara
23 {
24 namespace knowledge
25 {
26 namespace containers
27 {
32 class MADARA_EXPORT Map : public BaseContainer
33 {
34 public:
41  const std::string& delimiter = ".");
42 
50  Map(const std::string& name, KnowledgeBase& knowledge,
52  const std::string& delimiter = ".");
53 
61  Map(const std::string& name, Variables& knowledge,
63  const std::string& delimiter = ".");
64 
68  Map(const Map& rhs);
69 
73  virtual ~Map();
74 
79  void modify(void);
80 
86  void modify(const std::string& index);
87 
92  void operator=(const Map& rhs);
93 
102  void exchange(Map& other, bool refresh_keys = true, bool delete_keys = true);
103 
110  knowledge::KnowledgeRecord operator[](const std::string& key);
111 
120  knowledge::KnowledgeRecord to_record(const std::string& key);
121 
126  size_t size(void) const;
127 
133  std::vector<std::string> sync_keys(void);
134 
139  void keys(std::vector<std::string>& curkeys) const;
140 
146  bool exists(const std::string& key) const;
147 
153  bool has_prefix(const std::string& prefix) const;
154 
161  void set_name(
162  const std::string& var_name, KnowledgeBase& knowledge, bool sync = true);
163 
170  void set_name(
171  const std::string& var_name, Variables& knowledge, bool sync = true);
172 
182  void set_delimiter(const std::string& delimiter, bool sync = true);
183 
191  std::string get_delimiter(void);
192 
198  void clear(bool clear_knowledge = true);
199 
204  void reset(void);
205 
210  void erase(const std::string& key);
211 
217  int read_file(const std::string& key, const std::string& filename);
218 
225  int read_file(const std::string& key, const std::string& filename,
226  const KnowledgeUpdateSettings& settings);
227 
236  int set(const std::string& key,
239 
249  int set(const std::string& key,
251  const KnowledgeUpdateSettings& settings);
252 
262  int set(const std::string& key, const KnowledgeRecord& value,
264 
274  int set_index(const std::string& key, size_t index,
276 
287  int set_index(const std::string& key, size_t index,
289  const KnowledgeUpdateSettings& settings);
290 
300  int set(const std::string& key,
301  const madara::knowledge::KnowledgeRecord::Integer* value, uint32_t size);
302 
313  int set(const std::string& key,
314  const madara::knowledge::KnowledgeRecord::Integer* value, uint32_t size,
315  const KnowledgeUpdateSettings& settings);
316 
325  int set(const std::string& key,
326  const std::vector<KnowledgeRecord::Integer>& value);
327 
337  int set(const std::string& key,
338  const std::vector<KnowledgeRecord::Integer>& value,
339  const KnowledgeUpdateSettings& settings);
340 
349  int set(const std::string& key, double value);
350 
360  int set(const std::string& key, double value,
361  const KnowledgeUpdateSettings& settings);
362 
372  int set_index(const std::string& key, size_t index, double value);
373 
384  int set_index(const std::string& key, size_t index, double value,
385  const KnowledgeUpdateSettings& settings);
386 
396  int set(const std::string& key, const double* value, uint32_t size);
397 
408  int set(const std::string& key, const double* value, uint32_t size,
409  const KnowledgeUpdateSettings& settings);
410 
419  int set(const std::string& key, const std::vector<double>& value);
420 
430  int set(const std::string& key, const std::vector<double>& value,
431  const KnowledgeUpdateSettings& settings);
432 
441  int set(const std::string& key, const std::string& value);
442 
452  int set(const std::string& key, const std::string& value,
453  const KnowledgeUpdateSettings& settings);
454 
462  int set_file(const std::string& key, const unsigned char* value, size_t size);
463 
472  int set_file(const std::string& key, const unsigned char* value, size_t size,
473  const KnowledgeUpdateSettings& settings);
474 
482  int set_jpeg(const std::string& key, const unsigned char* value, size_t size);
483 
492  int set_jpeg(const std::string& key, const unsigned char* value, size_t size,
493  const KnowledgeUpdateSettings& settings);
494 
502  void set_quality(const std::string& key, uint32_t quality,
504  false));
505 
515  std::string get_debug_info(void);
516 
522  virtual BaseContainer* clone(void) const;
523 
528  bool is_true(void) const;
529 
534  bool is_false(void) const;
535 
536 private:
541  virtual bool is_true_(void) const;
542 
547  virtual bool is_false_(void) const;
548 
557  virtual void modify_(void);
558 
568  virtual std::string get_debug_info_(void);
569 
571  typedef std::map<std::string, VariableReference> InternalMap;
572 
577 
582 
587 };
588 }
589 }
590 }
591 
592 #endif // _MADARA_CONTAINERS_MAP_H_
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
This class encapsulates an entry in a KnowledgeBase.
Settings for applying knowledge updates.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
This class is an abstract base class for all containers.
Definition: BaseContainer.h:34
This class stores a map of strings to KaRL variables.
Definition: Map.h:33
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Map.h:576
std::map< std::string, VariableReference > InternalMap
internal map of variable references
Definition: Map.h:571
std::string delimiter_
Delimiter for the prefix to subvars.
Definition: Map.h:586
InternalMap map_
Map of variables to values.
Definition: Map.h:581
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
constexpr string_t string
Provides functions and classes for the distributed knowledge base.
MADARA_EXPORT bool exists(const char *originator, uint64_t clock, uint32_t update_number, OriginatorFragmentMap &map)
Checks if a fragment already exists within a fragment map.
int read_file(const std::string &filename, void *&buffer, size_t &size, bool add_zero_char)
Reads a file into a provided void pointer.
Definition: Utility.cpp:418
Copyright(c) 2020 Galois.