37 delimiter_(rhs.delimiter_)
48 MADARA_GUARD_TYPE guard(mutex_);
50 for (
size_t index = 0; index < vector_.size(); ++index)
51 context_->mark_modified(vector_[index]);
59 std::stringstream result;
66 MADARA_GUARD_TYPE guard(mutex_);
67 size_t elements = vector_.size();
69 result << this->name_;
70 result <<
" [" << elements <<
"]";
75 result <<
context_->get(vector_[0]).to_string();
77 for (
size_t index = 1; index < elements; ++index)
79 result <<
", " <<
context_->get(vector_[index]).to_string();
96 return get_debug_info();
107 if (
context_ && name_ !=
"" && index < vector_.size())
110 MADARA_GUARD_TYPE guard(mutex_);
112 context_->mark_modified(vector_[index]);
120 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
123 this->name_ = rhs.
name_;
125 this->size_ = rhs.
size_;
138 std::stringstream buffer;
141 MADARA_GUARD_TYPE guard(mutex_);
144 buffer << delimiter_;
147 ref =
context_->get_ref(buffer.str(), keep_local);
159 MADARA_GUARD_TYPE guard(mutex_);
161 if (!size_.is_valid())
163 size_ = get_size_ref();
190 set_file(i, unmanaged, size);
205 MADARA_GUARD_TYPE guard(mutex_);
207 if (!size_.is_valid())
209 size_ = get_size_ref();
214 size_t old_size = vector_.size();
216 if (old_size != (
size_t)size)
218 vector_.resize(size);
223 if ((
size_t)size > old_size)
225 for (; old_size < (size_t)size; ++old_size)
227 std::stringstream buffer;
229 buffer << delimiter_;
231 vector_[old_size] =
context_->get_ref(buffer.str(), settings_);
234 else if (delete_vars)
236 for (; (size_t)size < old_size; ++size)
238 std::stringstream buffer;
240 buffer << delimiter_;
243 context_->delete_variable(buffer.str(), settings_);
251 size_t cur_size =
context_->get(size_, settings_).to_integer();
253 size_t old_size = vector_.size();
255 if (old_size != cur_size)
257 vector_.resize(cur_size);
259 if (cur_size > old_size)
261 for (; old_size < cur_size; ++old_size)
263 std::stringstream buffer;
265 buffer << delimiter_;
267 vector_[old_size] =
context_->get_ref(buffer.str(), settings_);
270 else if (delete_vars)
272 for (; cur_size < old_size; ++cur_size)
274 std::stringstream buffer;
276 buffer << delimiter_;
279 context_->delete_variable(buffer.str(), settings_);
288 Vector& other,
bool refresh_keys,
bool delete_keys)
296 MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
297 guard2(other.
mutex_, std::adopt_lock);
305 size_t other_size = other.
vector_.size();
306 size_t this_size = this->vector_.size();
308 for (
size_t i = 0; i < this_size; ++i)
312 context_->get(this->vector_[i], settings_);
318 context_->set(this->vector_[i], std::move(val), settings_);
327 std::stringstream buffer;
328 buffer << this->name_;
330 buffer << delimiter_;
337 this->
context_->set(this->vector_[i], empty, this->settings_);
341 std::stringstream buffer;
342 buffer << other.
name_;
343 buffer << delimiter_;
353 for (
size_t i = this_size; i < other_size; ++i)
355 std::stringstream buffer;
356 buffer << this->name_;
357 buffer << delimiter_;
365 this->
context_->set(this->size_, other_size, this->settings_);
370 this->resize(-1,
true);
384 MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
385 guard2(other.
mutex_, std::adopt_lock);
387 size_t other_size = other.
vector_.size();
388 size_t this_size = this->vector_.size();
390 size_t size = other_size + this_size;
393 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
398 this->resize(0,
true);
408 MADARA_GUARD_TYPE guard(mutex_);
410 target.resize(vector_.size());
412 for (
size_t i = 0; i < vector_.size(); ++i)
414 target[i].deep_copy((*
this)[i]);
425 if (index < vector_.size() &&
context_)
428 MADARA_GUARD_TYPE guard(mutex_);
429 result =
context_->get(vector_[index], keep_local);
440 if (index < vector_.size() &&
context_)
443 MADARA_GUARD_TYPE guard(mutex_);
444 result =
context_->get(vector_[index], settings_);
454 if (index < vector_.size() &&
context_)
457 MADARA_GUARD_TYPE guard(mutex_);
458 result =
context_->exists(vector_[index]);
469 if (index < vector_.size() &&
context_)
472 MADARA_GUARD_TYPE guard(mutex_);
473 result =
context_->read_file(vector_[index], filename, settings_);
484 if (index < vector_.size() &&
context_)
487 MADARA_GUARD_TYPE guard(mutex_);
488 result =
context_->read_file(vector_[index], filename, settings);
495 size_t index,
const unsigned char* value,
size_t size)
499 if (index < vector_.size() &&
context_)
502 MADARA_GUARD_TYPE guard(mutex_);
503 result =
context_->set_file(vector_[index], value, size, settings_);
510 const unsigned char* value,
size_t size,
515 if (index < vector_.size() &&
context_)
518 MADARA_GUARD_TYPE guard(mutex_);
519 result =
context_->set_file(vector_[index], value, size, settings);
526 size_t index,
const unsigned char* value,
size_t size)
530 if (index < vector_.size() &&
context_)
533 MADARA_GUARD_TYPE guard(mutex_);
534 result =
context_->set_jpeg(vector_[index], value, size, settings_);
541 const unsigned char* value,
size_t size,
546 if (index < vector_.size() &&
context_)
549 MADARA_GUARD_TYPE guard(mutex_);
550 result =
context_->set_jpeg(vector_[index], value, size, settings);
560 if (index < vector_.size() &&
context_)
563 MADARA_GUARD_TYPE guard(mutex_);
564 result =
context_->set(vector_[index], value, settings_);
576 if (index < vector_.size() &&
context_)
579 MADARA_GUARD_TYPE guard(mutex_);
580 result =
context_->set(vector_[index], value, settings);
591 if (index < vector_.size() &&
context_)
594 MADARA_GUARD_TYPE guard(mutex_);
595 result =
context_->set_index(vector_[index], sub_index, value, settings_);
607 if (index < vector_.size() &&
context_)
610 MADARA_GUARD_TYPE guard(mutex_);
611 result =
context_->set_index(vector_[index], sub_index, value, settings);
622 if (index < vector_.size() &&
context_)
625 MADARA_GUARD_TYPE guard(mutex_);
626 result =
context_->set(vector_[index], value, size, settings_);
638 if (index < vector_.size() &&
context_)
641 MADARA_GUARD_TYPE guard(mutex_);
642 result =
context_->set(vector_[index], value, size, settings);
649 size_t index,
const std::vector<KnowledgeRecord::Integer>& value)
653 if (index < vector_.size() &&
context_)
656 MADARA_GUARD_TYPE guard(mutex_);
657 result =
context_->set(vector_[index], value, settings_);
664 const std::vector<KnowledgeRecord::Integer>& value,
669 if (index < vector_.size() &&
context_)
672 MADARA_GUARD_TYPE guard(mutex_);
673 result =
context_->set(vector_[index], value, settings);
683 if (index < vector_.size() &&
context_)
686 MADARA_GUARD_TYPE guard(mutex_);
687 result =
context_->set(vector_[index], value, settings_);
698 if (index < vector_.size() &&
context_)
701 MADARA_GUARD_TYPE guard(mutex_);
702 result =
context_->set(vector_[index], value, settings);
709 size_t index,
size_t sub_index,
double value)
713 if (index < vector_.size() &&
context_)
716 MADARA_GUARD_TYPE guard(mutex_);
717 result =
context_->set_index(vector_[index], sub_index, value, settings_);
728 if (index < vector_.size() &&
context_)
731 MADARA_GUARD_TYPE guard(mutex_);
732 result =
context_->set_index(vector_[index], sub_index, value, settings);
739 size_t index,
const double* value, uint32_t size)
743 if (index < vector_.size() &&
context_)
746 MADARA_GUARD_TYPE guard(mutex_);
747 result =
context_->set(vector_[index], value, size, settings_);
758 if (index < vector_.size() &&
context_)
761 MADARA_GUARD_TYPE guard(mutex_);
762 result =
context_->set(vector_[index], value, size, settings);
769 size_t index,
const std::vector<double>& value)
773 if (index < vector_.size() &&
context_)
776 MADARA_GUARD_TYPE guard(mutex_);
777 result =
context_->set(vector_[index], value, settings_);
788 if (index < vector_.size() &&
context_)
791 MADARA_GUARD_TYPE guard(mutex_);
792 result =
context_->set(vector_[index], value, settings);
803 if (index < vector_.size() &&
context_)
806 MADARA_GUARD_TYPE guard(mutex_);
807 result =
context_->set(vector_[index], value, settings_);
818 if (index < vector_.size() &&
context_)
821 MADARA_GUARD_TYPE guard(mutex_);
822 result =
context_->set(vector_[index], value, settings);
831 if (index < vector_.size() &&
context_)
834 MADARA_GUARD_TYPE guard(mutex_);
835 context_->set_quality(vector_[index].get_name(), quality,
true, settings);
844 "Vector::is_true: Checking for truth\n");
849 MADARA_GUARD_TYPE guard(mutex_);
854 "Vector::is_true: context was not null. Result changed to %d\n",
857 for (
size_t index = 0; index < vector_.size(); ++index)
860 "Vector::is_true: checking index %d, is_false of %d. \n", (
int)result,
861 (
int)
context_->get(vector_[index]).is_false());
863 if (
context_->get(vector_[index]).is_false())
866 "Vector::is_true: result is false, breaking\n");
873 if (vector_.size() == 0)
878 "Vector::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.
uint32_t type(void) const
returns the type of the value
std::vector< Integer > to_integers(void) const
converts the value to a vector of integers
double to_double(void) const
converts the value to a float/double.
bool is_binary_file_type(void) const
returns true if the knowledge record has a binary file type
Integer to_integer(void) const
converts the value to an integer.
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...
std::vector< double > to_doubles(void) const
converts the value to a vector of doubles
Settings for applying knowledge updates.
Settings for applying knowledge updates.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the current value of a variable.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
Optimized reference to a variable within the knowledge base.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
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 KaRL variables.
VariableReference size_
Reference to the size field of the vector space.
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.
std::vector< VariableReference > vector_
Values of the array.
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.
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.
void modify(void)
Mark the vector as modified.
knowledge::KnowledgeRecord operator[](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.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
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 is_true(void) const
Determines if all values in the vector are true.
void exchange(Vector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
ThreadSafeContext * context_
Variable context that we are modifying.
int set_file(size_t index, const unsigned char *value, size_t size)
Atomically sets the value of an index to an arbitrary string.
bool is_false(void) const
Determines if the value of the vector is false.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
virtual BaseContainer * clone(void) const
Clones this container.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
void transfer_to(Vector &other)
Transfers elements from this vector to another.
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 ...
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
void push_back(KnowledgeRecord value)
Pushes the value to the end of the array after incrementing the array size.
int set(size_t index, madara::knowledge::KnowledgeRecord::Integer value=madara::knowledge::KnowledgeRecord::MODIFIED)
Sets a knowledge variable to a specified value.
virtual ~Vector()
Destructor.
Vector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
void operator=(const Vector &rhs)
Assignment operator.
int read_file(size_t index, const std::string &filename)
Read a file into the index.
knowledge::KnowledgeRecord to_record(size_t index) const
Retrieves a copy of the record from the map.
size_t size(void) const
Returns the size of the local vector.
Provides functions and classes for the distributed knowledge base.
::std::vector< KnowledgeRecord > KnowledgeVector