8 :
BaseContainer (
"", settings), context_ (0), delimiter_ (delimiter)
23 resize (size, delete_vars);
37 resize (size, delete_vars);
62 for (
size_t index = 0; index <
vector_.size (); ++index)
72 std::stringstream result;
74 result <<
"String Vector: ";
79 MADARA_GUARD_TYPE guard (
mutex_);
80 size_t elements =
vector_.size ();
82 result << this->
name_;
83 result <<
" [" << elements <<
"]";
90 for (
size_t index = 1; index < elements; ++index)
155 std::stringstream buffer;
158 MADARA_GUARD_TYPE guard (
mutex_);
177 MADARA_GUARD_TYPE guard (
mutex_);
192 int size,
bool delete_vars)
197 MADARA_GUARD_TYPE guard (
mutex_);
206 size_t old_size =
vector_.size ();
208 if (old_size != (
size_t)size)
214 if ((
size_t)size > old_size)
216 for (; old_size < (size_t)size; ++old_size)
218 std::stringstream buffer;
225 else if (delete_vars)
227 for (; (size_t)size < old_size; ++
size)
229 std::stringstream buffer;
245 size_t old_size =
vector_.size ();
247 if (old_size != cur_size)
251 if (cur_size > old_size)
253 for (; old_size < cur_size; ++old_size)
255 std::stringstream buffer;
262 else if (delete_vars)
264 for (; cur_size < old_size; ++cur_size)
266 std::stringstream buffer;
282 MADARA_GUARD_TYPE guard (
mutex_);
296 MADARA_GUARD_TYPE guard (
mutex_);
318 MADARA_GUARD_TYPE guard (
mutex_);
337 MADARA_GUARD_TYPE guard (
mutex_);
354 MADARA_GUARD_TYPE guard (
mutex_);
370 StringVector & other,
bool refresh_keys,
bool delete_keys)
376 MADARA_GUARD_TYPE guard (
mutex_), guard2 (other.
mutex_);
384 size_t other_size = other.
vector_.size ();
385 size_t this_size = this->
vector_.size ();
387 for (
size_t i = 0; i < this_size; ++i)
406 std::stringstream buffer;
407 buffer << this->
name_;
419 std::stringstream buffer;
420 buffer << other.
name_;
432 for (
size_t i = this_size; i < other_size; ++i)
434 std::stringstream buffer;
435 buffer << this->
name_;
463 MADARA_GUARD_TYPE guard (
mutex_);
464 MADARA_GUARD_TYPE guard2 (other.
mutex_);
466 size_t other_size = other.
vector_.size ();
467 size_t this_size = this->
vector_.size ();
469 size_t size = other_size + this_size;
472 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
488 MADARA_GUARD_TYPE guard (
mutex_);
490 target.resize (
vector_.size ());
492 for (
size_t i = 0; i <
vector_.size (); ++i)
501 std::vector <type> & target)
const 506 MADARA_GUARD_TYPE guard (
mutex_);
508 target.resize (
vector_.size ());
510 for (
size_t i = 0; i <
vector_.size (); ++i)
512 target[i] = (*this)[i];
527 MADARA_GUARD_TYPE guard (
mutex_);
543 MADARA_GUARD_TYPE guard (
mutex_);
559 MADARA_GUARD_TYPE guard (
mutex_);
576 MADARA_GUARD_TYPE guard (
mutex_);
594 MADARA_GUARD_TYPE guard (
mutex_);
603 const std::vector <type> & value)
610 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)
628 const std::vector <type> & value,
636 MADARA_GUARD_TYPE guard (
mutex_);
637 if (
vector_.size () < value.size ())
638 resize ((
int)value.size (),
false);
640 for (
size_t i = 0; i < value.size (); ++i)
660 MADARA_GUARD_TYPE guard (
mutex_);
672 "StringVector::is_true: Checking for truth\n");
677 MADARA_GUARD_TYPE guard (
mutex_);
682 "StringVector::is_true: context was not null. Result changed to %d\n",
685 for (
size_t index = 0; index <
vector_.size (); ++index)
689 "StringVector::is_true: checking index %d, is_false of %d. \n",
695 "StringVector::is_true: result is false, breaking\n");
707 "StringVector::is_true: final result is %d\n", (int)result);
This class encapsulates an entry in a KnowledgeBase.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
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.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
std::string get_name(void) const
Returns the name of the container.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
madara::knowledge::KnowledgeRecord KnowledgeRecord
std::string name_
Prefix of variable.
std::string delimiter_
Delimiter for the prefix to subvars.
virtual BaseContainer * clone(void) const
Clones this container.
This class stores variables and their values for use by any entity needing state information in a thr...
ThreadSafeContext * context_
Variable context that we are modifying.
bool is_false(void) const
Determines if the value of the vector is false.
void transfer_to(StringVector &other)
Transfers elements from this vector to another.
MADARA_LOCK_TYPE mutex_
guard for access and changes
Optimized reference to a variable within the knowledge base.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
bool is_valid(void) const
Checks to see if the variable reference has been initialized.
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 std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
This class stores a vector of strings inside of KaRL.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
::std::vector< KnowledgeRecord > KnowledgeVector
void operator=(const StringVector &rhs)
Assignment operator.
type operator[](size_t index) const
Retrieves a copy of the record from the map.
A thread-safe guard for a context or knowledge base.
std::vector< VariableReference > vector_
Values of the array.
This class provides a distributed knowledge base to users.
void modify(void)
Mark the vector as modified.
StringVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
Integer to_integer(void) const
converts the value to an integer
void push_back(type value)
Pushes the value to the end of the array after incrementing the array size.
knowledge::KnowledgeRecord to_record(void) const
Retrieves the entire vector as a native double array in a record.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
bool delete_variable(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Deletes the key.
VariableReference size_
Reference to the size field of the vector space.
bool is_true(void) const
Determines if all values in the vector are true.
Provides functions and classes for the distributed knowledge base.
KnowledgeUpdateSettings settings_
Settings for modifications.
virtual ~StringVector()
Destructor.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
int set(size_t index, const type &value)
Sets a knowledge variable to a specified value.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
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.
Settings for applying knowledge updates.
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 ...
uint32_t set_quality(const std::string &key, uint32_t quality, bool force_update, const KnowledgeReferenceSettings &settings)
Atomically sets quality of this process for a variable.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
bool is_false(void) const
Checks to see if the record is false.
Settings for applying knowledge updates.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
void exchange(StringVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for g...
std::string type
trait that describes the value type
size_t size(void) const
Returns the size of the local vector.
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.