MADARA  3.1.8
FlexMap.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_CONTAINERS_FLEX_MAP_H_
3 #define _MADARA_CONTAINERS_FLEX_MAP_H_
4 
5 #include <vector>
6 #include <map>
7 #include <string>
8 #include "madara/LockType.h"
12 #include "String.h"
13 #include "Integer.h"
14 #include "Double.h"
15 #include "Map.h"
16 #include "StringVector.h"
17 #include "DoubleVector.h"
18 #include "IntegerVector.h"
19 #include "BufferVector.h"
20 #include "NativeDoubleVector.h"
21 #include "NativeIntegerVector.h"
22 #include "BaseContainer.h"
23 
32 namespace madara
33 {
34  namespace knowledge
35  {
36  namespace containers
37  {
38  class FlexMap;
39 
53  class MADARA_Export FlexMap : public BaseContainer
54  {
55  public:
61  FlexMap (const KnowledgeUpdateSettings & settings =
63  const std::string & delimiter = ".");
64 
72  FlexMap (const std::string & name,
74  const KnowledgeUpdateSettings & settings =
76  const std::string & delimiter = ".");
77 
85  FlexMap (const std::string & name,
86  Variables & knowledge,
87  const KnowledgeUpdateSettings & settings =
89  const std::string & delimiter = ".");
90 
94  FlexMap (const FlexMap & rhs);
95 
99  virtual ~FlexMap ();
100 
105  void modify (void);
106 
111  void operator= (const FlexMap & rhs);
112 
121  void exchange (FlexMap & other,
122  bool refresh_keys = true, bool delete_keys = true);
123 
129  FlexMap operator[] (const std::string & key);
130 
136  FlexMap operator[] (size_t index);
137 
143  knowledge::KnowledgeRecord to_record (void) const;
144 
149  void to_container (BufferVector & target) const;
150 
155  void to_container (DoubleVector & target) const;
156 
161  void to_container (IntegerVector & target) const;
162 
167  void to_container (NativeDoubleVector & target) const;
168 
173  void to_container (NativeIntegerVector & target) const;
174 
179  void to_container (StringVector & target) const;
180 
185  void to_container (Double & target) const;
186 
191  void to_container (Integer & target) const;
192 
197  void to_container (String & target) const;
198 
203  void to_container (Map & target) const;
204 
209  knowledge::KnowledgeRecord::Integer to_integer (void) const;
210 
215  double to_double (void) const;
216 
221  std::string to_string (void) const;
222 
229  size_t size (bool first_level_keys_only = true) const;
230 
238  void keys (std::vector <std::string> & curkeys,
239  bool first_level_keys_only = true) const;
240 
252  bool exists (
253  const std::string & key, bool first_level_key = false) const;
254 
259  bool exists (void) const;
260 
266  void set_name (const std::string & var_name,
267  KnowledgeBase & knowledge);
268 
274  void set_name (const std::string & var_name,
275  Variables & knowledge);
276 
284  void set_delimiter (const std::string & delimiter);
285 
293  std::string get_delimiter (void);
294 
298  void clear (void);
299 
305  void erase (const std::string & key, bool delete_subkeys = true);
306 
311  bool is_true (void) const;
312 
317  bool is_false (void) const;
318 
323  int read_file (const std::string & filename);
324 
330  int read_file (
331  const std::string & filename,
332  const KnowledgeUpdateSettings & settings);
333 
341  int set (
343 
349  void operator= (
351 
357  void operator= (int value);
358 
364  void operator= (
365  double value);
366 
372  void operator= (
373  const std::string value);
374 
382  void operator= (const std::vector <KnowledgeRecord::Integer> & value);
383 
391  void operator= (const std::vector <double> & value);
392 
401  int set (KnowledgeRecord::Integer value,
402  const KnowledgeUpdateSettings & settings);
403 
412  int set_index (size_t index,
414 
424  int set_index (size_t index,
426  const KnowledgeUpdateSettings & settings);
427 
436  int set (const knowledge::KnowledgeRecord::Integer * value,
437  uint32_t size);
438 
448  int set (const knowledge::KnowledgeRecord::Integer * value,
449  uint32_t size,
450  const KnowledgeUpdateSettings & settings);
451 
459  int set (const std::vector <KnowledgeRecord::Integer> & value);
460 
469  int set (const std::vector <KnowledgeRecord::Integer> & value,
470  const KnowledgeUpdateSettings & settings);
471 
479  int set (double value);
480 
489  int set (double value,
490  const KnowledgeUpdateSettings & settings);
491 
500  int set_index (size_t index, double value);
501 
511  int set_index (size_t index, double value,
512  const KnowledgeUpdateSettings & settings);
513 
522  int set (const double * value,
523  uint32_t size);
524 
534  int set (const double * value,
535  uint32_t size,
536  const KnowledgeUpdateSettings & settings);
537 
545  int set (const std::vector <double> & value);
546 
555  int set (const std::vector <double> & value,
556  const KnowledgeUpdateSettings & settings);
557 
565  int set (const std::string & value);
566 
575  int set (const std::string & value,
576  const KnowledgeUpdateSettings & settings);
577 
584  int set_file (const unsigned char * value, size_t size);
585 
593  int set_file (const unsigned char * value, size_t size,
594  const KnowledgeUpdateSettings & settings);
595 
602  int set_jpeg (const unsigned char * value, size_t size);
603 
611  int set_jpeg (const unsigned char * value, size_t size,
612  const KnowledgeUpdateSettings & settings);
613 
620  void set_quality (uint32_t quality,
621  const KnowledgeReferenceSettings & settings =
623 
633  std::string get_debug_info (void);
634 
640  virtual BaseContainer * clone (void) const;
641 
642  private:
643 
648  virtual bool is_true_ (void) const;
649 
654  virtual bool is_false_ (void) const;
655 
664  virtual void modify_ (void);
665 
675  virtual std::string get_debug_info_ (void);
676 
678  void update_variable (void) const;
679 
681  typedef std::map <std::string, VariableReference> InternalFlexMap;
682 
687 
692 
697  };
698  }
699  }
700 }
701 
702 #endif // _MADARA_CONTAINERS_FLEX_MAP_H_
This class encapsulates an entry in a KnowledgeBase.
This class stores a double within a variable context.
Definition: Double.h:32
This class stores a vector of character buffers.
Definition: BufferVector.h:31
This class stores a vector of doubles inside of KaRL.
MADARA_Export int read_file(const std::string &filename, void *&buffer, size_t &size, bool add_zero_char=false)
Reads a file into a provided void pointer.
Definition: Utility.cpp:747
This class stores a string within a variable context.
Definition: String.h:31
This class stores variables and their values for use by any entity needing state information in a thr...
This class stores a vector of integers inside of KaRL.
Definition: IntegerVector.h:31
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: FlexMap.h:686
Optimized reference to a variable within the knowledge base.
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
This class stores a vector of strings inside of KaRL.
Definition: StringVector.h:31
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:44
This class stores an integer within a variable context.
Definition: Integer.h:31
This class stores a vector of doubles inside of KaRL.
static constexpr struct madara::knowledge::tags::string_t string
std::string delimiter_
Delimiter for the prefix to subvars.
Definition: FlexMap.h:696
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.
VariableReference variable_
The current location variable.
Definition: FlexMap.h:691
Settings for applying knowledge updates.
This class stores a vector of doubles inside of KaRL.
Definition: DoubleVector.h:31
std::map< std::string, VariableReference > InternalFlexMap
internal map of variable references
Definition: FlexMap.h:681
Provides an interface for external functions into the MADARA KaRL variable settings.
This class stores a flexible map of strings and ints to KaRL variables FlexMap differs from Map in th...
Definition: FlexMap.h:53
This class is an abstract base class for all containers.
Definition: BaseContainer.h:33