MADARA  3.4.1
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:
62  const std::string& delimiter = ".");
63 
73  const std::string& delimiter = ".");
74 
82  FlexMap(const std::string& name, Variables& knowledge,
84  const std::string& delimiter = ".");
85 
89  FlexMap(const FlexMap& rhs);
90 
94  virtual ~FlexMap();
95 
100  void modify(void);
101 
106  void operator=(const FlexMap& rhs);
107 
116  void exchange(
117  FlexMap& other, bool refresh_keys = true, bool delete_keys = true);
118 
124  FlexMap operator[](const std::string& key);
125 
131  FlexMap operator[](size_t index);
132 
140  knowledge::KnowledgeRecord to_record(
141  const KnowledgeRecord& default_value = KnowledgeRecord(0)) const;
142 
147  void to_container(BufferVector& target) const;
148 
153  void to_container(DoubleVector& target) const;
154 
159  void to_container(IntegerVector& target) const;
160 
165  void to_container(NativeDoubleVector& target) const;
166 
171  void to_container(NativeIntegerVector& target) const;
172 
177  void to_container(StringVector& target) const;
178 
183  void to_container(Double& target) const;
184 
189  void to_container(Integer& target) const;
190 
195  void to_container(String& target) const;
196 
201  void to_container(Map& target) const;
202 
210  KnowledgeRecord::Integer default_value = 0) const;
211 
218  double to_double(double default_value = 0.0) const;
219 
226  std::string to_string(const std::string& default_value = "") const;
227 
234  size_t size(bool first_level_keys_only = true) const;
235 
243  void keys(std::vector<std::string>& curkeys,
244  bool first_level_keys_only = true) const;
245 
257  bool exists(const std::string& key, bool first_level_key = false) const;
258 
263  bool exists(void) const;
264 
270  void set_name(const std::string& var_name, KnowledgeBase& knowledge);
271 
277  void set_name(const std::string& var_name, Variables& knowledge);
278 
286  void set_delimiter(const std::string& delimiter);
287 
295  std::string get_delimiter(void);
296 
300  void clear(void);
301 
307  void erase(const std::string& key, bool delete_subkeys = true);
308 
313  bool is_true(void) const;
314 
319  bool is_false(void) const;
320 
325  int read_file(const std::string& filename);
326 
332  int read_file(
333  const std::string& filename, const KnowledgeUpdateSettings& settings);
334 
344 
350  void operator=(knowledge::KnowledgeRecord::Integer value);
351 
357  void operator=(int value);
358 
364  void operator=(double value);
365 
371  void operator=(const std::string value);
372 
380  void operator=(const std::vector<KnowledgeRecord::Integer>& value);
381 
389  void operator=(const std::vector<double>& value);
390 
399  int set(
400  KnowledgeRecord::Integer value, const KnowledgeUpdateSettings& settings);
401 
410  int set_index(size_t index, knowledge::KnowledgeRecord::Integer value);
411 
421  int set_index(size_t index, knowledge::KnowledgeRecord::Integer value,
422  const KnowledgeUpdateSettings& settings);
423 
432  int set(const knowledge::KnowledgeRecord::Integer* value, uint32_t size);
433 
443  int set(const knowledge::KnowledgeRecord::Integer* value, uint32_t size,
444  const KnowledgeUpdateSettings& settings);
445 
453  int set(const std::vector<KnowledgeRecord::Integer>& value);
454 
463  int set(const std::vector<KnowledgeRecord::Integer>& value,
464  const KnowledgeUpdateSettings& settings);
465 
473  int set(double value);
474 
483  int set(double value, const KnowledgeUpdateSettings& settings);
484 
493  int set_index(size_t index, double value);
494 
504  int set_index(
505  size_t index, double value, const KnowledgeUpdateSettings& settings);
506 
515  int set(const double* value, uint32_t size);
516 
526  int set(const double* value, uint32_t size,
527  const KnowledgeUpdateSettings& settings);
528 
536  int set(const std::vector<double>& value);
537 
546  int set(const std::vector<double>& value,
547  const KnowledgeUpdateSettings& settings);
548 
556  int set(const std::string& value);
557 
566  int set(const std::string& value, const KnowledgeUpdateSettings& settings);
567 
574  int set_file(const unsigned char* value, size_t size);
575 
583  int set_file(const unsigned char* value, size_t size,
584  const KnowledgeUpdateSettings& settings);
585 
592  int set_jpeg(const unsigned char* value, size_t size);
593 
601  int set_jpeg(const unsigned char* value, size_t size,
602  const KnowledgeUpdateSettings& settings);
603 
610  void set_quality(uint32_t quality,
612  false));
613 
623  std::string get_debug_info(void);
624 
630  virtual BaseContainer* clone(void) const;
631 
632 private:
637  virtual bool is_true_(void) const;
638 
643  virtual bool is_false_(void) const;
644 
653  virtual void modify_(void);
654 
664  virtual std::string get_debug_info_(void);
665 
667  void update_variable(void) const;
668 
670  typedef std::map<std::string, VariableReference> InternalFlexMap;
671 
676 
681 
686 };
687 }
688 }
689 }
690 
691 #endif // _MADARA_CONTAINERS_FLEX_MAP_H_
madara::knowledge::KnowledgeRecord KnowledgeRecord
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...
Optimized reference to a variable within the knowledge base.
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 vector of character buffers.
Definition: BufferVector.h:32
This class stores a vector of doubles inside of KaRL.
Definition: DoubleVector.h:32
This class stores a double within a variable context.
Definition: Double.h:33
This class stores a flexible map of strings and ints to KaRL variables FlexMap differs from Map in th...
Definition: FlexMap.h:54
std::string delimiter_
Delimiter for the prefix to subvars.
Definition: FlexMap.h:685
VariableReference variable_
The current location variable.
Definition: FlexMap.h:680
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: FlexMap.h:675
std::map< std::string, VariableReference > InternalFlexMap
internal map of variable references
Definition: FlexMap.h:670
This class stores a vector of integers inside of KaRL.
Definition: IntegerVector.h:32
This class stores an integer within a variable context.
Definition: Integer.h:32
This class stores a map of strings to KaRL variables.
Definition: Map.h:33
This class stores a vector of doubles inside of KaRL.
This class stores a vector of doubles inside of KaRL.
This class stores a vector of strings inside of KaRL.
Definition: StringVector.h:32
This class stores a string within a variable context.
Definition: String.h:32
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.