9 :
BaseContainer (
"", settings), context_ (0), delimiter_ (delimiter)
24 resize (size, delete_vars);
38 resize (size, delete_vars);
62 for (
size_t index = 0; index <
vector_.size (); ++index)
72 std::stringstream result;
74 result <<
"Buffer Vector: ";
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)
150 const unsigned char * value,
size_t size)
155 MADARA_GUARD_TYPE guard (
mutex_);
162 size_t i = this->
size ();
177 std::stringstream buffer;
180 MADARA_GUARD_TYPE guard (
mutex_);
194 int size,
bool delete_vars)
199 MADARA_GUARD_TYPE guard (
mutex_);
208 size_t old_size =
vector_.size ();
210 if (old_size != (
size_t)size)
216 if ((
size_t)size > old_size)
218 for (; old_size < (size_t)size; ++old_size)
220 std::stringstream buffer;
227 else if (delete_vars)
229 for (; (size_t)size < old_size; ++
size)
231 std::stringstream buffer;
247 size_t old_size =
vector_.size ();
249 if (old_size != cur_size)
253 if (cur_size > old_size)
255 for (; old_size < cur_size; ++old_size)
257 std::stringstream buffer;
264 else if (delete_vars)
266 for (; cur_size < old_size; ++cur_size)
268 std::stringstream buffer;
284 MADARA_GUARD_TYPE guard (
mutex_);
298 MADARA_GUARD_TYPE guard (
mutex_);
320 MADARA_GUARD_TYPE guard (
mutex_);
339 MADARA_GUARD_TYPE guard (
mutex_);
356 MADARA_GUARD_TYPE guard (
mutex_);
372 BufferVector & other,
bool refresh_keys,
bool delete_keys)
378 MADARA_GUARD_TYPE guard (
mutex_), guard2 (other.
mutex_);
386 size_t other_size = other.
vector_.size ();
387 size_t this_size = this->
vector_.size ();
389 for (
size_t i = 0; i < this_size; ++i)
408 std::stringstream buffer;
409 buffer << this->
name_;
421 std::stringstream buffer;
422 buffer << other.
name_;
434 for (
size_t i = this_size; i < other_size; ++i)
436 std::stringstream buffer;
437 buffer << this->
name_;
465 MADARA_GUARD_TYPE guard (
mutex_);
466 MADARA_GUARD_TYPE guard2 (other.
mutex_);
468 size_t other_size = other.
vector_.size ();
469 size_t this_size = this->
vector_.size ();
471 size_t size = other_size + this_size;
474 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
490 MADARA_GUARD_TYPE guard (
mutex_);
493 target.reserve (
vector_.size());
495 for (
const auto &cur :
vector_)
497 if (cur.is_valid()) {
500 target.emplace_back ();
522 MADARA_GUARD_TYPE guard (
mutex_);
538 MADARA_GUARD_TYPE guard (
mutex_);
556 MADARA_GUARD_TYPE guard (
mutex_);
575 MADARA_GUARD_TYPE guard (
mutex_);
586 const unsigned char * value,
size_t size)
593 MADARA_GUARD_TYPE guard (
mutex_);
609 MADARA_GUARD_TYPE guard (
mutex_);
620 const unsigned char * value,
size_t size,
628 MADARA_GUARD_TYPE guard (
mutex_);
639 const unsigned char * value,
size_t size)
646 MADARA_GUARD_TYPE guard (
mutex_);
656 const unsigned char * value,
size_t size,
664 MADARA_GUARD_TYPE guard (
mutex_);
680 MADARA_GUARD_TYPE guard (
mutex_);
693 "BufferVector::is_true: Checking for truth\n");
698 MADARA_GUARD_TYPE guard (
mutex_);
703 "BufferVector::is_true: context was not null. Result changed to %d\n",
706 for (
size_t index = 0; index <
vector_.size (); ++index)
710 "BufferVector::is_true: checking index %d, is_false of %d. \n",
716 "BufferVector::is_true: result is false, breaking\n");
728 "BufferVector::is_true: final result is %d\n", (int)result);
This class encapsulates an entry in a KnowledgeBase.
bool is_false(void) const
Determines if the value of the vector is false.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
This class stores a vector of character buffers.
VariableReference size_
Reference to the size field of the vector space.
std::vector< VariableReference > vector_
Values of the array.
int set_jpeg(size_t index, const unsigned char *value, size_t size)
Atomically sets the value of an index to a JPEG image.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
std::string get_name(void) const
Returns the name of the container.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
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 ~BufferVector()
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.
size_t size(void) const
Returns the size of the local vector.
std::string name_
Prefix of variable.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
void push_back(const unsigned char *value, size_t size)
Pushes the value to the end of the array after incrementing the array size.
void exchange(BufferVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
This class stores variables and their values for use by any entity needing state information in a thr...
void transfer_to(BufferVector &other)
Transfers elements from this vector to another.
void modify(void)
Mark the vector as modified.
void operator=(const BufferVector &rhs)
Assignment operator.
MADARA_LOCK_TYPE mutex_
guard for access and changes
bool is_true(void) const
Determines if all values in the vector are true.
VariableReference get_size_ref(void) const
Returns a reference to the size field of the current name.
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
Optimized reference to a variable within the knowledge base.
#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.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
Provides container classes for fast knowledge base access and mutation.
::std::vector< KnowledgeRecord > KnowledgeVector
virtual void modify_(void)
Polymorphic modify method used by collection containers.
A thread-safe guard for a context or knowledge base.
knowledge::KnowledgeRecord operator[](size_t index) const
Retrieves a copy of the record from the map.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
This class provides a distributed knowledge base to users.
virtual BaseContainer * clone(void) const
Clones this container.
int set(size_t index, const knowledge::KnowledgeRecord &value)
Atomically sets the value of an index to a provided record.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
std::string delimiter_
Delimiter for the prefix to subvars.
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 using stored settings.
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.
Provides functions and classes for the distributed knowledge base.
KnowledgeUpdateSettings settings_
Settings for modifications.
ThreadSafeContext * context_
Variable context that we are modifying.
knowledge::KnowledgeRecord to_record(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.
Copyright (c) 2015 Carnegie Mellon University.
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.
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.
BufferVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
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...
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
int set_file(size_t index, const unsigned char *value, size_t size)
Atomically sets the value of an index to an arbitrary string using stored settings.
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.
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 ...
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.