12 const Dimensions& dimensions,
bool delete_vars,
19 resize(dimensions, delete_vars);
31 resize(dimensions, delete_vars);
40 delimiter_(rhs.delimiter_)
54 if (dimensions.
x > 0 && dimensions.
y > 0 && dimensions.
z > 0)
56 for (
size_t i = 0; i < dimensions.
x; ++i)
58 for (
size_t j = 0; j < dimensions.
y; ++j)
60 for (
size_t k = 0; k < dimensions.
z; ++k)
62 context_->mark_modified(vector_[i][j][k]);
74 std::stringstream result;
76 result <<
"DoubleVector3D: ";
84 result << this->name_;
85 result <<
" [" << dimensions.
x <<
"," << dimensions.
y <<
"," << dimensions.
z
89 if (dimensions.
x > 0 && dimensions.
y > 0)
91 for (
size_t i = 0; i < dimensions.
x; ++i)
93 for (
size_t j = 0; j < dimensions.
y; ++j)
95 result <<
context_->get(vector_[i][j][0]).to_string();
97 for (
size_t k = 1; k < dimensions.
z; ++k)
99 result <<
", " <<
context_->get(vector_[i][j][k]).to_string();
119 return get_debug_info();
133 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size() &&
134 index.
z < vector_[index.
x][index.
y].size())
135 context_->mark_modified(vector_[index.
x][index.
y][index.
z]);
144 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
147 this->name_ = rhs.
name_;
149 this->size_ = rhs.
size_;
163 std::stringstream buffer;
168 buffer << delimiter_;
171 ref =
context_->get_ref(buffer.str(), keep_local);
178 const Dimensions& dimensions,
bool delete_vars)
185 "DoubleVector3D::resize: resizing to [%d,%d]\n", (
int)dimensions.
x,
188 bool is_reset = dimensions.
x == 0 && dimensions.
y == 0;
190 if (!size_.is_valid())
192 size_ = get_size_ref();
200 "DoubleVector3D::resize: old size is [%d,%d]\n", (
int)old_size.
x,
206 "DoubleVector3D::resize: new size is being reset to size in KB\n");
208 new_size.
x = old_size.
x;
209 new_size.
y = old_size.
y;
210 new_size.
z = old_size.
z;
215 "DoubleVector3D::resize: using dimensions passed in.\n");
218 std::vector<KnowledgeRecord::Integer> update(3);
219 update[0] = dimensions.
x;
220 update[1] = dimensions.
y;
221 update[2] = dimensions.
z;
223 context_->set(size_, update, settings_);
227 vector_.resize(new_size.
x);
229 for (
size_t i = 0; i < new_size.
x; ++i)
232 "DoubleVector3D::resize: resizing vector_[%d] to %d.\n", (
int)i,
235 vector_[i].resize(new_size.
y);
239 size_t start = old_size.
y;
242 if (is_reset || (old_size.
x < new_size.
x && i >= old_size.
x))
248 "DoubleVector3D::resize: creating var_refs from %d->%d.\n",
249 (
int)start, (
int)new_size.
y);
252 for (
size_t j = start; j < new_size.
y; ++j)
254 vector_[i][j].resize(new_size.
z);
258 size_t start_z = old_size.
z;
261 if (is_reset || ((old_size.
y < new_size.
y && j >= old_size.
y) ||
262 (old_size.
x < new_size.
x && i >= old_size.
x)))
268 for (
size_t k = start_z; k < new_size.
z; ++k)
270 std::stringstream var_name;
271 var_name << this->name_;
272 var_name << delimiter_;
274 var_name << delimiter_;
276 var_name << delimiter_;
279 vector_[i][j][k] =
context_->get_ref(var_name.str(), settings_);
285 if ((new_size.
x < old_size.
x || new_size.
y < old_size.
y ||
286 new_size.
z < old_size.
z) &&
290 "DoubleVector3D::resize: deleting refs: rows: 0->%d.\n",
294 for (
size_t i = 0; i < old_size.
x; ++i)
297 size_t start = new_size.
y;
300 if (old_size.
x > new_size.
x && i >= new_size.
x)
306 "DoubleVector3D::resize: deleting refs: %d:%d->%d.\n", (
int)i,
307 (
int)start, (
int)old_size.
x);
310 for (
size_t j = start; j < old_size.
y; ++j)
313 size_t start_k = new_size.
z;
316 if (old_size.
y > new_size.
y && j >= new_size.
y)
322 for (
size_t k = start_k; k < old_size.
z; ++k)
324 std::stringstream var_name;
325 var_name << this->name_;
326 var_name << delimiter_;
328 var_name << delimiter_;
330 var_name << delimiter_;
334 "DoubleVector3D::resize: deleting ref: %s.\n",
335 var_name.str().c_str());
337 context_->delete_variable(var_name.str(), settings_);
360 std::vector<KnowledgeRecord::Integer> sizes(record.
to_integers());
361 cur_size.
x = (size_t)(sizes.size() >= 3 ? sizes[0] : 0);
362 cur_size.
y = (size_t)(sizes.size() >= 3 ? sizes[1] : 0);
363 cur_size.
z = (size_t)(sizes.size() >= 3 ? sizes[2] : 0);
383 size_ = get_size_ref();
426 delimiter_ = delimiter;
442 std::vector<std::vector<std::vector<type> > >& target)
const
452 target.resize(dimensions.
x);
454 for (
size_t i = 0; i < dimensions.
x; ++i)
456 target[i].resize(dimensions.
y);
457 for (
size_t j = 0; j < dimensions.
y; ++j)
459 target[i][j].resize(dimensions.
z);
460 for (
size_t k = 0; k < dimensions.
z; ++k)
463 context_->get(vector_[i][j][k], keep_local).to_double();
479 "DoubleVector3D::[]: retrieving [%d,%d,%d].\n", (
int)index.
x,
480 (
int)index.
y, (
int)index.
z);
486 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size() &&
487 index.
z < vector_[index.
x][index.
y].size())
490 "DoubleVector3D::[]: [%d][%d][%d] is within [%d,%d,%d].\n",
491 (
int)index.
x, (
int)index.
y, (
int)index.
z, (
int)vector_.size(),
492 (
int)vector_[index.
x].size(), (
int)vector_[index.
x][index.
y].size());
494 result =
context_->get(vector_[index.
x][index.
y][index.
z], keep_local)
498 "DoubleVector3D::[]: value is %.3f.\n", result);
503 "DoubleVector3D::[]: [%d][%d][%d] is not within [%d,%d,%d].\n",
504 (
int)index.
x, (
int)index.
y, (
int)index.
z, (
int)vector_.size(),
505 (
int)vector_[index.
x].size(), (
int)vector_[index.
x][index.
y].size());
521 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size() &&
522 index.
z < vector_[index.
x][index.
y].size())
524 result =
context_->exists(vector_[index.
x][index.
y][index.
z]);
540 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size() &&
541 index.
z < vector_[index.
x][index.
y].size())
544 context_->set(vector_[index.
x][index.
y][index.
z], value, settings_);
552 const std::vector<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)
564 for (
size_t k = 0; k < value[i][j].size() && k < vector_[i][j].size();
567 context_->set(vector_[i][j][k], value[i][j][k], settings_);
585 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size() &&
586 index.
z < vector_[index.
x][index.
y].size())
589 context_->set(vector_[index.
x][index.
y][index.
z], value, settings);
597 const std::vector<std::vector<std::vector<type> > >& value,
606 for (
size_t i = 0; i < value.size() && i < vector_.size(); ++i)
608 for (
size_t j = 0; j < value[i].size() && j < vector_[i].size(); ++j)
610 for (
size_t k = 0; k < value[i][j].size() && k < vector_[i][j].size();
613 context_->set(vector_[i][j][k], value[i][j][k], settings);
623 const Indices& index, uint32_t quality,
630 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size() &&
631 index.
z < vector_[index.
x][index.
y].size())
632 context_->set_quality(vector_[index.
x][index.
y][index.
z].get_name(),
633 quality,
true, settings);
642 "DoubleVector3D::is_true: Checking for truth\n");
651 "DoubleVector3D::is_true: context was not null. Result changed to %d\n",
654 for (
size_t i = 0; i < vector_.size(); ++i)
656 for (
size_t j = 0; j < vector_[i].size(); ++i)
658 for (
size_t k = 0; k < vector_[i][j].size(); ++k)
661 "DoubleVector3D::is_true: checking [%d,%d,%d], is_false of %d. "
663 (
int)i, (
int)j, (
int)k,
664 (
int)
context_->get(vector_[i][j][k]).is_false());
666 if (
context_->get(vector_[i][j][k]).is_false())
669 "DoubleVector3D::is_true: result is false, breaking\n");
678 if (vector_.size() == 0)
683 "DoubleVector3D::is_true: final result is %d\n", (
int)result);
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
const ThreadSafeContext * context_
A thread-safe guard for a context or knowledge base.
This class provides a distributed knowledge base to users.
This class encapsulates an entry in a KnowledgeBase.
std::vector< Integer > to_integers(void) const
converts the value to a vector of integers
Settings for applying knowledge updates.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
Optimized reference to a variable within the knowledge base.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
KnowledgeUpdateSettings settings_
Settings for modifications.
std::string name_
Prefix of variable.
MADARA_LOCK_TYPE mutex_
guard for access and changes
Manages a 3D array of doubles as a virtual overlay in the KnowledgeBase.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
DoubleVector3D(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
VariableReference get_size_ref(void)
Returns a reference to the size of vector.
std::string delimiter_
Delimiter for the prefix to subvars.
void modify(void)
Mark the vector as modified.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true.
double type
convenience typedef for element type
bool exists(const Indices &index) const
Checks to see if the index has ever been assigned a value.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
void resize(const Dimensions &dimensions, bool delete_vars=true)
Resizes the vector.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
void operator=(const DoubleVector3D &rhs)
Assignment operator.
std::vector< std::vector< std::vector< VariableReference > > > vector_
Values of the array.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, const Dimensions &dimensions={0, 0, 0})
Sets the variable name that this refers to.
type operator[](const Indices &index) const
Retrieves an index from the multi-dimensional array.
virtual ~DoubleVector3D()
Destructor.
Dimensions size(void) const
Returns the size of the local vector.
VariableReference size_
Reference to the size of 2D array.
bool is_true(void) const
Determines if all values in the vector are true.
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.
bool is_false(void) const
Determines if the value of the vector is false.
virtual BaseContainer * clone(void) const
Clones this container.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
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.
int set(const Indices &index, type value)
Sets a knowledge variable to a specified value.
void copy_to(std::vector< std::vector< std::vector< type > > > &target) const
Copies the vector elements to an STL vector.
Provides functions and classes for the distributed knowledge base.