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)
56 for (
size_t i = 0; i < dimensions.
x; ++i)
58 for (
size_t j = 0; j < dimensions.
y; ++j)
60 context_->mark_modified(vector_[i][j]);
71 std::stringstream result;
73 result <<
"DoubleVector2D: ";
81 result << this->name_;
82 result <<
" [" << dimensions.
x <<
"," << dimensions.
y <<
"]";
85 if (dimensions.
x > 0 && dimensions.
y > 0)
87 for (
size_t i = 0; i < dimensions.
x; ++i)
89 result <<
context_->get(vector_[i][0]).to_string();
91 for (
size_t j = 1; j < dimensions.
y; ++j)
93 result <<
", " <<
context_->get(vector_[i][j]).to_string();
112 return get_debug_info();
126 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size())
127 context_->mark_modified(vector_[index.
x][index.
y]);
136 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
139 this->name_ = rhs.
name_;
141 this->size_ = rhs.
size_;
155 std::stringstream buffer;
160 buffer << delimiter_;
163 ref =
context_->get_ref(buffer.str(), keep_local);
170 const Dimensions& dimensions,
bool delete_vars)
177 "DoubleVector2D::resize: resizing to [%d,%d]\n", (
int)dimensions.
x,
180 bool is_reset = dimensions.
x == 0 && dimensions.
y == 0;
182 if (!size_.is_valid())
184 size_ = get_size_ref();
192 "DoubleVector2D::resize: old size is [%d,%d]\n", (
int)old_size.
x,
198 "DoubleVector2D::resize: new size is being reset to size in KB\n");
200 new_size.
x = old_size.
x;
201 new_size.
y = old_size.
y;
206 "DoubleVector2D::resize: using dimensions passed in.\n");
209 std::vector<KnowledgeRecord::Integer> update(2);
210 update[0] = dimensions.
x;
211 update[1] = dimensions.
y;
213 context_->set(size_, update, settings_);
217 vector_.resize(new_size.
x);
219 for (
size_t i = 0; i < new_size.
x; ++i)
222 "DoubleVector2D::resize: resizing vector_[%d] to %d.\n", (
int)i,
225 vector_[i].resize(new_size.
y);
229 size_t start = old_size.
y;
232 if (is_reset || (old_size.
x < new_size.
x && i >= old_size.
x))
238 "DoubleVector2D::resize: creating var_refs from %d->%d.\n",
239 (
int)start, (
int)new_size.
y);
242 for (
size_t j = start; j < new_size.
y; ++j)
244 std::stringstream var_name;
245 var_name << this->name_;
246 var_name << delimiter_;
248 var_name << delimiter_;
251 vector_[i][j] =
context_->get_ref(var_name.str(), settings_);
256 if ((new_size.
x < old_size.
x || new_size.
y < old_size.
y) && delete_vars)
259 "DoubleVector2D::resize: deleting refs: rows: 0->%d.\n",
263 for (
size_t i = 0; i < old_size.
x; ++i)
266 size_t start = new_size.
y;
269 if (old_size.
x > new_size.
x && i >= new_size.
x)
275 "DoubleVector2D::resize: deleting refs: %d:%d->%d.\n", (
int)i,
276 (
int)start, (
int)old_size.
x);
279 for (
size_t j = start; j < old_size.
y; ++j)
281 std::stringstream var_name;
282 var_name << this->name_;
283 var_name << delimiter_;
285 var_name << delimiter_;
289 "DoubleVector2D::resize: deleting ref: %s.\n",
290 var_name.str().c_str());
292 context_->delete_variable(var_name.str(), settings_);
314 std::vector<KnowledgeRecord::Integer> sizes(record.
to_integers());
315 cur_size.
x = (size_t)(sizes.size() >= 2 ? sizes[0] : 0);
316 cur_size.
y = (size_t)(sizes.size() >= 2 ? sizes[1] : 0);
336 size_ = get_size_ref();
379 delimiter_ = delimiter;
395 std::vector<std::vector<type> >& target)
const
405 target.resize(dimensions.
x);
407 for (
size_t i = 0; i < dimensions.
x; ++i)
409 target[i].resize(dimensions.
y);
410 for (
size_t j = 0; j < dimensions.
y; ++j)
412 target[i][j] =
context_->get(vector_[i][j], keep_local).to_double();
430 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size())
432 result =
context_->get(vector_[index.
x][index.
y], keep_local).to_double();
448 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size())
450 result =
context_->exists(vector_[index.
x][index.
y]);
466 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size())
468 result =
context_->set(vector_[index.
x][index.
y], value, settings_);
476 const std::vector<std::vector<type> >& value)
484 for (
size_t i = 0; i < value.size() && i < vector_.size(); ++i)
486 for (
size_t j = 0; j < value[i].size() && j < vector_[i].size(); ++j)
488 context_->set(vector_[i][j], value[i][j], settings_);
505 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size())
507 result =
context_->set(vector_[index.
x][index.
y], value, settings);
515 const std::vector<std::vector<type> >& value,
524 for (
size_t i = 0; i < value.size() && i < vector_.size(); ++i)
526 for (
size_t j = 0; j < value[i].size() && j < vector_[i].size(); ++j)
528 context_->set(vector_[i][j], value[i][j], settings);
537 const Indices& index, uint32_t quality,
544 if (index.
x < vector_.size() && index.
y < vector_[index.
x].size())
546 vector_[index.
x][index.
y].get_name(), quality,
true, settings);
555 "DoubleVector2D::is_true: Checking for truth\n");
564 "DoubleVector2D::is_true: context was not null. Result changed to %d\n",
567 for (
size_t i = 0; i < vector_.size(); ++i)
569 for (
size_t j = 0; j < vector_[i].size(); ++i)
572 "DoubleVector2D::is_true: checking [%d,%d], is_false of %d. \n",
573 (
int)i, (
int)j, (
int)
context_->get(vector_[i][j]).is_false());
575 if (
context_->get(vector_[i][j]).is_false())
578 "DoubleVector2D::is_true: result is false, breaking\n");
586 if (vector_.size() == 0)
591 "DoubleVector2D::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 2D array of doubles as a virtual overlay in the KnowledgeBase.
VariableReference get_size_ref(void)
Returns a reference to the size of vector.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true.
ThreadSafeContext * context_
Variable context that we are modifying.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, const Dimensions &dimensions={0, 0})
Sets the variable name that this refers to.
void modify(void)
Mark the vector as modified.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
int set(const Indices &index, double value)
Sets a knowledge variable to a specified value.
std::vector< std::vector< VariableReference > > vector_
Values of the array.
bool is_true(void) const
Determines if all values in the vector are true.
void operator=(const DoubleVector2D &rhs)
Assignment operator.
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.
type operator[](const Indices &index) const
Retrieves an index from the multi-dimensional array.
void resize(const Dimensions &dimensions, bool delete_vars=true)
Resizes the vector.
VariableReference size_
Reference to the size of 2D array.
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
DoubleVector2D(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
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 ...
bool is_false(void) const
Determines if the value of the vector is false.
Dimensions size(void) const
Returns the size of the local vector.
std::string delimiter_
Delimiter for the prefix to subvars.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
bool exists(const Indices &index) const
Checks to see if the index has ever been assigned a value.
double type
convenience typedef for element type
void copy_to(std::vector< std::vector< type > > &target) const
Copies the vector elements to an STL vector.
virtual ~DoubleVector2D()
Destructor.
virtual BaseContainer * clone(void) const
Clones this container.
Provides functions and classes for the distributed knowledge base.