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_);
210 set (i, (
char *)unmanaged, size);
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)
406 MADARA_GUARD_TYPE guard (
mutex_), guard2 (other.
mutex_);
414 size_t other_size = other.
vector_.size ();
415 size_t this_size = this->
vector_.size ();
417 for (
size_t i = 0; i < this_size; ++i)
436 std::stringstream buffer;
437 buffer << this->
name_;
449 std::stringstream buffer;
450 buffer << other.
name_;
462 for (
size_t i = this_size; i < other_size; ++i)
464 std::stringstream buffer;
465 buffer << this->
name_;
493 MADARA_GUARD_TYPE guard (
mutex_);
494 MADARA_GUARD_TYPE guard2 (other.
mutex_);
496 size_t other_size = other.
vector_.size ();
497 size_t this_size = this->
vector_.size ();
499 size_t size = other_size + this_size;
502 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
518 MADARA_GUARD_TYPE guard (
mutex_);
520 target.resize (
vector_.size ());
522 for (
size_t i = 0; i <
vector_.size (); ++i)
524 target[i].deep_copy ((*
this)[i]);
539 MADARA_GUARD_TYPE guard (
mutex_);
555 MADARA_GUARD_TYPE guard (
mutex_);
571 MADARA_GUARD_TYPE guard (
mutex_);
588 MADARA_GUARD_TYPE guard (
mutex_);
606 MADARA_GUARD_TYPE guard (
mutex_);
616 const unsigned char * value,
size_t size)
623 MADARA_GUARD_TYPE guard (
mutex_);
633 const unsigned char * value,
size_t size,
641 MADARA_GUARD_TYPE guard (
mutex_);
651 const unsigned char * value,
size_t size)
658 MADARA_GUARD_TYPE guard (
mutex_);
668 const unsigned char * value,
size_t size,
676 MADARA_GUARD_TYPE guard (
mutex_);
692 MADARA_GUARD_TYPE guard (
mutex_);
710 MADARA_GUARD_TYPE guard (
mutex_);
728 MADARA_GUARD_TYPE guard (
mutex_);
747 MADARA_GUARD_TYPE guard (
mutex_);
765 MADARA_GUARD_TYPE guard (
mutex_);
784 MADARA_GUARD_TYPE guard (
mutex_);
794 const std::vector <KnowledgeRecord::Integer> & value)
801 MADARA_GUARD_TYPE guard (
mutex_);
811 const std::vector <KnowledgeRecord::Integer> & value,
819 MADARA_GUARD_TYPE guard (
mutex_);
836 MADARA_GUARD_TYPE guard (
mutex_);
854 MADARA_GUARD_TYPE guard (
mutex_);
872 MADARA_GUARD_TYPE guard (
mutex_);
891 MADARA_GUARD_TYPE guard (
mutex_);
901 const double * value,
909 MADARA_GUARD_TYPE guard (
mutex_);
919 const double * value,
928 MADARA_GUARD_TYPE guard (
mutex_);
938 const std::vector <double> & value)
945 MADARA_GUARD_TYPE guard (
mutex_);
955 const std::vector <double> & value,
963 MADARA_GUARD_TYPE guard (
mutex_);
980 MADARA_GUARD_TYPE guard (
mutex_);
998 MADARA_GUARD_TYPE guard (
mutex_);
1014 MADARA_GUARD_TYPE guard (
mutex_);
1024 bool result (
false);
1027 "Vector::is_true: Checking for truth\n");
1032 MADARA_GUARD_TYPE guard (
mutex_);
1037 "Vector::is_true: context was not null. Result changed to %d\n",
1040 for (
size_t index = 0; index <
vector_.size (); ++index)
1044 "Vector::is_true: checking index %d, is_false of %d. \n",
1050 "Vector::is_true: result is false, breaking\n");
1062 "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.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
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.
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.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
Settings for applying knowledge updates.
void transfer_to(Vector &other)
Transfers elements from this vector to another.
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...