8 :
BaseContainer (
"", settings), context_ (0), delimiter_ (delimiter)
23 resize (size, delete_vars);
37 resize (size, delete_vars);
60 MADARA_GUARD_TYPE guard (
mutex_);
62 for (
size_t index = 0; index <
vector_.size (); ++index)
72 std::stringstream result;
79 MADARA_GUARD_TYPE guard (
mutex_);
80 size_t elements =
vector_.size ();
82 result << this->
name_;
83 result <<
" [" << elements <<
"]";
90 for (
size_t index = 1; index < elements; ++index)
118 return new Vector (*
this);
127 MADARA_GUARD_TYPE guard (
mutex_);
158 std::stringstream buffer;
161 MADARA_GUARD_TYPE guard (
mutex_);
179 MADARA_GUARD_TYPE guard (
mutex_);
222 int size,
bool delete_vars)
227 MADARA_GUARD_TYPE guard (
mutex_);
236 size_t old_size =
vector_.size ();
238 if (old_size != (
size_t)size)
244 if ((
size_t)size > old_size)
246 for (; old_size < (size_t)size; ++old_size)
248 std::stringstream buffer;
255 else if (delete_vars)
257 for (; (size_t)size < old_size; ++
size)
259 std::stringstream buffer;
275 size_t old_size =
vector_.size ();
277 if (old_size != cur_size)
281 if (cur_size > old_size)
283 for (; old_size < cur_size; ++old_size)
285 std::stringstream buffer;
292 else if (delete_vars)
294 for (; cur_size < old_size; ++cur_size)
296 std::stringstream buffer;
312 MADARA_GUARD_TYPE guard (
mutex_);
326 MADARA_GUARD_TYPE guard (
mutex_);
348 MADARA_GUARD_TYPE guard (
mutex_);
367 MADARA_GUARD_TYPE guard (
mutex_);
384 MADARA_GUARD_TYPE guard (
mutex_);
400 Vector & other,
bool refresh_keys,
bool delete_keys)
408 MADARA_GUARD_TYPE guard (
mutex_, std::adopt_lock),
409 guard2 (other.
mutex_, std::adopt_lock);
418 size_t other_size = other.
vector_.size ();
419 size_t this_size = this->
vector_.size ();
421 for (
size_t i = 0; i < this_size; ++i)
441 std::stringstream buffer;
442 buffer << this->
name_;
455 std::stringstream buffer;
456 buffer << other.
name_;
468 for (
size_t i = this_size; i < other_size; ++i)
470 std::stringstream buffer;
471 buffer << this->
name_;
500 MADARA_GUARD_TYPE guard (
mutex_, std::adopt_lock),
501 guard2 (other.
mutex_, std::adopt_lock);
504 size_t other_size = other.
vector_.size ();
505 size_t this_size = this->
vector_.size ();
507 size_t size = other_size + this_size;
510 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
526 MADARA_GUARD_TYPE guard (
mutex_);
528 target.resize (
vector_.size ());
530 for (
size_t i = 0; i <
vector_.size (); ++i)
532 target[i].deep_copy ((*
this)[i]);
547 MADARA_GUARD_TYPE guard (
mutex_);
563 MADARA_GUARD_TYPE guard (
mutex_);
579 MADARA_GUARD_TYPE guard (
mutex_);
596 MADARA_GUARD_TYPE guard (
mutex_);
614 MADARA_GUARD_TYPE guard (
mutex_);
624 const unsigned char * value,
size_t size)
631 MADARA_GUARD_TYPE guard (
mutex_);
641 const unsigned char * value,
size_t size,
649 MADARA_GUARD_TYPE guard (
mutex_);
659 const unsigned char * value,
size_t size)
666 MADARA_GUARD_TYPE guard (
mutex_);
676 const unsigned char * value,
size_t size,
684 MADARA_GUARD_TYPE guard (
mutex_);
700 MADARA_GUARD_TYPE guard (
mutex_);
718 MADARA_GUARD_TYPE guard (
mutex_);
736 MADARA_GUARD_TYPE guard (
mutex_);
755 MADARA_GUARD_TYPE guard (
mutex_);
773 MADARA_GUARD_TYPE guard (
mutex_);
792 MADARA_GUARD_TYPE guard (
mutex_);
802 const std::vector <KnowledgeRecord::Integer> & value)
809 MADARA_GUARD_TYPE guard (
mutex_);
819 const std::vector <KnowledgeRecord::Integer> & value,
827 MADARA_GUARD_TYPE guard (
mutex_);
844 MADARA_GUARD_TYPE guard (
mutex_);
862 MADARA_GUARD_TYPE guard (
mutex_);
880 MADARA_GUARD_TYPE guard (
mutex_);
899 MADARA_GUARD_TYPE guard (
mutex_);
909 const double * value,
917 MADARA_GUARD_TYPE guard (
mutex_);
927 const double * value,
936 MADARA_GUARD_TYPE guard (
mutex_);
946 const std::vector <double> & value)
953 MADARA_GUARD_TYPE guard (
mutex_);
963 const std::vector <double> & value,
971 MADARA_GUARD_TYPE guard (
mutex_);
988 MADARA_GUARD_TYPE guard (
mutex_);
1006 MADARA_GUARD_TYPE guard (
mutex_);
1022 MADARA_GUARD_TYPE guard (
mutex_);
1032 bool result (
false);
1035 "Vector::is_true: Checking for truth\n");
1040 MADARA_GUARD_TYPE guard (
mutex_);
1045 "Vector::is_true: context was not null. Result changed to %d\n",
1048 for (
size_t index = 0; index <
vector_.size (); ++index)
1052 "Vector::is_true: checking index %d, is_false of %d. \n",
1058 "Vector::is_true: result is false, breaking\n");
1070 "Vector::is_true: final result is %d\n", (int)result);
This class encapsulates an entry in a KnowledgeBase.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
VariableReference size_
Reference to the size field of the vector space.
int32_t type(void) const
returns the size of the value
std::string get_name(void) const
Returns the name of the container.
virtual ~Vector()
Destructor.
int set_file(const std::string &key, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to an arbitrary string.
int set_jpeg(const std::string &key, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to a JPEG image.
double to_double(void) const
converts the value to a float/double.
std::string name_
Prefix of variable.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
int set_index(size_t index, size_t sub_index, madara::knowledge::KnowledgeRecord::Integer value)
Sets an index within an array to a specified value.
ThreadSafeContext * context_
Variable context that we are modifying.
size_t size(void) const
Returns the size of the local vector.
bool is_binary_file_type(void) const
returns true if the knowledge record has a binary file type
This class stores variables and their values for use by any entity needing state information in a thr...
knowledge::KnowledgeRecord to_record(size_t index) const
Retrieves a copy of the record from the map.
Vector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
int set_file(size_t index, const unsigned char *value, size_t size)
Atomically sets the value of an index to an arbitrary string.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
std::string delimiter_
Delimiter for the prefix to subvars.
bool is_true(void) const
Determines if all values in the vector are true.
void operator=(const Vector &rhs)
Assignment operator.
MADARA_LOCK_TYPE mutex_
guard for access and changes
std::vector< VariableReference > vector_
Values of the array.
Optimized reference to a variable within the knowledge base.
int set_index(const std::string &key, size_t index, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of an array index to a value.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
bool is_valid(void) const
Checks to see if the variable reference has been initialized.
int set_jpeg(size_t index, const unsigned char *value, size_t size)
Atomically sets the value of an index to a JPEG image.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
::std::vector< KnowledgeRecord > KnowledgeVector
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
A thread-safe guard for a context or knowledge base.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
This class stores a vector of KaRL variables.
void modify(void)
Mark the vector as modified.
bool is_false(void) const
Determines if the value of the vector is false.
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
This class provides a distributed knowledge base to users.
std::vector< double > to_doubles(void) const
converts the value to a vector of doubles
int set(size_t index, madara::knowledge::KnowledgeRecord::Integer value=madara::knowledge::KnowledgeRecord::MODIFIED)
Sets a knowledge variable to a specified value.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
void set_quality(size_t index, uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to a certain variable from this entity.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
Integer to_integer(void) const
converts the value to an integer.
int read_file(size_t index, const std::string &filename)
Read a file into the index.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
bool delete_variable(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Deletes the key.
std::vector< Integer > to_integers(void) const
converts the value to a vector of integers
Provides functions and classes for the distributed knowledge base.
KnowledgeUpdateSettings settings_
Settings for modifications.
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 ...
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
knowledge::KnowledgeRecord operator[](size_t index) const
Retrieves a copy of the record from the map.
Settings for applying knowledge updates.
void transfer_to(Vector &other)
Transfers elements from this vector to another.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
uint32_t set_quality(const std::string &key, uint32_t quality, bool force_update, const KnowledgeReferenceSettings &settings)
Atomically sets quality of this process for a variable.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
virtual BaseContainer * clone(void) const
Clones this container.
void push_back(KnowledgeRecord value)
Pushes the value to the end of the array after incrementing the array size.
void exchange(Vector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
bool is_false(void) const
Checks to see if the record is false.
Settings for applying knowledge updates.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
int read_file(const std::string &key, const std::string &filename, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically reads a file into a variable.
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for g...
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true...
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.
unsigned char * to_unmanaged_buffer(size_t &size) const
returns an unmanaged buffer that the user will have to take care of (this is a copy of the internal v...