43 delimiter_(rhs.delimiter_)
54 for (
size_t index = 0; index <
vector_.size(); ++index)
63 std::stringstream result;
65 result <<
"Buffer Vector: ";
70 MADARA_GUARD_TYPE guard(
mutex_);
71 size_t elements =
vector_.size();
73 result << this->
name_;
74 result <<
" [" << elements <<
"]";
81 for (
size_t index = 1; index < elements; ++index)
137 MADARA_GUARD_TYPE guard(
mutex_);
144 size_t i = this->
size();
157 std::stringstream buffer;
160 MADARA_GUARD_TYPE guard(
mutex_);
177 MADARA_GUARD_TYPE guard(
mutex_);
186 size_t old_size =
vector_.size();
188 if (old_size != (
size_t)
size)
195 if ((
size_t)
size > old_size)
197 for (; old_size < (size_t)
size; ++old_size)
199 std::stringstream buffer;
206 else if (delete_vars)
208 for (; (size_t)
size < old_size; ++
size)
210 std::stringstream buffer;
225 size_t old_size =
vector_.size();
227 if (old_size != cur_size)
231 if (cur_size > old_size)
233 for (; old_size < cur_size; ++old_size)
235 std::stringstream buffer;
242 else if (delete_vars)
244 for (; cur_size < old_size; ++cur_size)
246 std::stringstream buffer;
261 MADARA_GUARD_TYPE guard(
mutex_);
273 MADARA_GUARD_TYPE guard(
mutex_);
293 MADARA_GUARD_TYPE guard(
mutex_);
310 MADARA_GUARD_TYPE guard(
mutex_);
325 MADARA_GUARD_TYPE guard(
mutex_);
338 BufferVector& other,
bool refresh_keys,
bool delete_keys)
346 MADARA_GUARD_TYPE guard(
mutex_, std::adopt_lock),
347 guard2(other.
mutex_, std::adopt_lock);
355 size_t other_size = other.
vector_.size();
356 size_t this_size = this->
vector_.size();
358 for (
size_t i = 0; i < this_size; ++i)
377 std::stringstream buffer;
378 buffer << this->
name_;
390 std::stringstream buffer;
391 buffer << other.
name_;
402 for (
size_t i = this_size; i < other_size; ++i)
404 std::stringstream buffer;
405 buffer << this->
name_;
435 MADARA_GUARD_TYPE guard(
mutex_, std::adopt_lock),
436 guard2(other.
mutex_, std::adopt_lock);
438 size_t other_size = other.
vector_.size();
439 size_t this_size = this->
vector_.size();
441 size_t size = other_size + this_size;
444 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
458 MADARA_GUARD_TYPE guard(
mutex_);
461 target.reserve(
vector_.size());
463 for (
const auto& cur :
vector_)
471 target.emplace_back();
489 MADARA_GUARD_TYPE guard(
mutex_);
503 MADARA_GUARD_TYPE guard(
mutex_);
517 MADARA_GUARD_TYPE guard(
mutex_);
532 MADARA_GUARD_TYPE guard(
mutex_);
540 size_t index,
const unsigned char* value,
size_t size)
547 MADARA_GUARD_TYPE guard(
mutex_);
561 MADARA_GUARD_TYPE guard(
mutex_);
577 MADARA_GUARD_TYPE guard(
mutex_);
585 size_t index,
const unsigned char* value,
size_t size)
592 MADARA_GUARD_TYPE guard(
mutex_);
607 MADARA_GUARD_TYPE guard(
mutex_);
620 MADARA_GUARD_TYPE guard(
mutex_);
631 "BufferVector::is_true: Checking for truth\n");
636 MADARA_GUARD_TYPE guard(
mutex_);
641 "BufferVector::is_true: context was not null. Result changed to %d\n",
644 for (
size_t index = 0; index <
vector_.size(); ++index)
647 "BufferVector::is_true: checking index %d, is_false of %d. \n",
653 "BufferVector::is_true: result is false, breaking\n");
665 "BufferVector::is_true: final result is %d\n", (
int)result);
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
const ThreadSafeContext * context_
A thread-safe guard for a context or knowledge base.
This class provides a distributed knowledge base to users.
This class encapsulates an entry in a KnowledgeBase.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
Integer to_integer(void) const
converts the value to an integer.
bool is_false(void) const
Checks to see if the record is false.
Settings for applying knowledge updates.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
int read_file(const std::string &key, const std::string &filename, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically reads a file into a variable.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the current value of 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...
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
bool delete_variable(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Deletes the key.
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.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the 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.
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.
Optimized reference to a variable within the knowledge base.
bool is_valid(void) const
Checks to see if the variable reference has been initialized.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
std::string get_name(void) const
Returns the name of the container.
KnowledgeUpdateSettings settings_
Settings for modifications.
std::string name_
Prefix of variable.
MADARA_LOCK_TYPE mutex_
guard for access and changes
This class stores a vector of character buffers.
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.
knowledge::KnowledgeRecord to_record(size_t index) const
Retrieves a copy of the record from the map.
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
int set_jpeg(size_t index, const unsigned char *value, size_t size)
Atomically sets the value of an index to a JPEG image.
virtual ~BufferVector()
Destructor.
std::vector< VariableReference > vector_
Values of the array.
void transfer_to(BufferVector &other)
Transfers elements from this vector to another.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
VariableReference get_size_ref(void) const
Returns a reference to the size field of the current name.
size_t size(void) const
Returns the size of the local vector.
void push_back(const unsigned char *value, size_t size)
Pushes the value to the end of the array after incrementing the array size.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true.
bool is_true(void) const
Determines if all values in the vector are true.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
int set(size_t index, const knowledge::KnowledgeRecord &value)
Atomically sets the value of an index to a provided record.
void modify(void)
Mark the vector as modified.
knowledge::KnowledgeRecord operator[](size_t index) const
Retrieves a copy of the record from the map.
int read_file(size_t index, const std::string &filename)
Read a file into the index using stored settings.
virtual BaseContainer * clone(void) const
Clones this container.
void exchange(BufferVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
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.
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 ...
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
void operator=(const BufferVector &rhs)
Assignment operator.
BufferVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
std::string delimiter_
Delimiter for the prefix to subvars.
bool is_false(void) const
Determines if the value of the vector is false.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
VariableReference size_
Reference to the size field of the vector space.
ThreadSafeContext * context_
Variable context that we are modifying.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
Provides container classes for fast knowledge base access and mutation.
Provides functions and classes for the distributed knowledge base.
::std::vector< KnowledgeRecord > KnowledgeVector
Copyright(c) 2020 Galois.