MADARA  3.4.1
madara::knowledge::containers::FlexMap Class Reference

This class stores a flexible map of strings and ints to KaRL variables FlexMap differs from Map in three distinct ways. More...

#include <FlexMap.h>

Inheritance diagram for madara::knowledge::containers::FlexMap:
madara::knowledge::containers::BaseContainer

Public Member Functions

 FlexMap (const FlexMap &rhs)
 Copy constructor. More...
 
 FlexMap (const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
 Default constructor. More...
 
 FlexMap (const std::string &name, KnowledgeBase &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
 Constructor. More...
 
 FlexMap (const std::string &name, Variables &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
 Constructor. More...
 
virtual ~FlexMap ()
 Destructor. More...
 
void clear (void)
 Clears the map. More...
 
virtual BaseContainerclone (void) const
 Clones this container. More...
 
void erase (const std::string &key, bool delete_subkeys=true)
 Erases a variable from the map. More...
 
void exchange (FlexMap &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, bool first_level_key=false) const
 Checks if a key is in the map. More...
 
bool exists (void) const
 Checks for the existence of the current location in the context. 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 is_false (void) const
 Checks if the value in the record is false (0) More...
 
bool is_true (void) const
 Checks if the value in the record is not false (0) More...
 
void keys (std::vector< std::string > &curkeys, bool first_level_keys_only=true) const
 Returns the keys within the map. More...
 
void modify (void)
 Mark the flex map 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 FlexMap &rhs)
 Assignment operator. More...
 
void operator= (const std::string value)
 Sets the location to the specified STL string. More...
 
void operator= (const std::vector< double > &value)
 Sets the location to native double vector of the provided values. More...
 
void operator= (const std::vector< KnowledgeRecord::Integer > &value)
 Sets the location to native integer vector of the provided values. More...
 
void operator= (double value)
 Sets the location to the specified double. More...
 
void operator= (int value)
 Sets the location to the specified int. More...
 
void operator= (knowledge::KnowledgeRecord::Integer value)
 Sets the location to the specified Integer. More...
 
FlexMap operator[] (const std::string &key)
 Retrieves a flex map at the keyed location. More...
 
FlexMap operator[] (size_t index)
 Retrieves a flex map at the indexed location. More...
 
int read_file (const std::string &filename)
 Read a file into a location in the map. More...
 
int read_file (const std::string &filename, const KnowledgeUpdateSettings &settings)
 Read a file into a location in the map. More...
 
int set (const double *value, uint32_t size)
 Sets the location within the map to the specified value. More...
 
int set (const double *value, uint32_t size, const KnowledgeUpdateSettings &settings)
 Sets the location within the map to the specified value. More...
 
int set (const knowledge::KnowledgeRecord::Integer *value, uint32_t size)
 Sets the location within the map to the specified value. More...
 
int set (const knowledge::KnowledgeRecord::Integer *value, uint32_t size, const KnowledgeUpdateSettings &settings)
 Sets the location within the map to the specified value. More...
 
int set (const std::string &value)
 Sets the location within the map to the specified value. More...
 
int set (const std::string &value, const KnowledgeUpdateSettings &settings)
 Sets the location within the map to the specified value. More...
 
int set (const std::vector< double > &value)
 Sets the location within the map to the specified value. More...
 
int set (const std::vector< double > &value, const KnowledgeUpdateSettings &settings)
 Sets the location within the map to the specified value. More...
 
int set (const std::vector< KnowledgeRecord::Integer > &value)
 Sets the location within the map to the specified value. More...
 
int set (const std::vector< KnowledgeRecord::Integer > &value, const KnowledgeUpdateSettings &settings)
 Sets the location within the map to the specified value. More...
 
int set (double value)
 Sets the location within the map to the specified value. More...
 
int set (double value, const KnowledgeUpdateSettings &settings)
 Sets the location within the map to the specified value. More...
 
int set (knowledge::KnowledgeRecord::Integer value=knowledge::KnowledgeRecord::MODIFIED)
 Sets the location within the map to the specified value. More...
 
int set (KnowledgeRecord::Integer value, const KnowledgeUpdateSettings &settings)
 Sets the location within the map to the specified value. More...
 
void set_delimiter (const std::string &delimiter)
 Sets the delimiter for adding and detecting subvariables. More...
 
int set_file (const unsigned char *value, size_t size)
 Atomically sets the value of an index to an arbitrary string. More...
 
int set_file (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 (size_t index, double value)
 Sets an index within a map to a specified value. More...
 
int set_index (size_t index, double value, const KnowledgeUpdateSettings &settings)
 Sets an index within a map to a specified value. More...
 
int set_index (size_t index, knowledge::KnowledgeRecord::Integer value)
 Sets an index within an array to a specified value. More...
 
int set_index (size_t index, knowledge::KnowledgeRecord::Integer value, const KnowledgeUpdateSettings &settings)
 Sets an index within an array to a specified value. More...
 
int set_jpeg (const unsigned char *value, size_t size)
 Atomically sets the value of an index to a JPEG image. More...
 
int set_jpeg (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)
 Sets the variable name that this refers to. More...
 
void set_name (const std::string &var_name, Variables &knowledge)
 Sets the variable name that this refers to. More...
 
void set_quality (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 (bool first_level_keys_only=true) const
 Returns the size of the map. More...
 
void to_container (BufferVector &target) const
 Fills a BufferVector container with all subkeys. More...
 
void to_container (Double &target) const
 Fills a Double container with the current location. More...
 
void to_container (DoubleVector &target) const
 Fills a DoubleVector container with all subkeys. More...
 
void to_container (Integer &target) const
 Fills an Integer container with the current location. More...
 
void to_container (IntegerVector &target) const
 Fills a IntegerVector container with all subkeys. More...
 
void to_container (Map &target) const
 Fills a Map container with all subkeys. More...
 
void to_container (NativeDoubleVector &target) const
 Fills a NativeDoubleVector container with all subkeys. More...
 
void to_container (NativeIntegerVector &target) const
 Fills a NativeIntegerVector container with all subkeys. More...
 
void to_container (String &target) const
 Fills a String container with the current location. More...
 
void to_container (StringVector &target) const
 Fills a StringVector container with all subkeys. More...
 
double to_double (double default_value=0.0) const
 Returns the value at the location as a double. More...
 
knowledge::KnowledgeRecord::Integer to_integer (KnowledgeRecord::Integer default_value=0) const
 Returns the value at the location as an integer. More...
 
knowledge::KnowledgeRecord to_record (const KnowledgeRecord &default_value=KnowledgeRecord(0)) const
 Retrieves a copy of the record from the current location. More...
 
std::string to_string (const std::string &default_value="") const
 Returns the value at the location as a string. 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, VariableReferenceInternalFlexMap
 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...
 
void update_variable (void) const
 Updates the variable reference if necessary. More...
 

Private Attributes

ThreadSafeContextcontext_
 Variable context that we are modifying. More...
 
std::string delimiter_
 Delimiter for the prefix to subvars. More...
 
VariableReference variable_
 The current location variable. More...
 

Detailed Description

This class stores a flexible map of strings and ints to KaRL variables FlexMap differs from Map in three distinct ways.

First, it can use either integers (for easy multi-dimensional arrays) or strings like Map. Second, it allows for the usage of the [] operator to modify values. This can causes a small performance penalty due to the creation of FlexMaps with each [] operator, but is much more intuitive and an increase in quality-of-life. Third, because of its micromanagement of the variable names, it is slower than Map in almost all operations on variables within the map.

Definition at line 53 of file FlexMap.h.

Member Typedef Documentation

◆ InternalFlexMap

internal map of variable references

Definition at line 670 of file FlexMap.h.

Constructor & Destructor Documentation

◆ FlexMap() [1/4]

madara::knowledge::containers::FlexMap::FlexMap ( const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings(),
const std::string &  delimiter = "." 
)

Default constructor.

Parameters
settingssettings to apply by default
delimiterthe delimiter for variables in the map

Definition at line 6 of file FlexMap.cpp.

◆ FlexMap() [2/4]

madara::knowledge::containers::FlexMap::FlexMap ( const std::string &  name,
KnowledgeBase knowledge,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings(),
const std::string &  delimiter = "." 
)

Constructor.

Parameters
namethe name of the map within the variable context
knowledgethe variable context
settingssettings to apply by default
delimiterthe delimiter for variables in the map

Definition at line 12 of file FlexMap.cpp.

◆ FlexMap() [3/4]

madara::knowledge::containers::FlexMap::FlexMap ( const std::string &  name,
Variables knowledge,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings(),
const std::string &  delimiter = "." 
)

Constructor.

Parameters
namethe name of the map within the variable context
knowledgethe variable context
settingssettings to apply by default
delimiterthe delimiter for variables in the map

Definition at line 21 of file FlexMap.cpp.

◆ FlexMap() [4/4]

madara::knowledge::containers::FlexMap::FlexMap ( const FlexMap rhs)

Copy constructor.

Definition at line 30 of file FlexMap.cpp.

◆ ~FlexMap()

madara::knowledge::containers::FlexMap::~FlexMap ( )
virtual

Destructor.

Definition at line 38 of file FlexMap.cpp.

Member Function Documentation

◆ clear()

void madara::knowledge::containers::FlexMap::clear ( void  )

Clears the map.

This deletes all keys in the Flex Map from the context.

Definition at line 533 of file FlexMap.cpp.

◆ clone()

madara::knowledge::containers::BaseContainer * madara::knowledge::containers::FlexMap::clone ( void  ) const
virtual

Clones this container.

Returns
a deep copy of the container that must be managed by the user (i.e., you have to delete the return value)

Implements madara::knowledge::containers::BaseContainer.

Definition at line 139 of file FlexMap.cpp.

◆ erase()

void madara::knowledge::containers::FlexMap::erase ( const std::string &  key,
bool  delete_subkeys = true 
)

Erases a variable from the map.

Parameters
keythe variable to delete from the map
delete_subkeysif true, delete all keys with the key prefix

Definition at line 551 of file FlexMap.cpp.

◆ exchange()

void madara::knowledge::containers::FlexMap::exchange ( FlexMap other,
bool  refresh_keys = true,
bool  delete_keys = true 
)

Exchanges the map at this location with the map at another location.

Parameters
otherthe other integer to exchange with
refresh_keysforce a refresh of the keys in both maps to ensure all keys are swapped
delete_keysdelete any unused keys

Definition at line 511 of file FlexMap.cpp.

◆ exists() [1/2]

bool madara::knowledge::containers::FlexMap::exists ( const std::string &  key,
bool  first_level_key = false 
) const

Checks if a key is in the map.

By default, this will check for an exact match (i.e., the exact string matches to an existing record). If you want to just check if the key exists in the next level, set first_level_key to true.

Parameters
keythe map key to check for
first_level_keyif true, checks for existence of key in the next level of map hierarchy. This is a more expensive version of exists. O (log N) vs. O (N)

Definition at line 666 of file FlexMap.cpp.

◆ exists() [2/2]

bool madara::knowledge::containers::FlexMap::exists ( void  ) const

Checks for the existence of the current location in the context.

Checks if the value in the record is false (0)

Returns
true if location exists in map. False otherwise.
true if value is false

Definition at line 651 of file FlexMap.cpp.

◆ get_debug_info()

std::string madara::knowledge::containers::FlexMap::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)

Returns
info in format {container}: {name}{ = value, if appropriate}

Definition at line 106 of file FlexMap.cpp.

◆ get_debug_info_()

std::string madara::knowledge::containers::FlexMap::get_debug_info_ ( void  )
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)

Returns
info in format {container}: {name}{ = value, if appropriate}

Implements madara::knowledge::containers::BaseContainer.

Definition at line 133 of file FlexMap.cpp.

◆ get_delimiter()

std::string madara::knowledge::containers::FlexMap::get_delimiter ( void  )

Gets the delimiter for adding and detecting subvariables.

By default, MADARA uses a '.' delimiter for names like "ai.madara.Var1". Other conventions can include '/' for ROS-like topic directory structures, e.g., ai/madara/Var1.

Returns
the delimiter to use for variable demarcation

Definition at line 642 of file FlexMap.cpp.

◆ get_name()

std::string madara::knowledge::containers::BaseContainer::get_name ( void  ) const
inlineinherited

Returns the name of the container.

Returns
name of the container

Definition at line 4 of file BaseContainer.inl.

◆ get_settings()

madara::knowledge::KnowledgeUpdateSettings madara::knowledge::containers::BaseContainer::get_settings ( void  )
inherited

Gets the update settings for the container.

Returns
the current settings

Definition at line 29 of file BaseContainer.cpp.

◆ is_false()

bool madara::knowledge::containers::FlexMap::is_false ( void  ) const

Checks if the value in the record is false (0)

Returns
true if value is false

Definition at line 69 of file FlexMap.cpp.

◆ is_false_()

bool madara::knowledge::containers::FlexMap::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.

Definition at line 1250 of file FlexMap.cpp.

◆ is_true()

bool madara::knowledge::containers::FlexMap::is_true ( void  ) const

Checks if the value in the record is not false (0)

Returns
true if value is not false

Definition at line 44 of file FlexMap.cpp.

◆ is_true_()

bool madara::knowledge::containers::FlexMap::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.

Definition at line 1245 of file FlexMap.cpp.

◆ keys()

void madara::knowledge::containers::FlexMap::keys ( std::vector< std::string > &  curkeys,
bool  first_level_keys_only = true 
) const

Returns the keys within the map.

This can be an O(n) operation that checks for any key that has name{delimiter}key.

Parameters
curkeysthe results of the operation
first_level_keys_onlyif true, only generate first level keys

Definition at line 697 of file FlexMap.cpp.

◆ modify()

void madara::knowledge::containers::FlexMap::modify ( void  )

Mark the flex map as modified.

The map retains the same values but will resend values as if they had been modified.

Definition at line 84 of file FlexMap.cpp.

◆ modify_()

void madara::knowledge::containers::FlexMap::modify_ ( void  )
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.

Definition at line 128 of file FlexMap.cpp.

◆ modify_if_false()

bool madara::knowledge::containers::BaseContainer::modify_if_false ( BaseContainer conditional)
virtualinherited

Modifies the container if the argument is false.

Parameters
conditionalthe container that must be false to modify
Returns
true if the container was modified

Definition at line 56 of file BaseContainer.cpp.

◆ modify_if_true()

bool madara::knowledge::containers::BaseContainer::modify_if_true ( BaseContainer conditional)
virtualinherited

Modifies the container if the argument is true.

Parameters
conditionalthe container that must be true to modify
Returns
true if the container was modified

Definition at line 36 of file BaseContainer.cpp.

◆ operator=() [1/7]

void madara::knowledge::containers::FlexMap::operator= ( const FlexMap rhs)

Assignment operator.

Parameters
rhsvalue to copy

Definition at line 144 of file FlexMap.cpp.

◆ operator=() [2/7]

void madara::knowledge::containers::FlexMap::operator= ( const std::string  value)

Sets the location to the specified STL string.

Parameters
valuevalue to set at location

Definition at line 173 of file FlexMap.cpp.

◆ operator=() [3/7]

void madara::knowledge::containers::FlexMap::operator= ( const std::vector< double > &  value)

Sets the location to native double vector of the provided values.

Parameters
valuearray of doubles to set at the location
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 184 of file FlexMap.cpp.

◆ operator=() [4/7]

void madara::knowledge::containers::FlexMap::operator= ( const std::vector< KnowledgeRecord::Integer > &  value)

Sets the location to native integer vector of the provided values.

Parameters
valuearray of integers to set at the location
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 178 of file FlexMap.cpp.

◆ operator=() [5/7]

void madara::knowledge::containers::FlexMap::operator= ( double  value)

Sets the location to the specified double.

Parameters
valuevalue to set at location

Definition at line 168 of file FlexMap.cpp.

◆ operator=() [6/7]

void madara::knowledge::containers::FlexMap::operator= ( int  value)

Sets the location to the specified int.

Parameters
valuevalue to set at location

Definition at line 163 of file FlexMap.cpp.

◆ operator=() [7/7]

void madara::knowledge::containers::FlexMap::operator= ( knowledge::KnowledgeRecord::Integer  value)

Sets the location to the specified Integer.

Parameters
valuevalue to set at location

Definition at line 157 of file FlexMap.cpp.

◆ operator[]() [1/2]

madara::knowledge::containers::FlexMap madara::knowledge::containers::FlexMap::operator[] ( const std::string &  key)

Retrieves a flex map at the keyed location.

Parameters
keythe name of the variable entry
Returns
a flex map of the location in the map

Definition at line 441 of file FlexMap.cpp.

◆ operator[]() [2/2]

madara::knowledge::containers::FlexMap madara::knowledge::containers::FlexMap::operator[] ( size_t  index)

Retrieves a flex map at the indexed location.

Parameters
indexthe index of the variable entry
Returns
a flex map of the location in the map

Definition at line 459 of file FlexMap.cpp.

◆ read_file() [1/2]

int madara::knowledge::containers::FlexMap::read_file ( const std::string &  filename)

Read a file into a location in the map.

Parameters
filenamefile to read

Definition at line 721 of file FlexMap.cpp.

◆ read_file() [2/2]

int madara::knowledge::containers::FlexMap::read_file ( const std::string &  filename,
const KnowledgeUpdateSettings settings 
)

Read a file into a location in the map.

Parameters
filenamefile to read
settingssettings to use when evaluating/updating

Definition at line 741 of file FlexMap.cpp.

◆ set() [1/14]

int madara::knowledge::containers::FlexMap::set ( const double *  value,
uint32_t  size 
)

Sets the location within the map to the specified value.

Parameters
valuearray of doubles to set at the location
sizenumber of elements in the array
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 1019 of file FlexMap.cpp.

◆ set() [2/14]

int madara::knowledge::containers::FlexMap::set ( const double *  value,
uint32_t  size,
const KnowledgeUpdateSettings settings 
)

Sets the location within the map to the specified value.

Parameters
valuearray of doubles to set at the location
sizenumber of elements in the array
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 1040 of file FlexMap.cpp.

◆ set() [3/14]

int madara::knowledge::containers::FlexMap::set ( const knowledge::KnowledgeRecord::Integer value,
uint32_t  size 
)

Sets the location within the map to the specified value.

Parameters
valuearray of integers to set at the location
sizenumber of elements in the array
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 850 of file FlexMap.cpp.

◆ set() [4/14]

int madara::knowledge::containers::FlexMap::set ( const knowledge::KnowledgeRecord::Integer value,
uint32_t  size,
const KnowledgeUpdateSettings settings 
)

Sets the location within the map to the specified value.

Parameters
valuearray of integers to set at the location
sizenumber of elements in the array
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 871 of file FlexMap.cpp.

◆ set() [5/14]

int madara::knowledge::containers::FlexMap::set ( const std::string &  value)

Sets the location within the map to the specified value.

Parameters
valuevalue to set at location
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 1103 of file FlexMap.cpp.

◆ set() [6/14]

int madara::knowledge::containers::FlexMap::set ( const std::string &  value,
const KnowledgeUpdateSettings settings 
)

Sets the location within the map to the specified value.

Parameters
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 1123 of file FlexMap.cpp.

◆ set() [7/14]

int madara::knowledge::containers::FlexMap::set ( const std::vector< double > &  value)

Sets the location within the map to the specified value.

Parameters
valuearray of doubles to set at the location
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 1061 of file FlexMap.cpp.

◆ set() [8/14]

int madara::knowledge::containers::FlexMap::set ( const std::vector< double > &  value,
const KnowledgeUpdateSettings settings 
)

Sets the location within the map to the specified value.

Parameters
valuearray of doubles to set at the location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 1082 of file FlexMap.cpp.

◆ set() [9/14]

int madara::knowledge::containers::FlexMap::set ( const std::vector< KnowledgeRecord::Integer > &  value)

Sets the location within the map to the specified value.

Parameters
valuearray of integers to set at the location
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 893 of file FlexMap.cpp.

◆ set() [10/14]

int madara::knowledge::containers::FlexMap::set ( const std::vector< KnowledgeRecord::Integer > &  value,
const KnowledgeUpdateSettings settings 
)

Sets the location within the map to the specified value.

Parameters
valuearray of integers to set at the location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 914 of file FlexMap.cpp.

◆ set() [11/14]

int madara::knowledge::containers::FlexMap::set ( double  value)

Sets the location within the map to the specified value.

Parameters
valuevalue to set at location
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 936 of file FlexMap.cpp.

◆ set() [12/14]

int madara::knowledge::containers::FlexMap::set ( double  value,
const KnowledgeUpdateSettings settings 
)

Sets the location within the map to the specified value.

Parameters
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 956 of file FlexMap.cpp.

◆ set() [13/14]

int madara::knowledge::containers::FlexMap::set ( knowledge::KnowledgeRecord::Integer  value = knowledge::KnowledgeRecord::MODIFIED)

Sets the location within the map to the specified value.

Parameters
valuevalue to set at location
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 762 of file FlexMap.cpp.

◆ set() [14/14]

int madara::knowledge::containers::FlexMap::set ( KnowledgeRecord::Integer  value,
const KnowledgeUpdateSettings settings 
)

Sets the location within the map to the specified value.

Parameters
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 783 of file FlexMap.cpp.

◆ set_delimiter()

void madara::knowledge::containers::FlexMap::set_delimiter ( const std::string &  delimiter)

Sets the delimiter for adding and detecting subvariables.

By default, MADARA uses a '.' delimiter for names like "ai.madara.Var1". Other conventions can include '/' for ROS-like topic directory structures, e.g., ai/madara/Var1.

Parameters
delimiterthe delimiter to use for variable demarcation

Definition at line 636 of file FlexMap.cpp.

◆ set_file() [1/2]

int madara::knowledge::containers::FlexMap::set_file ( const unsigned char *  value,
size_t  size 
)

Atomically sets the value of an index to an arbitrary string.

Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
Returns
0 if the value was set. -1 if null key

Definition at line 1144 of file FlexMap.cpp.

◆ set_file() [2/2]

int madara::knowledge::containers::FlexMap::set_file ( const unsigned char *  value,
size_t  size,
const KnowledgeUpdateSettings settings 
)

Atomically sets the value of an index to an arbitrary string.

Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 1165 of file FlexMap.cpp.

◆ set_index() [1/4]

int madara::knowledge::containers::FlexMap::set_index ( size_t  index,
double  value 
)

Sets an index within a map to a specified value.

Parameters
indexindex of the location in the array
valuevalue to set at location
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 977 of file FlexMap.cpp.

◆ set_index() [2/4]

int madara::knowledge::containers::FlexMap::set_index ( size_t  index,
double  value,
const KnowledgeUpdateSettings settings 
)

Sets an index within a map to a specified value.

Parameters
indexindex of the location in the array
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 998 of file FlexMap.cpp.

◆ set_index() [3/4]

int madara::knowledge::containers::FlexMap::set_index ( size_t  index,
knowledge::KnowledgeRecord::Integer  value 
)

Sets an index within an array to a specified value.

Parameters
indexindex of the location in the array
valuevalue to set at location
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 805 of file FlexMap.cpp.

◆ set_index() [4/4]

int madara::knowledge::containers::FlexMap::set_index ( size_t  index,
knowledge::KnowledgeRecord::Integer  value,
const KnowledgeUpdateSettings settings 
)

Sets an index within an array to a specified value.

Parameters
indexindex of the location in the array
valuevalue to set at location
settingssettings for applying the update
Returns
0 if successful, -1 if key is null, and -2 if quality isn't high enough

Definition at line 827 of file FlexMap.cpp.

◆ set_jpeg() [1/2]

int madara::knowledge::containers::FlexMap::set_jpeg ( const unsigned char *  value,
size_t  size 
)

Atomically sets the value of an index to a JPEG image.

Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
Returns
0 if the value was set. -1 if null key

Definition at line 1186 of file FlexMap.cpp.

◆ set_jpeg() [2/2]

int madara::knowledge::containers::FlexMap::set_jpeg ( const unsigned char *  value,
size_t  size,
const KnowledgeUpdateSettings settings 
)

Atomically sets the value of an index to a JPEG image.

Parameters
valuenew value of the variable
sizeindicates the size of the value buffer
settingssettings for applying the update
Returns
0 if the value was set. -1 if null key

Definition at line 1207 of file FlexMap.cpp.

◆ set_name() [1/2]

void madara::knowledge::containers::FlexMap::set_name ( const std::string &  var_name,
KnowledgeBase knowledge 
)

Sets the variable name that this refers to.

Parameters
var_namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in

Definition at line 573 of file FlexMap.cpp.

◆ set_name() [2/2]

void madara::knowledge::containers::FlexMap::set_name ( const std::string &  var_name,
Variables knowledge 
)

Sets the variable name that this refers to.

Parameters
var_namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in

Definition at line 599 of file FlexMap.cpp.

◆ set_quality()

void madara::knowledge::containers::FlexMap::set_quality ( uint32_t  quality,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings(          false) 
)

Sets the quality of writing to a certain variable from this entity.

Parameters
qualityquality of writing to this location
settingssettings for referring to knowledge variables

Definition at line 1228 of file FlexMap.cpp.

◆ set_settings()

void madara::knowledge::containers::BaseContainer::set_settings ( const KnowledgeUpdateSettings settings)
inherited

Sets the update settings for the container.

Parameters
settingsthe new settings to use

Definition at line 20 of file BaseContainer.cpp.

◆ size()

size_t madara::knowledge::containers::FlexMap::size ( bool  first_level_keys_only = true) const

Returns the size of the map.

Parameters
first_level_keys_onlyif true, only use first level keys
Returns
size of the map

Definition at line 481 of file FlexMap.cpp.

◆ to_container() [1/10]

void madara::knowledge::containers::FlexMap::to_container ( BufferVector target) const

Fills a BufferVector container with all subkeys.

Parameters
targetcontainer to be filled

Definition at line 280 of file FlexMap.cpp.

◆ to_container() [2/10]

void madara::knowledge::containers::FlexMap::to_container ( Double target) const

Fills a Double container with the current location.

Parameters
targetcontainer to be filled

Definition at line 364 of file FlexMap.cpp.

◆ to_container() [3/10]

void madara::knowledge::containers::FlexMap::to_container ( DoubleVector target) const

Fills a DoubleVector container with all subkeys.

Parameters
targetcontainer to be filled

Definition at line 297 of file FlexMap.cpp.

◆ to_container() [4/10]

void madara::knowledge::containers::FlexMap::to_container ( Integer target) const

Fills an Integer container with the current location.

Parameters
targetcontainer to be filled

Definition at line 395 of file FlexMap.cpp.

◆ to_container() [5/10]

void madara::knowledge::containers::FlexMap::to_container ( IntegerVector target) const

Fills a IntegerVector container with all subkeys.

Parameters
targetcontainer to be filled

Definition at line 314 of file FlexMap.cpp.

◆ to_container() [6/10]

void madara::knowledge::containers::FlexMap::to_container ( Map target) const

Fills a Map container with all subkeys.

Parameters
targetcontainer to be filled

Definition at line 425 of file FlexMap.cpp.

◆ to_container() [7/10]

void madara::knowledge::containers::FlexMap::to_container ( NativeDoubleVector target) const

Fills a NativeDoubleVector container with all subkeys.

Parameters
targetcontainer to be filled

Definition at line 379 of file FlexMap.cpp.

◆ to_container() [8/10]

void madara::knowledge::containers::FlexMap::to_container ( NativeIntegerVector target) const

Fills a NativeIntegerVector container with all subkeys.

Parameters
targetcontainer to be filled

Definition at line 331 of file FlexMap.cpp.

◆ to_container() [9/10]

void madara::knowledge::containers::FlexMap::to_container ( String target) const

Fills a String container with the current location.

Parameters
targetcontainer to be filled

Definition at line 410 of file FlexMap.cpp.

◆ to_container() [10/10]

void madara::knowledge::containers::FlexMap::to_container ( StringVector target) const

Fills a StringVector container with all subkeys.

Parameters
targetcontainer to be filled

Definition at line 347 of file FlexMap.cpp.

◆ to_double()

double madara::knowledge::containers::FlexMap::to_double ( double  default_value = 0.0) const

Returns the value at the location as a double.

Parameters
default_valueif map location does not exist in KB, return this value instead
Returns
the value at the location

Definition at line 236 of file FlexMap.cpp.

◆ to_integer()

madara::knowledge::KnowledgeRecord::Integer madara::knowledge::containers::FlexMap::to_integer ( KnowledgeRecord::Integer  default_value = 0) const

Returns the value at the location as an integer.

Parameters
default_valueif map location does not exist in KB, return this value instead
Returns
the value at the location

Definition at line 214 of file FlexMap.cpp.

◆ to_record()

madara::knowledge::KnowledgeRecord madara::knowledge::containers::FlexMap::to_record ( const KnowledgeRecord default_value = KnowledgeRecord(0)) const

Retrieves a copy of the record from the current location.

Parameters
default_valueif map location does not exist in KB, return this value instead
Returns
the value of the entry. Modifications to this will not be reflected in the context. This is a local copy.

Definition at line 191 of file FlexMap.cpp.

◆ to_string()

std::string madara::knowledge::containers::FlexMap::to_string ( const std::string &  default_value = "") const

Returns the value at the location as a string.

Parameters
default_valueif map location does not exist in KB, return this value instead
Returns
the value at the location

Definition at line 258 of file FlexMap.cpp.

◆ update_variable()

void madara::knowledge::containers::FlexMap::update_variable ( void  ) const
private

Updates the variable reference if necessary.

Definition at line 623 of file FlexMap.cpp.

Member Data Documentation

◆ context_

ThreadSafeContext* madara::knowledge::containers::FlexMap::context_
private

Variable context that we are modifying.

Definition at line 675 of file FlexMap.h.

◆ delimiter_

std::string madara::knowledge::containers::FlexMap::delimiter_
private

Delimiter for the prefix to subvars.

Definition at line 685 of file FlexMap.h.

◆ mutex_

MADARA_LOCK_TYPE madara::knowledge::containers::BaseContainer::mutex_
mutableprotectedinherited

guard for access and changes

Mutex for local changes

Definition at line 136 of file BaseContainer.h.

◆ name_

std::string madara::knowledge::containers::BaseContainer::name_
protectedinherited

Prefix of variable.

Definition at line 146 of file BaseContainer.h.

◆ settings_

KnowledgeUpdateSettings madara::knowledge::containers::BaseContainer::settings_
protectedinherited

Settings for modifications.

Definition at line 151 of file BaseContainer.h.

◆ variable_

VariableReference madara::knowledge::containers::FlexMap::variable_
mutableprivate

The current location variable.

Definition at line 680 of file FlexMap.h.


The documentation for this class was generated from the following files: