MADARA  3.2.3
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 
145  knowledge::KnowledgeRecord to_record (
146  const KnowledgeRecord & default_value = KnowledgeRecord(0)) const;
147 
152  void to_container (BufferVector & target) const;
153 
158  void to_container (DoubleVector & target) const;
159 
164  void to_container (IntegerVector & target) const;
165 
170  void to_container (NativeDoubleVector & target) const;
171 
176  void to_container (NativeIntegerVector & target) const;
177 
182  void to_container (StringVector & target) const;
183 
188  void to_container (Double & target) const;
189 
194  void to_container (Integer & target) const;
195 
200  void to_container (String & target) const;
201 
206  void to_container (Map & target) const;
207 
215  KnowledgeRecord::Integer default_value = 0) const;
216 
223  double to_double (double default_value = 0.0) const;
224 
231  std::string to_string (const std::string & default_value = "") const;
232 
239  size_t size (bool first_level_keys_only = true) const;
240 
248  void keys (std::vector <std::string> & curkeys,
249  bool first_level_keys_only = true) const;
250 
262  bool exists (
263  const std::string & key, bool first_level_key = false) const;
264 
269  bool exists (void) const;
270 
276  void set_name (const std::string & var_name,
277  KnowledgeBase & knowledge);
278 
284  void set_name (const std::string & var_name,
285  Variables & knowledge);
286 
294  void set_delimiter (const std::string & delimiter);
295 
303  std::string get_delimiter (void);
304 
308  void clear (void);
309 
315  void erase (const std::string & key, bool delete_subkeys = true);
316 
321  bool is_true (void) const;
322 
327  bool is_false (void) const;
328 
333  int read_file (const std::string & filename);
334 
340  int read_file (
341  const std::string & filename,
342  const KnowledgeUpdateSettings & settings);
343 
351  int set (
353 
359  void operator= (
361 
367  void operator= (int value);
368 
374  void operator= (
375  double value);
376 
382  void operator= (
383  const std::string value);
384 
392  void operator= (const std::vector <KnowledgeRecord::Integer> & value);
393 
401  void operator= (const std::vector <double> & value);
402 
411  int set (KnowledgeRecord::Integer value,
412  const KnowledgeUpdateSettings & settings);
413 
422  int set_index (size_t index,
424 
434  int set_index (size_t index,
436  const KnowledgeUpdateSettings & settings);
437 
446  int set (const knowledge::KnowledgeRecord::Integer * value,
447  uint32_t size);
448 
458  int set (const knowledge::KnowledgeRecord::Integer * value,
459  uint32_t size,
460  const KnowledgeUpdateSettings & settings);
461 
469  int set (const std::vector <KnowledgeRecord::Integer> & value);
470 
479  int set (const std::vector <KnowledgeRecord::Integer> & value,
480  const KnowledgeUpdateSettings & settings);
481 
489  int set (double value);
490 
499  int set (double value,
500  const KnowledgeUpdateSettings & settings);
501 
510  int set_index (size_t index, double value);
511 
521  int set_index (size_t index, double value,
522  const KnowledgeUpdateSettings & settings);
523 
532  int set (const double * value,
533  uint32_t size);
534 
544  int set (const double * value,
545  uint32_t size,
546  const KnowledgeUpdateSettings & settings);
547 
555  int set (const std::vector <double> & value);
556 
565  int set (const std::vector <double> & value,
566  const KnowledgeUpdateSettings & settings);
567 
575  int set (const std::string & value);
576 
585  int set (const std::string & value,
586  const KnowledgeUpdateSettings & settings);
587 
594  int set_file (const unsigned char * value, size_t size);
595 
603  int set_file (const unsigned char * value, size_t size,
604  const KnowledgeUpdateSettings & settings);
605 
612  int set_jpeg (const unsigned char * value, size_t size);
613 
621  int set_jpeg (const unsigned char * value, size_t size,
622  const KnowledgeUpdateSettings & settings);
623 
630  void set_quality (uint32_t quality,
631  const KnowledgeReferenceSettings & settings =
633 
643  std::string get_debug_info (void);
644 
650  virtual BaseContainer * clone (void) const;
651 
652  private:
653 
658  virtual bool is_true_ (void) const;
659 
664  virtual bool is_false_ (void) const;
665 
674  virtual void modify_ (void);
675 
685  virtual std::string get_debug_info_ (void);
686 
688  void update_variable (void) const;
689 
691  typedef std::map <std::string, VariableReference> InternalFlexMap;
692 
697 
702 
707  };
708  }
709  }
710 }
711 
712 #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::knowledge::KnowledgeRecord KnowledgeRecord
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 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:696
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
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
This class stores an integer within a variable context.
Definition: Integer.h:31
This class stores a vector of doubles inside of KaRL.
std::string delimiter_
Delimiter for the prefix to subvars.
Definition: FlexMap.h:706
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:701
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:691
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