39 delimiter_(rhs.delimiter_)
50 for (
size_t index = 0; index < vector_.size(); ++index)
51 context_->mark_modified(vector_[index]);
59 std::stringstream result;
61 result <<
"Double Vector: ";
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 context_->mark_modified(vector_[index]);
119 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
122 this->name_ = rhs.
name_;
124 this->size_ = rhs.
size_;
135 MADARA_GUARD_TYPE guard(mutex_);
137 if (!size_.is_valid())
139 size_ = get_size_ref();
156 std::stringstream buffer;
159 MADARA_GUARD_TYPE guard(mutex_);
162 buffer << delimiter_;
165 ref =
context_->get_ref(buffer.str(), keep_local);
172 int size,
bool delete_vars)
177 MADARA_GUARD_TYPE guard(mutex_);
179 if (!size_.is_valid())
181 size_ = get_size_ref();
186 size_t old_size = vector_.size();
188 if (old_size != (
size_t)size)
190 vector_.resize(size);
195 if ((
size_t)size > old_size)
197 for (; old_size < (size_t)size; ++old_size)
199 std::stringstream buffer;
201 buffer << delimiter_;
203 vector_[old_size] =
context_->get_ref(buffer.str(), settings_);
206 else if (delete_vars)
208 for (; (size_t)size < old_size; ++size)
210 std::stringstream buffer;
212 buffer << delimiter_;
215 context_->delete_variable(buffer.str(), settings_);
223 size_t cur_size = (size_t)
context_->get(size_, settings_).to_integer();
225 size_t old_size = vector_.size();
227 if (old_size != cur_size)
229 vector_.resize(cur_size);
231 if (cur_size > old_size)
233 for (; old_size < (size_t)cur_size; ++old_size)
235 std::stringstream buffer;
237 buffer << delimiter_;
239 vector_[old_size] =
context_->get_ref(buffer.str(), settings_);
242 else if (delete_vars)
244 for (; (size_t)cur_size < old_size; ++cur_size)
246 std::stringstream buffer;
248 buffer << delimiter_;
251 context_->delete_variable(buffer.str(), settings_);
261 MADARA_GUARD_TYPE guard(mutex_);
262 return vector_.size();
273 MADARA_GUARD_TYPE guard(mutex_);
279 size_ = get_size_ref();
293 MADARA_GUARD_TYPE guard(mutex_);
310 MADARA_GUARD_TYPE guard(mutex_);
322 delimiter_ = delimiter;
326 MADARA_GUARD_TYPE guard(mutex_);
339 DoubleVector& other,
bool refresh_keys,
bool delete_keys)
347 MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
348 guard2(other.
mutex_, std::adopt_lock);
356 size_t other_size = other.
vector_.size();
357 size_t this_size = this->vector_.size();
359 for (
size_t i = 0; i < this_size; ++i)
363 context_->get(this->vector_[i], settings_);
378 std::stringstream buffer;
379 buffer << this->name_;
380 buffer << delimiter_;
387 this->
context_->set(this->vector_[i], zero, this->settings_);
391 std::stringstream buffer;
392 buffer << other.
name_;
393 buffer << delimiter_;
403 for (
size_t i = this_size; i < other_size; ++i)
405 std::stringstream buffer;
406 buffer << this->name_;
407 buffer << delimiter_;
422 this->resize(-1,
true);
437 MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
438 guard2(other.
mutex_, std::adopt_lock);
440 size_t other_size = other.
vector_.size();
441 size_t this_size = this->vector_.size();
443 size_t size = other_size + this_size;
446 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
451 this->resize(0,
true);
461 MADARA_GUARD_TYPE guard(mutex_);
463 target.resize(vector_.size());
465 for (
size_t i = 0; i < vector_.size(); ++i)
473 std::vector<double>& target)
const
478 MADARA_GUARD_TYPE guard(mutex_);
480 target.resize(vector_.size());
482 for (
size_t i = 0; i < vector_.size(); ++i)
484 target[i] = (*this)[i];
495 if (index < vector_.size() &&
context_)
498 MADARA_GUARD_TYPE guard(mutex_);
499 result =
context_->get(vector_[index], keep_local);
511 if (index < vector_.size() &&
context_)
514 MADARA_GUARD_TYPE guard(mutex_);
515 result =
context_->get(vector_[index], keep_local);
531 MADARA_GUARD_TYPE guard(mutex_);
535 context_->get(vector_[vector_.size() - 1], keep_local).to_double());
537 for (
size_t i = 0; i < vector_.size() - 1; ++i)
550 if (index < vector_.size() &&
context_)
553 MADARA_GUARD_TYPE guard(mutex_);
554 result =
context_->exists(vector_[index]);
564 if (index < vector_.size() &&
context_)
567 MADARA_GUARD_TYPE guard(mutex_);
568 result =
context_->set(vector_[index], value, settings_);
575 const std::vector<type>& value)
582 MADARA_GUARD_TYPE guard(mutex_);
583 if (vector_.size() < value.size())
584 resize((
int)value.size(),
false);
586 for (
size_t i = 0; i < value.size(); ++i)
588 context_->set(vector_[i], value[i], settings_);
602 if (index < vector_.size() &&
context_)
605 MADARA_GUARD_TYPE guard(mutex_);
606 result =
context_->set(vector_[index], value, settings);
620 MADARA_GUARD_TYPE guard(mutex_);
621 if (vector_.size() < value.size())
622 resize((
int)value.size(),
false);
624 for (
size_t i = 0; i < value.size(); ++i)
626 context_->set(vector_[i], value[i], settings);
638 if (index < vector_.size() &&
context_)
641 MADARA_GUARD_TYPE guard(mutex_);
642 context_->set_quality(vector_[index].get_name(), quality,
true, settings);
651 "DoubleVector::is_true: Checking for truth\n");
656 MADARA_GUARD_TYPE guard(mutex_);
661 "DoubleVector::is_true: context was not null. Result changed to %d\n",
664 for (
size_t index = 0; index < vector_.size(); ++index)
667 "DoubleVector::is_true: checking index %d, is_false of %d. \n",
668 (
int)result, (
int)
context_->get(vector_[index]).is_false());
670 if (
context_->get(vector_[index]).is_false())
673 "DoubleVector::is_true: result is false, breaking\n");
680 if (vector_.size() == 0)
685 "DoubleVector::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.
double to_double(void) const
converts the value to a float/double.
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 doubles inside of KaRL.
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 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.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
void transfer_to(DoubleVector &other)
Transfers elements from this vector to another.
size_t size(void) const
Returns the size of the local vector.
bool is_false(void) const
Determines if the value of the vector is false.
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.
bool is_true(void) const
Determines if all values in the vector are true.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
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.
virtual ~DoubleVector()
Destructor.
std::vector< VariableReference > vector_
Values of the array.
DoubleVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
knowledge::KnowledgeRecord to_record(void) const
Retrieves the entire vector as a native double array in a record.
void modify(void)
Mark the vector as modified.
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
void push_back(type value)
Pushes the value to the end of the array after incrementing the array size.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
void exchange(DoubleVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
void operator=(const DoubleVector &rhs)
Assignment operator.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
type operator[](size_t index) const
Retrieves a copy of the record from the vector.
ThreadSafeContext * context_
Variable context that we are modifying.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
double type
trait that describes the value type
int set(size_t index, type value)
Sets a knowledge variable to a specified value.
virtual BaseContainer * clone(void) const
Clones this container.
Provides functions and classes for the distributed knowledge base.
::std::vector< KnowledgeRecord > KnowledgeVector