8 :
BaseContainer (
"", settings), context_ (0), delimiter_ (delimiter)
23 resize (size, delete_vars);
37 resize (size, delete_vars);
61 for (
size_t index = 0; index <
vector_.size (); ++index)
71 std::stringstream result;
73 result <<
"Double Vector: ";
78 MADARA_GUARD_TYPE guard (
mutex_);
79 size_t elements =
vector_.size ();
81 result << this->
name_;
82 result <<
" [" << elements <<
"]";
89 for (
size_t index = 1; index < elements; ++index)
152 MADARA_GUARD_TYPE guard (
mutex_);
173 std::stringstream buffer;
176 MADARA_GUARD_TYPE guard (
mutex_);
190 int size,
bool delete_vars)
195 MADARA_GUARD_TYPE guard (
mutex_);
204 size_t old_size =
vector_.size ();
206 if (old_size != (
size_t)size)
212 if ((
size_t)size > old_size)
214 for (; old_size < (size_t)size; ++old_size)
216 std::stringstream buffer;
223 else if (delete_vars)
225 for (; (size_t)size < old_size; ++
size)
227 std::stringstream buffer;
243 size_t old_size =
vector_.size ();
245 if (old_size != cur_size)
249 if (cur_size > old_size)
251 for (; old_size < (size_t)cur_size; ++old_size)
253 std::stringstream buffer;
260 else if (delete_vars)
262 for (; (size_t)cur_size < old_size; ++cur_size)
264 std::stringstream buffer;
280 MADARA_GUARD_TYPE guard (
mutex_);
294 MADARA_GUARD_TYPE guard (
mutex_);
316 MADARA_GUARD_TYPE guard (
mutex_);
335 MADARA_GUARD_TYPE guard (
mutex_);
352 MADARA_GUARD_TYPE guard (
mutex_);
368 DoubleVector & other,
bool refresh_keys,
bool delete_keys)
374 MADARA_GUARD_TYPE guard (
mutex_), guard2 (other.
mutex_);
382 size_t other_size = other.
vector_.size ();
383 size_t this_size = this->
vector_.size ();
385 for (
size_t i = 0; i < this_size; ++i)
404 std::stringstream buffer;
405 buffer << this->
name_;
417 std::stringstream buffer;
418 buffer << other.
name_;
430 for (
size_t i = this_size; i < other_size; ++i)
432 std::stringstream buffer;
433 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 <double> & 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_);
544 MADARA_GUARD_TYPE guard (
mutex_);
561 MADARA_GUARD_TYPE guard (
mutex_);
567 for (
size_t i = 0; i <
vector_.size () - 1; ++i)
586 MADARA_GUARD_TYPE guard (
mutex_);
603 MADARA_GUARD_TYPE guard (
mutex_);
613 const std::vector <type> & value)
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)
646 MADARA_GUARD_TYPE guard (
mutex_);
656 const std::vector <type> & value,
664 MADARA_GUARD_TYPE guard (
mutex_);
665 if (
vector_.size () < value.size ())
666 resize ((
int)value.size (),
false);
668 for (
size_t i = 0; i < value.size (); ++i)
688 MADARA_GUARD_TYPE guard (
mutex_);
700 "DoubleVector::is_true: Checking for truth\n");
705 MADARA_GUARD_TYPE guard (
mutex_);
710 "DoubleVector::is_true: context was not null. Result changed to %d\n",
713 for (
size_t index = 0; index <
vector_.size (); ++index)
717 "DoubleVector::is_true: checking index %d, is_false of %d. \n",
723 "DoubleVector::is_true: result is false, breaking\n");
735 "DoubleVector::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 modify(void)
Mark the vector as modified.
double type
trait that describes the value type
VariableReference size_
Reference to the size field of the vector space.
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
type operator[](size_t index) const
Retrieves a copy of the record from the vector.
double to_double(void) const
converts the value to a float/double
std::string name_
Prefix of variable.
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
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...
size_t size(void) const
Returns the size of the local vector.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
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.
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
knowledge::KnowledgeRecord to_record(void) const
Retrieves the entire vector as a native double array in a record.
::std::vector< KnowledgeRecord > KnowledgeVector
bool is_true(void) const
Determines if all values in the vector are true.
std::string delimiter_
Delimiter for the prefix to subvars.
A thread-safe guard for a context or knowledge base.
bool is_false(void) const
Determines if the value of the vector is false.
void operator=(const DoubleVector &rhs)
Assignment operator.
void exchange(DoubleVector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
This class provides a distributed knowledge base to users.
virtual ~DoubleVector()
Destructor.
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::vector< VariableReference > vector_
Values of the array.
void transfer_to(DoubleVector &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 set_index(size_t index, T value)
sets the value at the index to the specified value.
Integer to_integer(void) const
converts the value to an integer
int set(size_t index, type value)
Sets a knowledge variable to a specified value.
virtual BaseContainer * clone(void) const
Clones this container.
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 * context_
Variable context that we are modifying.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
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.
void push_back(type value)
Pushes the value to the end of the array after incrementing the array size.
Provides functions and classes for the distributed knowledge base.
KnowledgeUpdateSettings settings_
Settings for modifications.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
Settings for applying knowledge updates.
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.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true...
bool is_false(void) const
Checks to see if the record is false.
Settings for applying knowledge updates.
This class stores a vector of doubles inside of KaRL.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
DoubleVector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
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 copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.