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_);
349 MADARA_GUARD_TYPE guard(mutex_), guard2(other.
mutex_);
357 size_t other_size = other.
vector_.size();
358 size_t this_size = this->vector_.size();
360 for (
size_t i = 0; i < this_size; ++i)
364 context_->get(this->vector_[i], settings_);
379 std::stringstream buffer;
380 buffer << this->name_;
381 buffer << delimiter_;
388 this->
context_->set(this->vector_[i], zero, this->settings_);
392 std::stringstream buffer;
393 buffer << other.
name_;
394 buffer << delimiter_;
404 for (
size_t i = this_size; i < other_size; ++i)
406 std::stringstream buffer;
407 buffer << this->name_;
408 buffer << delimiter_;
423 this->resize(-1,
true);
438 MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
439 guard2(other.
mutex_, std::adopt_lock);
441 size_t other_size = other.
vector_.size();
442 size_t this_size = this->vector_.size();
444 size_t size = other_size + this_size;
447 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
452 this->resize(0,
true);
462 MADARA_GUARD_TYPE guard(mutex_);
464 target.resize(vector_.size());
466 for (
size_t i = 0; i < vector_.size(); ++i)
474 std::vector<type>& target)
const
479 MADARA_GUARD_TYPE guard(mutex_);
481 target.resize(vector_.size());
483 for (
size_t i = 0; i < vector_.size(); ++i)
485 target[i] = (*this)[i];
497 if (index < vector_.size() &&
context_)
500 MADARA_GUARD_TYPE guard(mutex_);
501 result =
context_->get(vector_[index], keep_local);
514 if (index.
x < vector_.size() &&
context_)
517 MADARA_GUARD_TYPE guard(mutex_);
519 context_->get(vector_[index.
x], keep_local).retrieve_index(index.
y);
531 if (index < vector_.size() &&
context_)
534 MADARA_GUARD_TYPE guard(mutex_);
535 result =
context_->get(vector_[index], keep_local);
546 if (index < vector_.size() &&
context_)
549 MADARA_GUARD_TYPE guard(mutex_);
550 result =
context_->exists(vector_[index]);
557 size_t index,
type value)
561 if (index < vector_.size() &&
context_)
564 MADARA_GUARD_TYPE guard(mutex_);
565 result =
context_->set(vector_[index], value, settings_);
572 const std::vector<type>& value)
579 MADARA_GUARD_TYPE guard(mutex_);
580 if (vector_.size() < value.size())
581 resize((
int)value.size(),
false);
583 for (
size_t i = 0; i < value.size(); ++i)
585 context_->set(vector_[i], value[i], settings_);
599 if (index < vector_.size() &&
context_)
602 MADARA_GUARD_TYPE guard(mutex_);
603 result =
context_->set(vector_[index], value, settings);
617 MADARA_GUARD_TYPE guard(mutex_);
618 if (vector_.size() < value.size())
619 resize((
int)value.size(),
false);
621 for (
size_t i = 0; i < value.size(); ++i)
623 context_->set(vector_[i], value[i], settings);
635 if (index < vector_.size() &&
context_)
638 MADARA_GUARD_TYPE guard(mutex_);
639 context_->set_quality(vector_[index].get_name(), quality,
true, settings);
648 "DoubleVectorVector::is_true: Checking for truth\n");
653 MADARA_GUARD_TYPE guard(mutex_);
658 "DoubleVectorVector::is_true: context was not null. Result changed to "
662 for (
size_t index = 0; index < vector_.size(); ++index)
665 "DoubleVectorVector::is_true: checking index %d, is_false of %d. \n",
666 (
int)result, (
int)
context_->get(vector_[index]).is_false());
668 if (
context_->get(vector_[index]).is_false())
671 "DoubleVectorVector::is_true: result is false, breaking\n");
678 if (vector_.size() == 0)
683 "DoubleVectorVector::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.
double to_double(void) const
converts the value to a float/double.
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.
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 NativeDoubleVectors.
size_t size(void) const
Returns the size of the local vector.
std::vector< VariableReference > vector_
Values of the array.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
knowledge::KnowledgeRecord to_record(size_t index) const
Retrieves a copy of the record from the vector.
type operator[](size_t index) const
Retrieves a copy of the record from the vector.
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 void modify_(void)
Polymorphic modify method used by collection containers.
void operator=(const DoubleVectorVector &rhs)
Assignment operator.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
void modify(void)
Mark the vector as modified.
std::vector< double > type
trait that describes the value type
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.
bool is_true(void) const
Determines if all values in the vector are true.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true.
void push_back(const type &value)
Pushes the value to the end of the array after incrementing the array size.
void exchange(DoubleVectorVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
virtual BaseContainer * clone(void) const
Clones this container.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
int set(size_t index, type value)
Sets a knowledge variable to a specified value.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
std::string delimiter_
Delimiter for the prefix to subvars.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
ThreadSafeContext * context_
Variable context that we are modifying.
virtual ~DoubleVectorVector()
Destructor.
DoubleVectorVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
VariableReference size_
Reference to the size field of the vector space.
void transfer_to(DoubleVectorVector &other)
Transfers elements from this vector to another.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
bool is_false(void) const
Determines if the value of the vector is false.
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