33 variable_(rhs.variable_),
34 delimiter_(rhs.delimiter_)
52 "Vector::is_true: checking for non-zero value\n");
54 if (variable_.is_valid())
56 result =
context_->get(variable_, keep_local).is_true();
60 "FlexMap::is_true: final result is %d\n", (
int)result);
76 if (!variable_.is_valid())
78 result =
context_->get(variable_, keep_local).is_true();
99 if (variable_.is_valid())
108 std::stringstream result;
110 result <<
"Flex Map: ";
115 MADARA_GUARD_TYPE guard(mutex_);
135 return get_debug_info();
148 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
151 this->name_ = rhs.
name_;
160 set(value, settings_);
170 set(value, settings_);
175 set(value, settings_);
179 const std::vector<KnowledgeRecord::Integer>& value)
181 set(value, settings_);
185 const std::vector<double>& value)
187 set(value, settings_);
197 MADARA_GUARD_TYPE guard(mutex_);
199 if (!variable_.is_valid())
201 this->update_variable();
206 return context_->get(variable_, settings_);
210 return default_value;
220 MADARA_GUARD_TYPE guard(mutex_);
222 if (!variable_.is_valid())
224 this->update_variable();
229 return context_->get(variable_, settings_).to_integer();
233 return default_value;
237 double default_value)
const
242 MADARA_GUARD_TYPE guard(mutex_);
244 if (!variable_.is_valid())
246 this->update_variable();
251 return context_->get(variable_, settings_).to_double();
255 return default_value;
264 MADARA_GUARD_TYPE guard(mutex_);
266 if (!variable_.is_valid())
268 this->update_variable();
273 return context_->get(variable_, settings_).to_string();
277 return default_value;
286 MADARA_GUARD_TYPE guard(mutex_);
303 MADARA_GUARD_TYPE guard(mutex_);
320 MADARA_GUARD_TYPE guard(mutex_);
337 MADARA_GUARD_TYPE guard(mutex_);
353 MADARA_GUARD_TYPE guard(mutex_);
369 MADARA_GUARD_TYPE guard(mutex_);
385 MADARA_GUARD_TYPE guard(mutex_);
400 MADARA_GUARD_TYPE guard(mutex_);
415 MADARA_GUARD_TYPE guard(mutex_);
430 MADARA_GUARD_TYPE guard(mutex_);
444 FlexMap map(settings_, delimiter_);
449 MADARA_GUARD_TYPE guard(mutex_);
462 FlexMap map(settings_, delimiter_);
467 MADARA_GUARD_TYPE guard(mutex_);
469 std::stringstream buffer;
473 buffer << name_ << delimiter_ << index;
482 bool first_level_keys_only)
const
485 MADARA_GUARD_TYPE guard(mutex_);
489 if (!first_level_keys_only)
501 std::vector<std::string> next_keys;
502 std::map<std::string, madara::knowledge::KnowledgeRecord> all_record_vars;
503 context_->to_map(name_, delimiter_,
"", next_keys, all_record_vars,
true);
505 result = next_keys.size();
512 FlexMap& other,
bool refresh_keys,
bool delete_keys)
520 MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
521 guard2(other.
mutex_, std::adopt_lock);
529 this_map.
exchange(other_map, refresh_keys, delete_keys);
538 MADARA_GUARD_TYPE guard(mutex_);
547 context_->delete_variable(name_, settings_);
557 MADARA_GUARD_TYPE guard(mutex_);
559 context_->delete_variable(name_ + delimiter_ + key, settings_);
566 Map map(name_ + delimiter_ + key,
knowledge, settings_, delimiter_);
581 MADARA_GUARD_TYPE guard(mutex_);
585 if (
context_->exists(var_name, settings_))
589 variable_ =
context_->get_ref(var_name, keep_local);
607 MADARA_GUARD_TYPE guard(mutex_);
611 if (
context_->exists(var_name, settings_))
628 MADARA_GUARD_TYPE guard(mutex_);
632 variable_ =
context_->get_ref(name_, keep_local);
639 delimiter_ = delimiter;
658 if (!variable_.is_valid())
660 result =
context_->exists(variable_, keep_local);
667 const std::string& key,
bool first_level_key)
const
674 MADARA_GUARD_TYPE guard(mutex_);
678 result =
context_->exists(exact_key);
680 if (!result && first_level_key)
682 std::vector<std::string> curkeys;
685 std::vector<std::string>::iterator found;
688 found = std::find(curkeys.begin(), curkeys.end(), key);
690 result = found != curkeys.end();
698 std::vector<std::string>& curkeys,
bool first_level_keys_only)
const
701 MADARA_GUARD_TYPE guard(mutex_);
703 if (!first_level_keys_only)
715 std::vector<std::string> next_keys;
716 std::map<std::string, madara::knowledge::KnowledgeRecord> all_record_vars;
717 context_->to_map(name_, delimiter_,
"", curkeys, all_record_vars,
true);
729 MADARA_GUARD_TYPE guard(mutex_);
731 if (!variable_.is_valid())
736 result =
context_->read_file(variable_, filename, settings_);
750 MADARA_GUARD_TYPE guard(mutex_);
752 if (!variable_.is_valid())
757 result =
context_->read_file(variable_, filename, settings);
770 MADARA_GUARD_TYPE guard(mutex_);
772 if (!variable_.is_valid())
777 result =
context_->set(variable_, value, settings_);
792 MADARA_GUARD_TYPE guard(mutex_);
794 if (!variable_.is_valid())
799 result =
context_->set(variable_, value, settings);
814 MADARA_GUARD_TYPE guard(mutex_);
816 if (!variable_.is_valid())
821 result =
context_->set_index(variable_, index, value, settings_);
837 MADARA_GUARD_TYPE guard(mutex_);
839 if (!variable_.is_valid())
844 result =
context_->set_index(variable_, index, value, settings);
858 MADARA_GUARD_TYPE guard(mutex_);
860 if (!variable_.is_valid())
865 result =
context_->set(variable_, value, size, settings_);
880 MADARA_GUARD_TYPE guard(mutex_);
882 if (!variable_.is_valid())
887 result =
context_->set(variable_, value, size, settings);
894 const std::vector<KnowledgeRecord::Integer>& value)
901 MADARA_GUARD_TYPE guard(mutex_);
903 if (!variable_.is_valid())
908 result =
context_->set(variable_, value, settings_);
915 const std::vector<KnowledgeRecord::Integer>& value,
923 MADARA_GUARD_TYPE guard(mutex_);
925 if (!variable_.is_valid())
930 result =
context_->set(variable_, value, settings);
943 MADARA_GUARD_TYPE guard(mutex_);
945 if (!variable_.is_valid())
950 result =
context_->set(variable_, value, settings_);
964 MADARA_GUARD_TYPE guard(mutex_);
966 if (!variable_.is_valid())
971 result =
context_->set(variable_, value, settings);
978 size_t index,
double value)
985 MADARA_GUARD_TYPE guard(mutex_);
987 if (!variable_.is_valid())
992 result =
context_->set_index(variable_, index, value, settings_);
1006 MADARA_GUARD_TYPE guard(mutex_);
1008 if (!variable_.is_valid())
1013 result =
context_->set_index(variable_, index, value, settings);
1020 const double* value, uint32_t size)
1027 MADARA_GUARD_TYPE guard(mutex_);
1029 if (!variable_.is_valid())
1034 result =
context_->set(variable_, value, size, settings_);
1048 MADARA_GUARD_TYPE guard(mutex_);
1050 if (!variable_.is_valid())
1055 result =
context_->set(variable_, value, size, settings);
1062 const std::vector<double>& value)
1069 MADARA_GUARD_TYPE guard(mutex_);
1071 if (!variable_.is_valid())
1076 result =
context_->set(variable_, value, settings_);
1090 MADARA_GUARD_TYPE guard(mutex_);
1092 if (!variable_.is_valid())
1097 result =
context_->set(variable_, value, settings);
1110 MADARA_GUARD_TYPE guard(mutex_);
1112 if (!variable_.is_valid())
1117 result =
context_->set(variable_, value, settings_);
1131 MADARA_GUARD_TYPE guard(mutex_);
1133 if (!variable_.is_valid())
1138 result =
context_->set(variable_, value, settings);
1145 const unsigned char* value,
size_t size)
1152 MADARA_GUARD_TYPE guard(mutex_);
1154 if (!variable_.is_valid())
1159 result =
context_->set_file(variable_, value, size, settings_);
1173 MADARA_GUARD_TYPE guard(mutex_);
1175 if (!variable_.is_valid())
1180 result =
context_->set_file(variable_, value, size, settings);
1187 const unsigned char* value,
size_t size)
1194 MADARA_GUARD_TYPE guard(mutex_);
1196 if (!variable_.is_valid())
1201 result =
context_->set_jpeg(variable_, value, size, settings_);
1215 MADARA_GUARD_TYPE guard(mutex_);
1217 if (!variable_.is_valid())
1222 result =
context_->set_jpeg(variable_, value, size, settings);
1234 MADARA_GUARD_TYPE guard(mutex_);
1236 if (!variable_.is_valid())
1241 context_->set_quality(name_, quality,
true, settings);
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
const ThreadSafeContext * context_
A thread-safe guard for a context or knowledge base.
This class provides a distributed knowledge base to users.
This class encapsulates an entry in a KnowledgeBase.
Settings for applying knowledge updates.
Settings for applying knowledge updates.
Optimized reference to a variable within the knowledge base.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
KnowledgeUpdateSettings settings_
Settings for modifications.
std::string name_
Prefix of variable.
MADARA_LOCK_TYPE mutex_
guard for access and changes
This class stores a vector of character buffers.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
This class stores a vector of doubles inside of KaRL.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
This class stores a double within a variable context.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
This class stores a flexible map of strings and ints to KaRL variables FlexMap differs from Map in th...
void modify(void)
Mark the flex map as modified.
void keys(std::vector< std::string > &curkeys, bool first_level_keys_only=true) const
Returns the keys within the map.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
bool is_true(void) const
Checks if the value in the record is not false (0)
FlexMap operator[](const std::string &key)
Retrieves a flex map at the keyed location.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
VariableReference variable_
The current location variable.
virtual bool is_false_(void) const
Polymorphic is false method which can be used to determine if at least one value in the container is ...
bool exists(void) const
Checks for the existence of the current location in the context.
FlexMap(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
ThreadSafeContext * context_
Variable context that we are modifying.
void update_variable(void) const
Updates the variable reference if necessary.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
int set_index(size_t index, knowledge::KnowledgeRecord::Integer value)
Sets an index within an array to a specified value.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
void erase(const std::string &key, bool delete_subkeys=true)
Erases a variable from the map.
int read_file(const std::string &filename)
Read a file into a location in the map.
void exchange(FlexMap &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the map at this location with the map at another location.
void operator=(const FlexMap &rhs)
Assignment operator.
double to_double(double default_value=0.0) const
Returns the value at the location as a double.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true.
virtual ~FlexMap()
Destructor.
bool is_false(void) const
Checks if the value in the record is false (0)
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
void set_quality(uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to a certain variable from this entity.
knowledge::KnowledgeRecord::Integer to_integer(KnowledgeRecord::Integer default_value=0) const
Returns the value at the location as an integer.
int set_jpeg(const unsigned char *value, size_t size)
Atomically sets the value of an index to a JPEG image.
void clear(void)
Clears the map.
size_t size(bool first_level_keys_only=true) const
Returns the size of the map.
void to_container(BufferVector &target) const
Fills a BufferVector container with all subkeys.
std::string to_string(const std::string &default_value="") const
Returns the value at the location as a string.
int set_file(const unsigned char *value, size_t size)
Atomically sets the value of an index to an arbitrary string.
knowledge::KnowledgeRecord to_record(const KnowledgeRecord &default_value=KnowledgeRecord(0)) const
Retrieves a copy of the record from the current location.
virtual BaseContainer * clone(void) const
Clones this container.
int set(knowledge::KnowledgeRecord::Integer value=knowledge::KnowledgeRecord::MODIFIED)
Sets the location within the map to the specified value.
This class stores a vector of integers inside of KaRL.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
This class stores an integer within a variable context.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
This class stores a map of strings to KaRL variables.
void set_delimiter(const std::string &delimiter, bool sync=true)
Sets the delimiter for adding and detecting subvariables.
size_t size(void) const
Returns the size of the map.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, bool sync=true)
Sets the variable name that this refers to.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
void exchange(Map &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the map at this location with the map at another location.
void modify(void)
Mark the vector as modified.
void keys(std::vector< std::string > &curkeys) const
Returns the keys within the map.
void clear(bool clear_knowledge=true)
Clears the map.
This class stores a vector of doubles inside of KaRL.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
This class stores a vector of doubles inside of KaRL.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
This class stores a vector of strings inside of KaRL.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
This class stores a string within a variable context.
void set_name(const std::string &var_name, KnowledgeBase &knowledge)
Sets the variable name that this refers to.
Provides functions and classes for the distributed knowledge base.