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 && dimensions.
z > 0)
66 for (
size_t i = 0; i < dimensions.
x; ++i)
68 for (
size_t j = 0; j < dimensions.
y; ++j)
70 for (
size_t k = 0; k < dimensions.
z; ++k)
85 std::stringstream result;
87 result <<
"IntegerVector3D: ";
95 result << this->
name_;
96 result <<
" [" << dimensions.
x <<
"," <<
97 dimensions.
y <<
"," << dimensions.
z <<
"]";
100 if (dimensions.
x > 0 && dimensions.
y > 0)
102 for (
size_t i = 0; i < dimensions.
x; ++i)
104 for (
size_t j = 0; j < dimensions.
y; ++j)
108 for (
size_t k = 1; k < dimensions.
z; ++k)
120 return result.str ();
179 std::stringstream buffer;
195 const Dimensions & dimensions,
bool delete_vars)
202 "IntegerVector3D::resize: resizing to [%d,%d]\n",
203 (int)dimensions.
x, (
int)dimensions.
y);
205 bool is_reset = dimensions.
x == 0 && dimensions.
y == 0;
217 "IntegerVector3D::resize: old size is [%d,%d]\n",
218 (int)old_size.
x, (
int)old_size.
y);
223 "IntegerVector3D::resize: new size is being reset to size in KB\n");
225 new_size.
x = old_size.
x;
226 new_size.
y = old_size.
y;
227 new_size.
z = old_size.
z;
233 "IntegerVector3D::resize: using dimensions passed in.\n");
236 std::vector <KnowledgeRecord::Integer> update (3);
237 update[0] = dimensions.
x;
238 update[1] = dimensions.
y;
239 update[2] = dimensions.
z;
247 for (
size_t i = 0; i < new_size.
x; ++i)
250 "IntegerVector3D::resize: resizing vector_[%d] to %d.\n",
251 (int)i, (
int)new_size.
y);
257 size_t start = old_size.
y;
261 if (is_reset || (old_size.
x < new_size.
x && i >= old_size.
x))
267 "IntegerVector3D::resize: creating var_refs from %d->%d.\n",
268 (int)start, (
int)new_size.
y);
271 for (
size_t j = start; j < new_size.
y; ++j)
278 size_t start_z = old_size.
z;
281 if (is_reset || ((old_size.
y < new_size.
y && j >= old_size.
y) ||
282 (old_size.
x < new_size.
x && i >= old_size.
x)))
288 for (
size_t k = start_z; k < new_size.
z; ++k)
290 std::stringstream var_name;
291 var_name << this->
name_;
305 if ((new_size.
x < old_size.
x ||
306 new_size.
y < old_size.
y || new_size.
z < old_size.
z) && delete_vars)
309 "IntegerVector3D::resize: deleting refs: rows: 0->%d.\n",
313 for (
size_t i = 0; i < old_size.
x; ++i)
316 size_t start = new_size.
y;
319 if (old_size.
x > new_size.
x && i >= new_size.
x)
325 "IntegerVector3D::resize: deleting refs: %d:%d->%d.\n",
326 (int)i, (
int)start, (int)old_size.
x);
329 for (
size_t j = start; j < old_size.
y; ++j)
332 size_t start_k = new_size.
z;
335 if (old_size.
y > new_size.
y && j >= new_size.
y)
341 for (
size_t k = start_k; k < old_size.
z; ++k)
343 std::stringstream var_name;
344 var_name << this->
name_;
353 "IntegerVector3D::resize: deleting ref: %s.\n",
354 var_name.str ().c_str ());
379 std::vector <KnowledgeRecord::Integer> sizes (record.
to_integers ());
380 cur_size.
x = (size_t) (sizes.size () >= 3 ? sizes[0] : 0);
381 cur_size.
y = (size_t) (sizes.size () >= 3 ? sizes[1] : 0);
382 cur_size.
z = (size_t) (sizes.size () >= 3 ? sizes[2] : 0);
468 std::vector<std::vector<std::vector<type> > > & target)
const 478 target.resize (dimensions.
x);
480 for (
size_t i = 0; i < dimensions.
x; ++i)
482 target[i].resize (dimensions.
y);
483 for (
size_t j = 0; j < dimensions.
y; ++j)
485 target[i][j].resize (dimensions.
z);
486 for (
size_t k = 0; k < dimensions.
z; ++k)
505 "IntegerVector3D::[]: retrieving [%d,%d,%d].\n",
506 (int)index.
x,(
int)index.
y,(int)index.
z);
517 "IntegerVector3D::[]: [%d][%d][%d] is within [%d,%d,%d].\n",
518 (int)index.
x,(
int)index.
y,(int)index.
z,
527 "IntegerVector3D::[]: value is %d.\n",
534 "IntegerVector3D::[]: [%d][%d][%d] is not within [%d,%d,%d].\n",
535 (int)index.
x,(
int)index.
y,(int)index.
z,
592 const std::vector<std::vector<std::vector<type> > > & value)
600 for (
size_t i = 0; i < value.size () && i <
vector_.size (); ++i)
602 for (
size_t j = 0; j < value[i].size () && j <
vector_[i].size (); ++j)
605 k < value[i][j].size () && k <
vector_[i][j].size (); ++k)
642 const std::vector<std::vector<std::vector<type> > > & value,
651 for (
size_t i = 0; i < value.size () && i <
vector_.size (); ++i)
653 for (
size_t j = 0; j < value[i].size () && j <
vector_[i].size (); ++j)
656 k < value[i][j].size () && k <
vector_[i][j].size (); ++k)
681 quality,
true, settings);
691 "IntegerVector3D::is_true: Checking for truth\n");
700 "IntegerVector3D::is_true: context was not null. Result changed to %d\n",
703 for (
size_t i = 0; i <
vector_.size (); ++i)
705 for (
size_t j = 0; j <
vector_[i].size (); ++i)
707 for (
size_t k = 0; k <
vector_[i][j].size (); ++k)
710 "IntegerVector3D::is_true: checking [%d,%d,%d], is_false of %d. \n",
711 (int)i, (
int)j, (int)k,
717 "IntegerVector3D::is_true: result is false, breaking\n");
731 "IntegerVector3D::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.
bool exists(const Indices &index) const
Checks to see if the index has ever been assigned a value.
KnowledgeRecord::Integer type
convenience typedef for element type
void modify(void)
Mark the vector as modified.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
bool is_false(void) const
Determines if the value of the vector is false.
VariableReference get_size_ref(void)
Returns a reference to the size of vector.
virtual ~IntegerVector3D()
Destructor.
std::vector< std::vector< std::vector< VariableReference > > > vector_
Values of the array.
three dimensional indexing
std::string name_
Prefix of variable.
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 set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
This class stores variables and their values for use by any entity needing state information in a thr...
void operator=(const IntegerVector3D &rhs)
Assignment operator.
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.
ThreadSafeContext * context_
Variable context that we are modifying.
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
IntegerVector3D(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
void resize(const Dimensions &dimensions, bool delete_vars=true)
Resizes the vector.
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.
A thread-safe guard for a context or knowledge base.
std::string delimiter_
Delimiter for the prefix to subvars.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
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 void modify_(void)
Polymorphic modify method used by collection containers.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, const Dimensions &dimensions={0, 0, 0})
Sets the variable name that this refers to.
This class provides a distributed knowledge base to users.
Manages a 3D array of doubles as a virtual overlay in the KnowledgeBase.
bool is_true(void) const
Determines if all values in the vector are true.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
virtual BaseContainer * clone(void) const
Clones this container.
Integer to_integer(void) const
converts the value to an integer
VariableReference size_
Reference to the size of 2D array.
type operator[](const Indices &index) const
Retrieves an index from the multi-dimensional array.
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.
std::vector< Integer > to_integers(void) const
converts the value to a vector of integers
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.
void copy_to(std::vector< std::vector< std::vector< type > > > &target) const
Copies the vector elements to an STL vector.
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.
Dimensions size(void) const
Returns the size of the local 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.
int set(const Indices &index, type value)
Sets a knowledge variable to a specified value.
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...
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.