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 <<
"String 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_;
137 std::stringstream buffer;
140 MADARA_GUARD_TYPE guard(mutex_);
143 buffer << delimiter_;
146 ref =
context_->get_ref(buffer.str(), keep_local);
157 MADARA_GUARD_TYPE guard(mutex_);
159 if (!size_.is_valid())
161 size_ = get_size_ref();
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 =
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_);
338 StringVector& other,
bool refresh_keys,
bool delete_keys)
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];
494 if (index < vector_.size() &&
context_)
497 MADARA_GUARD_TYPE guard(mutex_);
498 result =
context_->get(vector_[index], keep_local);
509 if (index < vector_.size() &&
context_)
512 MADARA_GUARD_TYPE guard(mutex_);
513 result =
context_->get(vector_[index], settings_);
523 if (index < vector_.size() &&
context_)
526 MADARA_GUARD_TYPE guard(mutex_);
527 result =
context_->exists(vector_[index]);
534 size_t index,
const type& value)
538 if (index < vector_.size() &&
context_)
541 MADARA_GUARD_TYPE guard(mutex_);
542 result =
context_->set(vector_[index], value, settings_);
553 if (index < vector_.size() &&
context_)
556 MADARA_GUARD_TYPE guard(mutex_);
557 result =
context_->set(vector_[index], value, settings);
564 const std::vector<type>& value)
571 MADARA_GUARD_TYPE guard(mutex_);
573 if (vector_.size() < value.size())
574 resize((
int)value.size(),
false);
576 for (
size_t i = 0; i < value.size(); ++i)
578 context_->set(vector_[i], value[i], settings_);
595 MADARA_GUARD_TYPE guard(mutex_);
596 if (vector_.size() < value.size())
597 resize((
int)value.size(),
false);
599 for (
size_t i = 0; i < value.size(); ++i)
601 context_->set(vector_[i], value[i], settings);
613 if (index < vector_.size() &&
context_)
616 MADARA_GUARD_TYPE guard(mutex_);
617 context_->set_quality(vector_[index].get_name(), quality,
true, settings);
626 "StringVector::is_true: Checking for truth\n");
631 MADARA_GUARD_TYPE guard(mutex_);
636 "StringVector::is_true: context was not null. Result changed to %d\n",
639 for (
size_t index = 0; index < vector_.size(); ++index)
642 "StringVector::is_true: checking index %d, is_false of %d. \n",
643 (
int)result, (
int)
context_->get(vector_[index]).is_false());
645 if (
context_->get(vector_[index]).is_false())
648 "StringVector::is_true: result is false, breaking\n");
655 if (vector_.size() == 0)
660 "StringVector::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::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
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 strings inside of KaRL.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
void modify(void)
Mark the vector as modified.
void operator=(const StringVector &rhs)
Assignment operator.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
type operator[](size_t index) const
Retrieves a copy of the record from the map.
std::string type
trait that describes the value type
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
std::vector< VariableReference > vector_
Values of the array.
StringVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
bool is_false(void) const
Determines if the value of the vector is false.
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 exchange(StringVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
bool is_true(void) const
Determines if all values in the vector are true.
knowledge::KnowledgeRecord to_record(void) const
Retrieves the entire vector as a native double array in a record.
ThreadSafeContext * context_
Variable context that we are modifying.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
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 copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
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 transfer_to(StringVector &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.
void push_back(type value)
Pushes the value to the end of the array after incrementing the array size.
VariableReference size_
Reference to the size field of the vector space.
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(size_t index, const type &value)
Sets a knowledge variable to a specified value.
size_t size(void) const
Returns the size of the local vector.
virtual BaseContainer * clone(void) const
Clones this container.
virtual ~StringVector()
Destructor.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
Provides functions and classes for the distributed knowledge base.
::std::vector< KnowledgeRecord > KnowledgeVector
::std::vector< std::string > StringVector