49 for (
size_t index = 0; index < vector_.size(); ++index)
50 context_->mark_modified(vector_[index]);
58 std::stringstream result;
60 result <<
"Integer Vector: ";
65 MADARA_GUARD_TYPE guard(mutex_);
66 size_t elements = vector_.size();
68 result << this->name_;
69 result <<
" [" << elements <<
"]";
74 result <<
context_->get(vector_[0]).to_string();
76 for (
size_t index = 1; index < elements; ++index)
78 result <<
", " <<
context_->get(vector_[index]).to_string();
95 return get_debug_info();
106 if (
context_ && name_ !=
"" && index < vector_.size())
109 context_->mark_modified(vector_[index]);
118 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
121 this->name_ = rhs.
name_;
123 this->size_ = rhs.
size_;
134 MADARA_GUARD_TYPE guard(mutex_);
136 if (!size_.is_valid())
138 size_ = get_size_ref();
155 std::stringstream buffer;
158 MADARA_GUARD_TYPE guard(mutex_);
161 buffer << delimiter_;
164 ref =
context_->get_ref(buffer.str(), keep_local);
171 int size,
bool delete_vars)
176 MADARA_GUARD_TYPE guard(mutex_);
178 if (!size_.is_valid())
180 size_ = get_size_ref();
185 size_t old_size = vector_.size();
187 if (old_size != (
size_t)size)
189 vector_.resize(size);
194 if ((
size_t)size > old_size)
196 for (; old_size < (size_t)size; ++old_size)
198 std::stringstream buffer;
200 buffer << delimiter_;
202 vector_[old_size] =
context_->get_ref(buffer.str(), settings_);
205 else if (delete_vars)
207 for (; (size_t)size < old_size; ++size)
209 std::stringstream buffer;
211 buffer << delimiter_;
214 context_->delete_variable(buffer.str(), settings_);
222 size_t cur_size = (size_t)
context_->get(size_, settings_).to_integer();
224 size_t old_size = vector_.size();
226 if (old_size != cur_size)
228 vector_.resize(cur_size);
230 if (cur_size > old_size)
232 for (; old_size < cur_size; ++old_size)
234 std::stringstream buffer;
236 buffer << delimiter_;
238 vector_[old_size] =
context_->get_ref(buffer.str(), settings_);
241 else if (delete_vars)
243 for (; cur_size < old_size; ++cur_size)
245 std::stringstream buffer;
247 buffer << delimiter_;
250 context_->delete_variable(buffer.str(), settings_);
260 MADARA_GUARD_TYPE guard(mutex_);
261 return vector_.size();
272 MADARA_GUARD_TYPE guard(mutex_);
278 size_ = get_size_ref();
292 MADARA_GUARD_TYPE guard(mutex_);
309 MADARA_GUARD_TYPE guard(mutex_);
321 delimiter_ = delimiter;
325 MADARA_GUARD_TYPE guard(mutex_);
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)
362 context_->get(this->vector_[i], settings_);
377 std::stringstream buffer;
378 buffer << this->name_;
379 buffer << delimiter_;
386 this->
context_->set(this->vector_[i], zero, this->settings_);
390 std::stringstream buffer;
391 buffer << other.
name_;
392 buffer << delimiter_;
402 for (
size_t i = this_size; i < other_size; ++i)
404 std::stringstream buffer;
405 buffer << this->name_;
406 buffer << delimiter_;
421 this->resize(-1,
true);
436 MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
437 guard2(other.
mutex_, std::adopt_lock);
439 size_t other_size = other.
vector_.size();
440 size_t this_size = this->vector_.size();
442 size_t size = other_size + this_size;
445 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
450 this->resize(0,
true);
460 MADARA_GUARD_TYPE guard(mutex_);
462 target.resize(vector_.size());
464 for (
size_t i = 0; i < vector_.size(); ++i)
472 std::vector<type>& target)
const
477 MADARA_GUARD_TYPE guard(mutex_);
479 target.resize(vector_.size());
481 for (
size_t i = 0; i < vector_.size(); ++i)
483 target[i] = (*this)[i];
492 if (index < vector_.size() &&
context_)
495 MADARA_GUARD_TYPE guard(mutex_);
496 result =
context_->exists(vector_[index]);
508 if (index < vector_.size() &&
context_)
511 MADARA_GUARD_TYPE guard(mutex_);
512 result =
context_->get(vector_[index], keep_local);
524 if (index < vector_.size() &&
context_)
527 MADARA_GUARD_TYPE guard(mutex_);
528 result =
context_->get(vector_[index], keep_local);
544 MADARA_GUARD_TYPE guard(mutex_);
547 context_->get(vector_[vector_.size() - 1], keep_local).to_integer());
549 for (
size_t i = 0; i < vector_.size() - 1; ++i)
559 size_t index,
const type& value)
563 if (index < vector_.size() &&
context_)
566 MADARA_GUARD_TYPE guard(mutex_);
567 result =
context_->set(vector_[index], value, settings_);
578 if (index < vector_.size() &&
context_)
581 MADARA_GUARD_TYPE guard(mutex_);
582 result =
context_->inc(vector_[index], settings_).to_integer();
593 if (index < vector_.size() &&
context_)
596 MADARA_GUARD_TYPE guard(mutex_);
597 result =
context_->set(vector_[index], value, settings);
604 const std::vector<type>& value)
611 MADARA_GUARD_TYPE guard(mutex_);
612 if (vector_.size() < value.size())
613 resize((
int)value.size(),
false);
615 for (
size_t i = 0; i < value.size(); ++i)
617 context_->set(vector_[i], value[i], settings_);
634 MADARA_GUARD_TYPE guard(mutex_);
635 if (vector_.size() < value.size())
636 resize((
int)value.size(),
false);
638 for (
size_t i = 0; i < value.size(); ++i)
640 context_->set(vector_[i], value[i], settings);
652 if (index < vector_.size() &&
context_)
655 MADARA_GUARD_TYPE guard(mutex_);
656 context_->set_quality(vector_[index].get_name(), quality,
true, settings);
665 "IntegerVector::is_true: Checking for truth\n");
670 MADARA_GUARD_TYPE guard(mutex_);
675 "IntegerVector::is_true: context was not null. Result changed to %d\n",
678 for (
size_t index = 0; index < vector_.size(); ++index)
681 "IntegerVector::is_true: checking index %d, is_false of %d. \n",
682 (
int)result, (
int)
context_->get(vector_[index]).is_false());
684 if (
context_->get(vector_[index]).is_false())
687 "IntegerVector::is_true: result is false, breaking\n");
694 if (vector_.size() == 0)
699 "IntegerVector::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_
madara::knowledge::KnowledgeRecord KnowledgeRecord
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.
void set_index(size_t index, T value)
sets the value at the index to the specified value.
Integer to_integer(void) const
converts the value to an integer.
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...
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 integers inside of KaRL.
VariableReference size_
Reference to the size field of the vector space.
int set(size_t index, const type &value=madara::knowledge::KnowledgeRecord::MODIFIED)
Sets a knowledge variable to a specified value.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
virtual BaseContainer * clone(void) const
Clones this container.
type operator[](size_t index) const
Retrieves a copy of the record from the map.
void modify(void)
Mark the vector as modified.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
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 void modify_(void)
Polymorphic modify method used by collection containers.
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
std::vector< VariableReference > vector_
Values of the array.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
void push_back(type value)
Pushes the value to the end of the array after incrementing the array size.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
void transfer_to(IntegerVector &other)
Transfers elements from this vector to another.
size_t size(void) const
Returns the size of the local vector.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
virtual ~IntegerVector()
Destructor.
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.
std::string delimiter_
Delimiter for the prefix to subvars.
type inc(size_t index)
Increments an index by a specified value.
knowledge::KnowledgeRecord to_record(void) const
Retrieves the entire vector as a native double array in a record.
void operator=(const IntegerVector &rhs)
Assignment operator.
bool is_true(void) const
Determines if all values in the vector are true.
IntegerVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
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 ...
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
ThreadSafeContext * context_
Variable context that we are modifying.
bool is_false(void) const
Determines if the value of the vector is false.
void exchange(IntegerVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
Provides functions and classes for the distributed knowledge base.
::std::vector< KnowledgeRecord > KnowledgeVector