39 delimiter_(rhs.delimiter_)
50 for (
size_t index = 0; index < vector_.size(); ++index)
51 context_->mark_modified(vector_[index]);
60 std::stringstream result;
62 result <<
"Double Vector: ";
67 MADARA_GUARD_TYPE guard(mutex_);
68 size_t elements = vector_.size();
70 result << this->name_;
71 result <<
" [" << elements <<
"]";
76 result <<
context_->get(vector_[0]).to_string();
78 for (
size_t index = 1; index < elements; ++index)
80 result <<
", " <<
context_->get(vector_[index]).to_string();
98 return get_debug_info();
109 if (
context_ && name_ !=
"" && index < vector_.size())
112 context_->mark_modified(vector_[index]);
121 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
124 this->name_ = rhs.
name_;
126 this->size_ = rhs.
size_;
138 MADARA_GUARD_TYPE guard(mutex_);
140 if (!size_.is_valid())
142 size_ = get_size_ref();
159 std::stringstream buffer;
162 MADARA_GUARD_TYPE guard(mutex_);
165 buffer << delimiter_;
168 ref =
context_->get_ref(buffer.str(), keep_local);
175 int size,
bool delete_vars)
180 MADARA_GUARD_TYPE guard(mutex_);
182 if (!size_.is_valid())
184 size_ = get_size_ref();
189 size_t old_size = vector_.size();
191 if (old_size != (
size_t)size)
193 vector_.resize(size);
198 if ((
size_t)size > old_size)
200 for (; old_size < (size_t)size; ++old_size)
202 std::stringstream buffer;
204 buffer << delimiter_;
206 vector_[old_size] =
context_->get_ref(buffer.str(), settings_);
209 else if (delete_vars)
211 for (; (size_t)size < old_size; ++size)
213 std::stringstream buffer;
215 buffer << delimiter_;
218 context_->delete_variable(buffer.str(), settings_);
226 size_t cur_size = (size_t)
context_->get(size_, settings_).to_integer();
228 size_t old_size = vector_.size();
230 if (old_size != cur_size)
232 vector_.resize(cur_size);
234 if (cur_size > old_size)
236 for (; old_size < (size_t)cur_size; ++old_size)
238 std::stringstream buffer;
240 buffer << delimiter_;
242 vector_[old_size] =
context_->get_ref(buffer.str(), settings_);
245 else if (delete_vars)
247 for (; (size_t)cur_size < old_size; ++cur_size)
249 std::stringstream buffer;
251 buffer << delimiter_;
254 context_->delete_variable(buffer.str(), settings_);
264 MADARA_GUARD_TYPE guard(mutex_);
265 return vector_.size();
276 MADARA_GUARD_TYPE guard(mutex_);
282 size_ = get_size_ref();
296 MADARA_GUARD_TYPE guard(mutex_);
313 MADARA_GUARD_TYPE guard(mutex_);
325 delimiter_ = delimiter;
329 MADARA_GUARD_TYPE guard(mutex_);
351 MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
352 guard2(other.
mutex_, std::adopt_lock);
360 size_t other_size = other.
vector_.size();
361 size_t this_size = this->vector_.size();
363 for (
size_t i = 0; i < this_size; ++i)
367 context_->get(this->vector_[i], settings_);
382 std::stringstream buffer;
383 buffer << this->name_;
384 buffer << delimiter_;
391 this->
context_->set(this->vector_[i], zero, this->settings_);
395 std::stringstream buffer;
396 buffer << other.
name_;
397 buffer << delimiter_;
407 for (
size_t i = this_size; i < other_size; ++i)
409 std::stringstream buffer;
410 buffer << this->name_;
411 buffer << delimiter_;
426 this->resize(-1,
true);
441 MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
442 guard2(other.
mutex_, std::adopt_lock);
444 size_t other_size = other.
vector_.size();
445 size_t this_size = this->vector_.size();
447 size_t size = other_size + this_size;
450 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
455 this->resize(0,
true);
465 MADARA_GUARD_TYPE guard(mutex_);
467 target.resize(vector_.size());
469 for (
size_t i = 0; i < vector_.size(); ++i)
477 std::vector<IntegerVectorVector::type>& target)
const
482 MADARA_GUARD_TYPE guard(mutex_);
484 target.resize(vector_.size());
486 for (
size_t i = 0; i < vector_.size(); ++i)
488 target[i] = (*this)[i];
500 if (index < vector_.size() &&
context_)
503 MADARA_GUARD_TYPE guard(mutex_);
504 result =
context_->get(vector_[index], keep_local);
517 if (index.
x < vector_.size() &&
context_)
520 MADARA_GUARD_TYPE guard(mutex_);
522 context_->get(vector_[index.
x], keep_local).retrieve_index(index.
y);
535 if (index < vector_.size() &&
context_)
538 MADARA_GUARD_TYPE guard(mutex_);
539 result =
context_->get(vector_[index], keep_local);
550 if (index < vector_.size() &&
context_)
553 MADARA_GUARD_TYPE guard(mutex_);
554 result =
context_->exists(vector_[index]);
561 size_t index,
type value)
565 if (index < vector_.size() &&
context_)
568 MADARA_GUARD_TYPE guard(mutex_);
569 result =
context_->set(vector_[index], value, settings_);
576 const std::vector<type>& value)
583 MADARA_GUARD_TYPE guard(mutex_);
584 if (vector_.size() < value.size())
585 resize((
int)value.size(),
false);
587 for (
size_t i = 0; i < value.size(); ++i)
589 context_->set(vector_[i], value[i], settings_);
603 if (index < vector_.size() &&
context_)
606 MADARA_GUARD_TYPE guard(mutex_);
607 result =
context_->set(vector_[index], value, settings);
621 MADARA_GUARD_TYPE guard(mutex_);
622 if (vector_.size() < value.size())
623 resize((
int)value.size(),
false);
625 for (
size_t i = 0; i < value.size(); ++i)
627 context_->set(vector_[i], value[i], settings);
639 if (index < vector_.size() &&
context_)
642 MADARA_GUARD_TYPE guard(mutex_);
643 context_->set_quality(vector_[index].get_name(), quality,
true, settings);
652 "IntegerVectorVector::is_true: Checking for truth\n");
657 MADARA_GUARD_TYPE guard(mutex_);
662 "IntegerVectorVector::is_true: context was not null. Result changed to "
666 for (
size_t index = 0; index < vector_.size(); ++index)
669 "IntegerVectorVector::is_true: checking index %d, is_false of %d. \n",
670 (
int)result, (
int)
context_->get(vector_[index]).is_false());
672 if (
context_->get(vector_[index]).is_false())
675 "IntegerVectorVector::is_true: result is false, breaking\n");
682 if (vector_.size() == 0)
687 "IntegerVectorVector::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.
std::vector< Integer > to_integers(void) const
converts the value to a vector of integers
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 NativeIntegerVectors.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
bool is_true(void) const
Determines if all values in the vector are true.
void exchange(IntegerVectorVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
type operator[](size_t index) const
Retrieves a copy of the record from the vector.
virtual BaseContainer * clone(void) const
Clones this container.
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
std::string delimiter_
Delimiter for the prefix to subvars.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
IntegerVectorVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
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 * context_
Variable context that we are modifying.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
int set(size_t index, type value)
Sets a knowledge variable to a specified value.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
std::vector< int64_t > type
trait that describes the value type
virtual ~IntegerVectorVector()
Destructor.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
knowledge::KnowledgeRecord to_record(size_t index) const
Retrieves a copy of the record from the vector.
void push_back(const type &value)
Pushes the value to the end of the array after incrementing the array size.
size_t size(void) const
Returns the size of the local vector.
VariableReference size_
Reference to the size field of the vector space.
void operator=(const IntegerVectorVector &rhs)
Assignment operator.
bool is_false(void) const
Determines if the value of the vector is false.
void transfer_to(IntegerVectorVector &other)
Transfers elements from this vector to another.
std::vector< VariableReference > vector_
Values of the array.
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_quality(size_t index, uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to a certain variable from this entity.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
void modify(void)
Mark the vector as modified.
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.
Provides functions and classes for the distributed knowledge base.
::std::vector< KnowledgeRecord > KnowledgeVector