MADARA
3.1.8
|
This class stores a map of strings to KaRL variables. More...
#include <Map.h>
Public Member Functions | |
Map (const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".") | |
Default constructor. More... | |
Map (const std::string &name, KnowledgeBase &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".") | |
Constructor. More... | |
Map (const std::string &name, Variables &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".") | |
Constructor. More... | |
Map (const Map &rhs) | |
Copy constructor. More... | |
virtual | ~Map () |
Destructor. More... | |
void | clear (bool clear_knowledge=true) |
Clears the map. More... | |
virtual BaseContainer * | clone (void) const |
Clones this container. More... | |
void | erase (const std::string &key) |
Erases a variable from the map. More... | |
void | exchange (Map &other, bool refresh_keys=true, bool delete_keys=true) |
Exchanges the map at this location with the map at another location. More... | |
bool | exists (const std::string &key) const |
Checks for the existence of a key. More... | |
std::string | get_debug_info (void) |
Returns the type of the container along with name and any other useful information. More... | |
std::string | get_delimiter (void) |
Gets the delimiter for adding and detecting subvariables. More... | |
std::string | get_name (void) const |
Returns the name of the container. More... | |
KnowledgeUpdateSettings | get_settings (void) |
Gets the update settings for the container. More... | |
bool | has_prefix (const std::string &prefix) const |
Checks for the existence of a prefix in the keys. More... | |
bool | is_false (void) const |
Determines if the value of the map is false. More... | |
bool | is_true (void) const |
Determines if all values in the map are true. More... | |
void | keys (std::vector< std::string > &curkeys) const |
Returns the keys within the map. More... | |
void | modify (void) |
Mark the vector as modified. More... | |
void | modify (const std::string &index) |
Mark the value as modified. More... | |
virtual bool | modify_if_false (BaseContainer &conditional) |
Modifies the container if the argument is false. More... | |
virtual bool | modify_if_true (BaseContainer &conditional) |
Modifies the container if the argument is true. More... | |
void | operator= (const Map &rhs) |
Assignment operator. More... | |
knowledge::KnowledgeRecord | operator[] (const std::string &key) |
Retrieves a copy of the record from the map. More... | |
int | read_file (const std::string &key, const std::string &filename) |
Read a file into a location in the map. More... | |
int | read_file (const std::string &key, const std::string &filename, const KnowledgeUpdateSettings &settings) |
Read a file into a location in the map. More... | |
int | set (const std::string &key, madara::knowledge::KnowledgeRecord::Integer value=madara::knowledge::KnowledgeRecord::MODIFIED) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, madara::knowledge::KnowledgeRecord::Integer value, const KnowledgeUpdateSettings &settings) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const madara::knowledge::KnowledgeRecord::Integer *value, uint32_t size) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const madara::knowledge::KnowledgeRecord::Integer *value, uint32_t size, const KnowledgeUpdateSettings &settings) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const std::vector< KnowledgeRecord::Integer > &value) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const std::vector< KnowledgeRecord::Integer > &value, const KnowledgeUpdateSettings &settings) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, double value) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, double value, const KnowledgeUpdateSettings &settings) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const double *value, uint32_t size) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const double *value, uint32_t size, const KnowledgeUpdateSettings &settings) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const std::vector< double > &value) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const std::vector< double > &value, const KnowledgeUpdateSettings &settings) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const std::string &value) |
Sets a location within the map to the specified value. More... | |
int | set (const std::string &key, const std::string &value, const KnowledgeUpdateSettings &settings) |
Sets a location within the map to the specified value. More... | |
void | set_delimiter (const std::string &delimiter, bool sync=true) |
Sets the delimiter for adding and detecting subvariables. More... | |
int | set_file (const std::string &key, const unsigned char *value, size_t size) |
Atomically sets the value of an index to an arbitrary string. More... | |
int | set_file (const std::string &key, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings) |
Atomically sets the value of an index to an arbitrary string. More... | |
int | set_index (const std::string &key, size_t index, madara::knowledge::KnowledgeRecord::Integer value) |
Sets an index within an array to a specified value. More... | |
int | set_index (const std::string &key, size_t index, madara::knowledge::KnowledgeRecord::Integer value, const KnowledgeUpdateSettings &settings) |
Sets an index within an array to a specified value. More... | |
int | set_index (const std::string &key, size_t index, double value) |
Sets an index within a map to a specified value. More... | |
int | set_index (const std::string &key, size_t index, double value, const KnowledgeUpdateSettings &settings) |
Sets an index within a map to a specified value. More... | |
int | set_jpeg (const std::string &key, const unsigned char *value, size_t size) |
Atomically sets the value of an index to a JPEG image. More... | |
int | set_jpeg (const std::string &key, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings) |
Atomically sets the value of an index to a JPEG image. More... | |
void | set_name (const std::string &var_name, KnowledgeBase &knowledge, bool sync=true) |
Sets the variable name that this refers to. More... | |
void | set_name (const std::string &var_name, Variables &knowledge, bool sync=true) |
Sets the variable name that this refers to. More... | |
void | set_quality (const std::string &key, uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false)) |
Sets the quality of writing to a certain variable from this entity. More... | |
void | set_settings (const KnowledgeUpdateSettings &settings) |
Sets the update settings for the container. More... | |
size_t | size (void) const |
Returns the size of the map. More... | |
std::vector< std::string > | sync_keys (void) |
Syncs the keys from the knowledge base. More... | |
knowledge::KnowledgeRecord | to_record (const std::string &key) |
Retrieves a copy of the record from the map. More... | |
Protected Attributes | |
MADARA_LOCK_TYPE | mutex_ |
guard for access and changes More... | |
std::string | name_ |
Prefix of variable. More... | |
KnowledgeUpdateSettings | settings_ |
Settings for modifications. More... | |
Private Types | |
typedef std::map< std::string, VariableReference > | InternalMap |
internal map of variable references More... | |
Private Member Functions | |
virtual std::string | get_debug_info_ (void) |
Returns the type of the container along with name and any other useful information. More... | |
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 false. More... | |
virtual bool | is_true_ (void) const |
Polymorphic is true method which can be used to determine if all values in the container are true. More... | |
virtual void | modify_ (void) |
Polymorphic modify method used by collection containers. More... | |
Private Attributes | |
ThreadSafeContext * | context_ |
Variable context that we are modifying. More... | |
std::string | delimiter_ |
Delimiter for the prefix to subvars. More... | |
InternalMap | map_ |
Map of variables to values. More... | |
|
private |
madara::knowledge::containers::Map::Map | ( | const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings () , |
const std::string & | delimiter = "." |
||
) |
madara::knowledge::containers::Map::Map | ( | const std::string & | name, |
KnowledgeBase & | knowledge, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings () , |
||
const std::string & | delimiter = "." |
||
) |
madara::knowledge::containers::Map::Map | ( | const std::string & | name, |
Variables & | knowledge, | ||
const KnowledgeUpdateSettings & | settings = KnowledgeUpdateSettings () , |
||
const std::string & | delimiter = "." |
||
) |
madara::knowledge::containers::Map::Map | ( | const Map & | rhs | ) |
|
virtual |
void madara::knowledge::containers::Map::clear | ( | bool | clear_knowledge = true | ) |
|
virtual |
Clones this container.
Implements madara::knowledge::containers::BaseContainer.
void madara::knowledge::containers::Map::erase | ( | const std::string & | key | ) |
void madara::knowledge::containers::Map::exchange | ( | Map & | other, |
bool | refresh_keys = true , |
||
bool | delete_keys = true |
||
) |
bool madara::knowledge::containers::Map::exists | ( | const std::string & | key | ) | const |
std::string madara::knowledge::containers::Map::get_debug_info | ( | void | ) |
Returns the type of the container along with name and any other useful information.
The provided information should be useful for developers wishing to debug container operations, especially as it pertains to pending network operations (i.e., when used in conjunction with modify)
|
privatevirtual |
Returns the type of the container along with name and any other useful information.
The provided information should be useful for developers wishing to debug container operations, especially as it pertains to pending network operations (i.e., when used in conjunction with modify)
Implements madara::knowledge::containers::BaseContainer.
std::string madara::knowledge::containers::Map::get_delimiter | ( | void | ) |
Gets the delimiter for adding and detecting subvariables.
By default, MADARA uses a '.' delimiter for names like "com.madara.Var1". Other conventions can include '/' for ROS-like topic directory structures, e.g., com/madara/Var1.
|
inlineinherited |
Returns the name of the container.
Definition at line 5 of file BaseContainer.inl.
|
inherited |
Gets the update settings for the container.
Definition at line 37 of file BaseContainer.cpp.
bool madara::knowledge::containers::Map::has_prefix | ( | const std::string & | prefix | ) | const |
bool madara::knowledge::containers::Map::is_false | ( | void | ) | const |
|
privatevirtual |
Polymorphic is false method which can be used to determine if at least one value in the container is false.
Implements madara::knowledge::containers::BaseContainer.
bool madara::knowledge::containers::Map::is_true | ( | void | ) | const |
|
privatevirtual |
Polymorphic is true method which can be used to determine if all values in the container are true.
Implements madara::knowledge::containers::BaseContainer.
void madara::knowledge::containers::Map::keys | ( | std::vector< std::string > & | curkeys | ) | const |
void madara::knowledge::containers::Map::modify | ( | void | ) |
void madara::knowledge::containers::Map::modify | ( | const std::string & | index | ) |
|
privatevirtual |
Polymorphic modify method used by collection containers.
This method calls the modify method for this class. We separate the faster version (modify) from this version (modify_) to allow users the opportunity to have a fastery version that does not use polymorphic functions (generally virtual functions are half as efficient as normal function calls)
Implements madara::knowledge::containers::BaseContainer.
|
virtualinherited |
Modifies the container if the argument is false.
conditional | the container that must be false to modify |
Definition at line 64 of file BaseContainer.cpp.
|
virtualinherited |
Modifies the container if the argument is true.
conditional | the container that must be true to modify |
Definition at line 44 of file BaseContainer.cpp.
void madara::knowledge::containers::Map::operator= | ( | const Map & | rhs | ) |
madara::knowledge::KnowledgeRecord madara::knowledge::containers::Map::operator[] | ( | const std::string & | key | ) |
int madara::knowledge::containers::Map::read_file | ( | const std::string & | key, |
const std::string & | filename | ||
) |
int madara::knowledge::containers::Map::read_file | ( | const std::string & | key, |
const std::string & | filename, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
madara::knowledge::KnowledgeRecord::Integer | value = madara::knowledge::KnowledgeRecord::MODIFIED |
||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
madara::knowledge::KnowledgeRecord::Integer | value, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const madara::knowledge::KnowledgeRecord::Integer * | value, | ||
uint32_t | size | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const madara::knowledge::KnowledgeRecord::Integer * | value, | ||
uint32_t | size, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
Sets a location within the map to the specified value.
key | location within the map |
value | array of integers to set at the location |
size | number of elements in the array |
settings | settings for applying the update |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const std::vector< KnowledgeRecord::Integer > & | value | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const std::vector< KnowledgeRecord::Integer > & | value, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
double | value | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
double | value, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const double * | value, | ||
uint32_t | size | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const double * | value, | ||
uint32_t | size, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
Sets a location within the map to the specified value.
key | location within the map |
value | array of doubles to set at the location |
size | number of elements in the array |
settings | settings for applying the update |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const std::vector< double > & | value | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const std::vector< double > & | value, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const std::string & | value | ||
) |
int madara::knowledge::containers::Map::set | ( | const std::string & | key, |
const std::string & | value, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
void madara::knowledge::containers::Map::set_delimiter | ( | const std::string & | delimiter, |
bool | sync = true |
||
) |
Sets the delimiter for adding and detecting subvariables.
By default, MADARA uses a '.' delimiter for names like "com.madara.Var1". Other conventions can include '/' for ROS-like topic directory structures, e.g., com/madara/Var1.
delimiter | the delimiter to use for variable demarcation |
sync | sync the keys to existing vars in the new delimiter |
int madara::knowledge::containers::Map::set_file | ( | const std::string & | key, |
const unsigned char * | value, | ||
size_t | size | ||
) |
int madara::knowledge::containers::Map::set_file | ( | const std::string & | key, |
const unsigned char * | value, | ||
size_t | size, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
Atomically sets the value of an index to an arbitrary string.
key | key to store the file into |
value | new value of the variable |
size | indicates the size of the value buffer |
settings | settings for applying the update |
int madara::knowledge::containers::Map::set_index | ( | const std::string & | key, |
size_t | index, | ||
madara::knowledge::KnowledgeRecord::Integer | value | ||
) |
int madara::knowledge::containers::Map::set_index | ( | const std::string & | key, |
size_t | index, | ||
madara::knowledge::KnowledgeRecord::Integer | value, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
Sets an index within an array to a specified value.
key | location within the map |
index | index of the location in the array |
value | value to set at location |
settings | settings for applying the update |
int madara::knowledge::containers::Map::set_index | ( | const std::string & | key, |
size_t | index, | ||
double | value | ||
) |
int madara::knowledge::containers::Map::set_index | ( | const std::string & | key, |
size_t | index, | ||
double | value, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
Sets an index within a map to a specified value.
key | location within the map |
index | index of the location in the array |
value | value to set at location |
settings | settings for applying the update |
int madara::knowledge::containers::Map::set_jpeg | ( | const std::string & | key, |
const unsigned char * | value, | ||
size_t | size | ||
) |
int madara::knowledge::containers::Map::set_jpeg | ( | const std::string & | key, |
const unsigned char * | value, | ||
size_t | size, | ||
const KnowledgeUpdateSettings & | settings | ||
) |
void madara::knowledge::containers::Map::set_name | ( | const std::string & | var_name, |
KnowledgeBase & | knowledge, | ||
bool | sync = true |
||
) |
void madara::knowledge::containers::Map::set_name | ( | const std::string & | var_name, |
Variables & | knowledge, | ||
bool | sync = true |
||
) |
void madara::knowledge::containers::Map::set_quality | ( | const std::string & | key, |
uint32_t | quality, | ||
const KnowledgeReferenceSettings & | settings = KnowledgeReferenceSettings (false) |
||
) |
|
inherited |
Sets the update settings for the container.
settings | the new settings to use |
Definition at line 28 of file BaseContainer.cpp.
size_t madara::knowledge::containers::Map::size | ( | void | ) | const |
std::vector< std::string > madara::knowledge::containers::Map::sync_keys | ( | void | ) |
madara::knowledge::KnowledgeRecord madara::knowledge::containers::Map::to_record | ( | const std::string & | key | ) |
Retrieves a copy of the record from the map.
Same functionality as operator[]. This is provided for convenience to match other containers way of converting to a record.
key | the name of the variable entry |
|
private |
|
private |
|
private |
|
mutableprotectedinherited |
guard for access and changes
Mutex for local changes
Definition at line 141 of file BaseContainer.h.
|
protectedinherited |
Prefix of variable.
Definition at line 151 of file BaseContainer.h.
|
protectedinherited |
Settings for modifications.
Definition at line 156 of file BaseContainer.h.