MADARA  3.2.3
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:
40  Map (const KnowledgeUpdateSettings & settings =
42  const std::string & delimiter = ".");
43 
51  Map (const std::string & name,
53  const KnowledgeUpdateSettings & settings =
55  const std::string & delimiter = ".");
56 
64  Map (const std::string & name,
65  Variables & knowledge,
66  const KnowledgeUpdateSettings & settings =
68  const std::string & delimiter = ".");
69 
73  Map (const Map & rhs);
74 
78  virtual ~Map ();
79 
84  void modify (void);
85 
91  void modify (const std::string & index);
92 
93 
98  void operator= (const Map & rhs);
99 
108  void exchange (Map & other,
109  bool refresh_keys = true, bool delete_keys = true);
110 
117  knowledge::KnowledgeRecord operator[] (const std::string & key);
118 
127  knowledge::KnowledgeRecord to_record (const std::string & key);
128 
133  size_t size (void) const;
134 
140  std::vector <std::string> sync_keys (void);
141 
146  void keys (std::vector <std::string> & curkeys) const;
147 
153  bool exists (const std::string & key) const;
154 
160  bool has_prefix (const std::string & prefix) const;
161 
168  void set_name (const std::string & var_name,
169  KnowledgeBase & knowledge, bool sync = true);
170 
177  void set_name (const std::string & var_name,
178  Variables & knowledge, bool sync = true);
179 
189  void set_delimiter (const std::string & delimiter,
190  bool sync = true);
191 
199  std::string get_delimiter (void);
200 
206  void clear (bool clear_knowledge = true);
207 
212  void erase (const std::string & key);
213 
219  int read_file (const std::string & key,
220  const std::string & filename);
221 
228  int read_file (const std::string & key,
229  const std::string & filename,
230  const KnowledgeUpdateSettings & settings);
231 
240  int set (const std::string & key,
243 
253  int set (const std::string & key,
255  const KnowledgeUpdateSettings & settings);
256 
266  int set_index (const std::string & key,
267  size_t index,
269 
280  int set_index (const std::string & key,
281  size_t index,
283  const KnowledgeUpdateSettings & settings);
284 
294  int set (const std::string & key,
296  uint32_t size);
297 
308  int set (const std::string & key,
310  uint32_t size,
311  const KnowledgeUpdateSettings & settings);
312 
321  int set (const std::string & key,
322  const std::vector <KnowledgeRecord::Integer> & value);
323 
333  int set (const std::string & key,
334  const std::vector <KnowledgeRecord::Integer> & value,
335  const KnowledgeUpdateSettings & settings);
336 
345  int set (const std::string & key, double value);
346 
356  int set (const std::string & key, double value,
357  const KnowledgeUpdateSettings & settings);
358 
368  int set_index (const std::string & key,
369  size_t index,
370  double value);
371 
382  int set_index (const std::string & key,
383  size_t index,
384  double value,
385  const KnowledgeUpdateSettings & settings);
386 
396  int set (const std::string & key,
397  const double * value,
398  uint32_t size);
399 
410  int set (const std::string & key,
411  const double * value,
412  uint32_t size,
413  const KnowledgeUpdateSettings & settings);
414 
423  int set (const std::string & key,
424  const std::vector <double> & value);
425 
435  int set (const std::string & key,
436  const std::vector <double> & value,
437  const KnowledgeUpdateSettings & settings);
438 
447  int set (const std::string & key, const std::string & value);
448 
458  int set (const std::string & key, const std::string & value,
459  const KnowledgeUpdateSettings & settings);
460 
468  int set_file (const std::string & key,
469  const unsigned char * value, size_t size);
470 
479  int set_file (const std::string & key,
480  const unsigned char * value, size_t size,
481  const KnowledgeUpdateSettings & settings);
482 
490  int set_jpeg (const std::string & key,
491  const unsigned char * value, size_t size);
492 
501  int set_jpeg (const std::string & key,
502  const unsigned char * value, size_t size,
503  const KnowledgeUpdateSettings & settings);
504 
512  void set_quality (const std::string & key, uint32_t quality,
513  const KnowledgeReferenceSettings & settings =
515 
525  std::string get_debug_info (void);
526 
532  virtual BaseContainer * clone (void) const;
533 
538  bool is_true (void) const;
539 
544  bool is_false (void) const;
545 
546  private:
547 
552  virtual bool is_true_ (void) const;
553 
558  virtual bool is_false_ (void) const;
559 
568  virtual void modify_ (void);
569 
579  virtual std::string get_debug_info_ (void);
580 
582  typedef std::map <std::string, VariableReference> InternalMap;
583 
588 
592  InternalMap map_;
593 
598  };
599  }
600  }
601 }
602 
603 
604 
605 
606 #endif // _MADARA_CONTAINERS_MAP_H_
This class encapsulates an entry in a KnowledgeBase.
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Map.h:587
std::map< std::string, VariableReference > InternalMap
internal map of variable references
Definition: Map.h:582
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:480
This class stores variables and their values for use by any entity needing state information in a thr...
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
std::string delimiter_
Delimiter for the prefix to subvars.
Definition: Map.h:597
static struct madara::knowledge::tags::string_t string
This class stores a map of strings to KaRL variables.
Definition: Map.h:32
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
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.
Provides functions and classes for the distributed knowledge base.
Settings for applying knowledge updates.
Copyright (c) 2015 Carnegie Mellon University.
Settings for applying knowledge updates.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
Definition: BaseContainer.h:33
InternalMap map_
Map of variables to values.
Definition: Map.h:592