8 :
BaseContainer (
"", settings), context_ (0), delimiter_ (delimiter)
23 resize (dimensions, delete_vars);
37 resize (dimensions, delete_vars);
64 if (dimensions.
x > 0 && dimensions.
y > 0)
66 for (
size_t i = 0; i < dimensions.
x; ++i)
68 for (
size_t j = 0; j < dimensions.
y; ++j)
82 std::stringstream result;
84 result <<
"DoubleVector2D: ";
92 result << this->
name_;
93 result <<
" [" << dimensions.
x <<
"," << dimensions.
y <<
"]";
96 if (dimensions.
x > 0 && dimensions.
y > 0)
98 for (
size_t i = 0; i < dimensions.
x; ++i)
102 for (
size_t j = 1; j < dimensions.
y; ++j)
113 return result.str ();
170 std::stringstream buffer;
186 const Dimensions & dimensions,
bool delete_vars)
193 "DoubleVector2D::resize: resizing to [%d,%d]\n",
194 (int)dimensions.
x, (
int)dimensions.
y);
196 bool is_reset = dimensions.
x == 0 && dimensions.
y == 0;
208 "DoubleVector2D::resize: old size is [%d,%d]\n",
209 (int)old_size.
x, (
int)old_size.
y);
214 "DoubleVector2D::resize: new size is being reset to size in KB\n");
216 new_size.
x = old_size.
x;
217 new_size.
y = old_size.
y;
223 "DoubleVector2D::resize: using dimensions passed in.\n");
226 std::vector <KnowledgeRecord::Integer> update (2);
227 update[0] = dimensions.
x;
228 update[1] = dimensions.
y;
236 for (
size_t i = 0; i < new_size.
x; ++i)
239 "DoubleVector2D::resize: resizing vector_[%d] to %d.\n",
240 (int)i, (
int)new_size.
y);
246 size_t start = old_size.
y;
250 if (is_reset || (old_size.
x < new_size.
x && i >= old_size.
x))
256 "DoubleVector2D::resize: creating var_refs from %d->%d.\n",
257 (int)start, (
int)new_size.
y);
260 for (
size_t j = start; j < new_size.
y; ++j)
262 std::stringstream var_name;
263 var_name << this->
name_;
274 if ((new_size.
x < old_size.
x || new_size.
y < old_size.
y) && delete_vars)
277 "DoubleVector2D::resize: deleting refs: rows: 0->%d.\n",
281 for (
size_t i = 0; i < old_size.
x; ++i)
284 size_t start = new_size.
y;
287 if (old_size.
x > new_size.
x && i >= new_size.
x)
293 "DoubleVector2D::resize: deleting refs: %d:%d->%d.\n",
294 (int)i, (
int)start, (int)old_size.
x);
297 for (
size_t j = start; j < old_size.
y; ++j)
299 std::stringstream var_name;
300 var_name << this->
name_;
307 "DoubleVector2D::resize: deleting ref: %s.\n",
308 var_name.str ().c_str ());
332 std::vector <KnowledgeRecord::Integer> sizes (record.
to_integers ());
333 cur_size.
x = (size_t) (sizes.size () >= 2 ? sizes[0] : 0);
334 cur_size.
y = (size_t) (sizes.size () >= 2 ? sizes[1] : 0);
420 std::vector <std::vector <type> > & target)
const 430 target.resize (dimensions.
x);
432 for (
size_t i = 0; i < dimensions.
x; ++i)
434 target[i].resize (dimensions.
y);
435 for (
size_t j = 0; j < dimensions.
y; ++j)
507 const std::vector<std::vector<type> > & value)
515 for (
size_t i = 0; i < value.size () && i <
vector_.size (); ++i)
517 for (
size_t j = 0; j < value[i].size () && j <
vector_[i].size (); ++j)
551 const std::vector<std::vector<type> > & value,
560 for (
size_t i = 0; i < value.size () && i <
vector_.size (); ++i)
562 for (
size_t j = 0; j < value[i].size () && j <
vector_[i].size (); ++j)
594 "DoubleVector2D::is_true: Checking for truth\n");
603 "DoubleVector2D::is_true: context was not null. Result changed to %d\n",
606 for (
size_t i = 0; i <
vector_.size (); ++i)
608 for (
size_t j = 0; j <
vector_[i].size (); ++i)
611 "DoubleVector2D::is_true: checking [%d,%d], is_false of %d. \n",
617 "DoubleVector2D::is_true: result is false, breaking\n");
630 "DoubleVector2D::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.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
void operator=(const DoubleVector2D &rhs)
Assignment operator.
double to_double(void) const
converts the value to a float/double.
std::string name_
Prefix of variable.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
This class stores variables and their values for use by any entity needing state information in a thr...
Manages a 2D array of doubles as a virtual overlay in the KnowledgeBase.
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.
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.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
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 set_name(const std::string &var_name, KnowledgeBase &knowledge, const Dimensions &dimensions={0, 0})
Sets the variable name that this refers to.
double type
convenience typedef for element type
A thread-safe guard for a context or knowledge base.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
virtual BaseContainer * clone(void) const
Clones this container.
std::vector< std::vector< VariableReference > > vector_
Values of the array.
This class provides a distributed knowledge base to users.
ThreadSafeContext * context_
Variable context that we are modifying.
bool exists(const Indices &index) const
Checks to see if the index has ever been assigned a value.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
type operator[](const Indices &index) const
Retrieves an index from the multi-dimensional array.
void set_quality(const Indices &index, uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to a certain variable from this entity.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
virtual ~DoubleVector2D()
Destructor.
bool delete_variable(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Deletes the key.
bool is_false(void) const
Determines if the value of the vector is false.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
void copy_to(std::vector< std::vector< type > > &target) const
Copies the vector elements to an STL vector.
std::vector< Integer > to_integers(void) const
converts the value to a vector of integers
Dimensions size(void) const
Returns the size of the local vector.
Provides functions and classes for the distributed knowledge base.
void modify(void)
Mark the vector as modified.
KnowledgeUpdateSettings settings_
Settings for modifications.
void resize(const Dimensions &dimensions, bool delete_vars=true)
Resizes the vector.
std::string delimiter_
Delimiter for the prefix to subvars.
Settings for applying knowledge updates.
bool is_true(void) const
Determines if all values in the vector are true.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
VariableReference size_
Reference to the size of 2D array.
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.
int set(const Indices &index, double value)
Sets a knowledge variable to a specified value.
VariableReference get_size_ref(void)
Returns a reference to the size of vector.
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 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...
DoubleVector2D(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.