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 <<
"Integer 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)
153 MADARA_GUARD_TYPE guard (
mutex_);
174 std::stringstream buffer;
177 MADARA_GUARD_TYPE guard (
mutex_);
191 int size,
bool delete_vars)
196 MADARA_GUARD_TYPE guard (
mutex_);
205 size_t old_size =
vector_.size ();
207 if (old_size != (
size_t)size)
213 if ((
size_t)size > old_size)
215 for (; old_size < (size_t)size; ++old_size)
217 std::stringstream buffer;
224 else if (delete_vars)
226 for (; (size_t)size < old_size; ++
size)
228 std::stringstream buffer;
244 size_t old_size =
vector_.size ();
246 if (old_size != cur_size)
250 if (cur_size > old_size)
252 for (; old_size < cur_size; ++old_size)
254 std::stringstream buffer;
261 else if (delete_vars)
263 for (; cur_size < old_size; ++cur_size)
265 std::stringstream buffer;
281 MADARA_GUARD_TYPE guard (
mutex_);
295 MADARA_GUARD_TYPE guard (
mutex_);
317 MADARA_GUARD_TYPE guard (
mutex_);
336 MADARA_GUARD_TYPE guard (
mutex_);
353 MADARA_GUARD_TYPE guard (
mutex_);
375 MADARA_GUARD_TYPE guard (
mutex_), guard2 (other.
mutex_);
383 size_t other_size = other.
vector_.size ();
384 size_t this_size = this->
vector_.size ();
386 for (
size_t i = 0; i < this_size; ++i)
405 std::stringstream buffer;
406 buffer << this->
name_;
418 std::stringstream buffer;
419 buffer << other.
name_;
431 for (
size_t i = this_size; i < other_size; ++i)
433 std::stringstream buffer;
434 buffer << this->
name_;
462 MADARA_GUARD_TYPE guard (
mutex_);
463 MADARA_GUARD_TYPE guard2 (other.
mutex_);
465 size_t other_size = other.
vector_.size ();
466 size_t this_size = this->
vector_.size ();
468 size_t size = other_size + this_size;
471 for (
size_t i = 0, j = other_size; i < this_size; ++i, ++j)
487 MADARA_GUARD_TYPE guard (
mutex_);
489 target.resize (
vector_.size ());
491 for (
size_t i = 0; i <
vector_.size (); ++i)
500 std::vector <type> & target)
const 505 MADARA_GUARD_TYPE guard (
mutex_);
507 target.resize (
vector_.size ());
509 for (
size_t i = 0; i <
vector_.size (); ++i)
511 target[i] = (*this)[i];
525 MADARA_GUARD_TYPE guard (
mutex_);
542 MADARA_GUARD_TYPE guard (
mutex_);
559 MADARA_GUARD_TYPE guard (
mutex_);
576 MADARA_GUARD_TYPE guard (
mutex_);
581 for (
size_t i = 0; i <
vector_.size () - 1; ++i)
601 MADARA_GUARD_TYPE guard (
mutex_);
617 MADARA_GUARD_TYPE guard (
mutex_);
635 MADARA_GUARD_TYPE guard (
mutex_);
644 const std::vector <type> & value)
651 MADARA_GUARD_TYPE guard (
mutex_);
652 if (
vector_.size () < value.size ())
653 resize ((
int)value.size (),
false);
655 for (
size_t i = 0; i < value.size (); ++i)
668 const std::vector <type> & value,
676 MADARA_GUARD_TYPE guard (
mutex_);
677 if (
vector_.size () < value.size ())
678 resize ((
int)value.size (),
false);
680 for (
size_t i = 0; i < value.size (); ++i)
700 MADARA_GUARD_TYPE guard (
mutex_);
712 "IntegerVector::is_true: Checking for truth\n");
717 MADARA_GUARD_TYPE guard (
mutex_);
722 "IntegerVector::is_true: context was not null. Result changed to %d\n",
725 for (
size_t index = 0; index <
vector_.size (); ++index)
729 "IntegerVector::is_true: checking index %d, is_false of %d. \n",
735 "IntegerVector::is_true: result is false, breaking\n");
747 "IntegerVector::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.
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=madara::knowledge::KnowledgeRecord::MODIFIED)
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 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.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true...
madara::knowledge::KnowledgeRecord KnowledgeRecord
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
std::string name_
Prefix of variable.
type inc(size_t index)
Increments an index by a specified value.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
This class stores variables and their values for use by any entity needing state information in a thr...
This class stores a vector of integers inside of KaRL.
MADARA_LOCK_TYPE mutex_
guard for access and changes
ThreadSafeContext * context_
Variable context that we are modifying.
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.
bool is_true(void) const
Determines if all values in the vector are true.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
::std::vector< KnowledgeRecord > KnowledgeVector
IntegerVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
type operator[](size_t index) const
Retrieves a copy of the record from the map.
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
A thread-safe guard for a context or knowledge base.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
size_t size(void) const
Returns the size of the local vector.
virtual ~IntegerVector()
Destructor.
void operator=(const IntegerVector &rhs)
Assignment operator.
This class provides a distributed knowledge base to users.
madara::knowledge::KnowledgeRecord inc(const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically increments the value of the variable.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
void modify(void)
Mark the vector as modified.
knowledge::KnowledgeRecord to_record(void) const
Retrieves the entire vector as a native double array in a record.
void set_index(size_t index, T value)
sets the value at the index to the specified value.
bool is_false(void) const
Determines if the value of the vector is false.
Integer to_integer(void) const
converts the value to an integer
VariableReference size_
Reference to the size field of the vector space.
void exchange(IntegerVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
std::vector< VariableReference > vector_
Values of the array.
bool delete_variable(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Deletes the key.
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.
KnowledgeUpdateSettings settings_
Settings for modifications.
std::string delimiter_
Delimiter for the prefix to subvars.
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
Settings for applying knowledge updates.
void transfer_to(IntegerVector &other)
Transfers elements from this vector to another.
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.
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.
virtual BaseContainer * clone(void) const
Clones this container.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
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...
void push_back(type value)
Pushes the value to the end of the array after incrementing the array size.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
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 ...
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.