MADARA  3.4.1
Vector.cpp
Go to the documentation of this file.
1 #include "Vector.h"
3 
5  const KnowledgeUpdateSettings& settings, const std::string& delimiter)
6  : BaseContainer("", settings), context_(0), delimiter_(delimiter)
7 {
8 }
9 
11  KnowledgeBase& knowledge, int size, bool delete_vars,
12  const KnowledgeUpdateSettings& settings, const std::string& delimiter)
13  : BaseContainer(name, settings),
14  context_(&(knowledge.get_context())),
15  delimiter_(delimiter)
16 {
17  size_ = get_size_ref();
18  resize(size, delete_vars);
19 }
20 
22  Variables& knowledge, int size, bool delete_vars,
23  const KnowledgeUpdateSettings& settings, const std::string& delimiter)
24  : BaseContainer(name, settings),
25  context_(knowledge.get_context()),
26  delimiter_(delimiter)
27 {
28  size_ = get_size_ref();
29  resize(size, delete_vars);
30 }
31 
33  : BaseContainer(rhs),
34  context_(rhs.context_),
35  vector_(rhs.vector_),
36  size_(rhs.size_),
37  delimiter_(rhs.delimiter_)
38 {
39 }
40 
42 
44 {
45  if (context_ && name_ != "")
46  {
47  ContextGuard context_guard(*context_);
48  MADARA_GUARD_TYPE guard(mutex_);
49 
50  for (size_t index = 0; index < vector_.size(); ++index)
51  context_->mark_modified(vector_[index]);
52 
53  context_->mark_modified(size_);
54  }
55 }
56 
58 {
59  std::stringstream result;
60 
61  result << "Vector: ";
62 
63  if (context_)
64  {
65  ContextGuard context_guard(*context_);
66  MADARA_GUARD_TYPE guard(mutex_);
67  size_t elements = vector_.size();
68 
69  result << this->name_;
70  result << " [" << elements << "]";
71  result << " = [";
72 
73  if (elements > 0)
74  {
75  result << context_->get(vector_[0]).to_string();
76 
77  for (size_t index = 1; index < elements; ++index)
78  {
79  result << ", " << context_->get(vector_[index]).to_string();
80  }
81  }
82 
83  result << "]";
84  }
85 
86  return result.str();
87 }
88 
90 {
91  modify();
92 }
93 
95 {
96  return get_debug_info();
97 }
98 
101 {
102  return new Vector(*this);
103 }
104 
106 {
107  if (context_ && name_ != "" && index < vector_.size())
108  {
109  ContextGuard context_guard(*context_);
110  MADARA_GUARD_TYPE guard(mutex_);
111 
112  context_->mark_modified(vector_[index]);
113  }
114 }
115 
117 {
118  if (this != &rhs)
119  {
120  MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.mutex_);
121 
122  this->context_ = rhs.context_;
123  this->name_ = rhs.name_;
124  this->settings_ = rhs.settings_;
125  this->size_ = rhs.size_;
126  this->vector_ = rhs.vector_;
127  }
128 }
129 
132 {
133  VariableReference ref;
134 
135  if (context_ && name_ != "")
136  {
137  KnowledgeUpdateSettings keep_local(true);
138  std::stringstream buffer;
139 
140  ContextGuard context_guard(*context_);
141  MADARA_GUARD_TYPE guard(mutex_);
142 
143  buffer << name_;
144  buffer << delimiter_;
145  buffer << "size";
146 
147  ref = context_->get_ref(buffer.str(), keep_local);
148  }
149 
150  return ref;
151 }
152 
155 {
156  if (context_ && name_ != "")
157  {
158  ContextGuard context_guard(*context_);
159  MADARA_GUARD_TYPE guard(mutex_);
160 
161  if (!size_.is_valid())
162  {
163  size_ = get_size_ref();
164  }
165 
166  size_t i = size();
167 
168  resize((int)i + 1);
169 
171  {
172  set(i, value.to_double());
173  }
174  else if (value.type() == knowledge::KnowledgeRecord::STRING)
175  {
176  set(i, value.to_string());
177  }
179  {
180  set(i, value.to_integers());
181  }
183  {
184  set(i, value.to_doubles());
185  }
186  else if (value.is_binary_file_type())
187  {
188  size_t size;
189  unsigned char* unmanaged = value.to_unmanaged_buffer(size);
190  set_file(i, unmanaged, size);
191  delete[] unmanaged;
192  }
193  else
194  {
195  set(i, value.to_integer());
196  }
197  }
198 }
199 
200 void madara::knowledge::containers::Vector::resize(int size, bool delete_vars)
201 {
202  if (context_ && name_ != "")
203  {
204  ContextGuard context_guard(*context_);
205  MADARA_GUARD_TYPE guard(mutex_);
206 
207  if (!size_.is_valid())
208  {
209  size_ = get_size_ref();
210  }
211 
212  if (size >= 0)
213  {
214  size_t old_size = vector_.size();
215 
216  if (old_size != (size_t)size)
217  {
218  vector_.resize(size);
219 
220  context_->set(
221  size_, knowledge::KnowledgeRecord::Integer(size), settings_);
222 
223  if ((size_t)size > old_size)
224  {
225  for (; old_size < (size_t)size; ++old_size)
226  {
227  std::stringstream buffer;
228  buffer << name_;
229  buffer << delimiter_;
230  buffer << old_size;
231  vector_[old_size] = context_->get_ref(buffer.str(), settings_);
232  }
233  }
234  else if (delete_vars)
235  {
236  for (; (size_t)size < old_size; ++size)
237  {
238  std::stringstream buffer;
239  buffer << name_;
240  buffer << delimiter_;
241  buffer << size;
242 
243  context_->delete_variable(buffer.str(), settings_);
244  }
245  }
246  }
247  }
248  else
249  {
250  // dynamically allocate size from the context
251  size_t cur_size = context_->get(size_, settings_).to_integer();
252 
253  size_t old_size = vector_.size();
254 
255  if (old_size != cur_size)
256  {
257  vector_.resize(cur_size);
258 
259  if (cur_size > old_size)
260  {
261  for (; old_size < cur_size; ++old_size)
262  {
263  std::stringstream buffer;
264  buffer << name_;
265  buffer << delimiter_;
266  buffer << old_size;
267  vector_[old_size] = context_->get_ref(buffer.str(), settings_);
268  }
269  }
270  else if (delete_vars)
271  {
272  for (; cur_size < old_size; ++cur_size)
273  {
274  std::stringstream buffer;
275  buffer << name_;
276  buffer << delimiter_;
277  buffer << cur_size;
278 
279  context_->delete_variable(buffer.str(), settings_);
280  }
281  }
282  }
283  }
284  }
285 }
286 
288  Vector& other, bool refresh_keys, bool delete_keys)
289 {
290  if (context_ && other.context_)
291  {
292  std::lock(*context_, *other.context_, mutex_, other.mutex_);
293 
294  ContextGuard context_guard(*context_, std::adopt_lock);
295  ContextGuard other_context_guard(*other.context_, std::adopt_lock);
296  MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
297  guard2(other.mutex_, std::adopt_lock);
298 
299  if (refresh_keys)
300  {
301  other.resize();
302  this->resize();
303  }
304 
305  size_t other_size = other.vector_.size();
306  size_t this_size = this->vector_.size();
307 
308  for (size_t i = 0; i < this_size; ++i)
309  {
310  // temp = this[i];
312  context_->get(this->vector_[i], settings_);
313 
314  if (i < other_size)
315  {
316  auto val = other.context_->get(other.vector_[i], other.settings_);
317  // this[i] = other[i];
318  context_->set(this->vector_[i], std::move(val), settings_);
319 
320  // other[i] = temp;
321  other.context_->set(other.vector_[i], std::move(temp), other.settings_);
322  }
323  else
324  {
325  if (delete_keys)
326  {
327  std::stringstream buffer;
328  buffer << this->name_;
329 
330  buffer << delimiter_;
331  buffer << i;
332  this->context_->delete_variable(buffer.str(), other.settings_);
333  }
334  else
335  {
337  this->context_->set(this->vector_[i], empty, this->settings_);
338  }
339 
340  {
341  std::stringstream buffer;
342  buffer << other.name_;
343  buffer << delimiter_;
344  buffer << i;
345 
346  // other[i] = temp;
347  other.context_->set(buffer.str(), std::move(temp), other.settings_);
348  }
349  }
350  }
351 
352  // copy the other vector's elements to this vector's location
353  for (size_t i = this_size; i < other_size; ++i)
354  {
355  std::stringstream buffer;
356  buffer << this->name_;
357  buffer << delimiter_;
358  buffer << i;
359  context_->set(buffer.str(),
360  other.context_->get(other.vector_[i], other.settings_),
361  this->settings_);
362  }
363 
364  // set the size appropriately
365  this->context_->set(this->size_, other_size, this->settings_);
366  other.context_->set(other.size_, this_size, other.settings_);
367 
368  if (refresh_keys)
369  {
370  this->resize(-1, true);
371  other.resize(-1, true);
372  }
373  }
374 }
375 
377 {
378  if (context_ && other.context_)
379  {
380  std::lock(*context_, *other.context_, mutex_, other.mutex_);
381 
382  ContextGuard context_guard(*context_, std::adopt_lock);
383  ContextGuard other_context_guard(*other.context_, std::adopt_lock);
384  MADARA_GUARD_TYPE guard(mutex_, std::adopt_lock),
385  guard2(other.mutex_, std::adopt_lock);
386 
387  size_t other_size = other.vector_.size();
388  size_t this_size = this->vector_.size();
389 
390  size_t size = other_size + this_size;
391  other.resize((int)size);
392 
393  for (size_t i = 0, j = other_size; i < this_size; ++i, ++j)
394  {
395  other.context_->set(other.vector_[j], (*this)[i], other.settings_);
396  }
397 
398  this->resize(0, true);
399  }
400 }
401 
403  KnowledgeVector& target) const
404 {
405  if (context_)
406  {
407  ContextGuard context_guard(*context_);
408  MADARA_GUARD_TYPE guard(mutex_);
409 
410  target.resize(vector_.size());
411 
412  for (size_t i = 0; i < vector_.size(); ++i)
413  {
414  target[i].deep_copy((*this)[i]);
415  }
416  }
417 }
418 
420 operator[](size_t index) const
421 {
423  KnowledgeUpdateSettings keep_local(true);
424 
425  if (index < vector_.size() && context_)
426  {
427  ContextGuard context_guard(*context_);
428  MADARA_GUARD_TYPE guard(mutex_);
429  result = context_->get(vector_[index], keep_local);
430  }
431 
432  return result;
433 }
434 
437 {
439 
440  if (index < vector_.size() && context_)
441  {
442  ContextGuard context_guard(*context_);
443  MADARA_GUARD_TYPE guard(mutex_);
444  result = context_->get(vector_[index], settings_);
445  }
446 
447  return result;
448 }
449 
451 {
452  bool result(false);
453 
454  if (index < vector_.size() && context_)
455  {
456  ContextGuard context_guard(*context_);
457  MADARA_GUARD_TYPE guard(mutex_);
458  result = context_->exists(vector_[index]);
459  }
460 
461  return result;
462 }
463 
465  size_t index, const std::string& filename)
466 {
467  int result = -1;
468 
469  if (index < vector_.size() && context_)
470  {
471  ContextGuard context_guard(*context_);
472  MADARA_GUARD_TYPE guard(mutex_);
473  result = context_->read_file(vector_[index], filename, settings_);
474  }
475 
476  return result;
477 }
478 
480  const std::string& filename, const KnowledgeUpdateSettings& settings)
481 {
482  int result = -1;
483 
484  if (index < vector_.size() && context_)
485  {
486  ContextGuard context_guard(*context_);
487  MADARA_GUARD_TYPE guard(mutex_);
488  result = context_->read_file(vector_[index], filename, settings);
489  }
490 
491  return result;
492 }
493 
495  size_t index, const unsigned char* value, size_t size)
496 {
497  int result = -1;
498 
499  if (index < vector_.size() && context_)
500  {
501  ContextGuard context_guard(*context_);
502  MADARA_GUARD_TYPE guard(mutex_);
503  result = context_->set_file(vector_[index], value, size, settings_);
504  }
505 
506  return result;
507 }
508 
510  const unsigned char* value, size_t size,
511  const KnowledgeUpdateSettings& settings)
512 {
513  int result = -1;
514 
515  if (index < vector_.size() && context_)
516  {
517  ContextGuard context_guard(*context_);
518  MADARA_GUARD_TYPE guard(mutex_);
519  result = context_->set_file(vector_[index], value, size, settings);
520  }
521 
522  return result;
523 }
524 
526  size_t index, const unsigned char* value, size_t size)
527 {
528  int result = -1;
529 
530  if (index < vector_.size() && context_)
531  {
532  ContextGuard context_guard(*context_);
533  MADARA_GUARD_TYPE guard(mutex_);
534  result = context_->set_jpeg(vector_[index], value, size, settings_);
535  }
536 
537  return result;
538 }
539 
541  const unsigned char* value, size_t size,
542  const KnowledgeUpdateSettings& settings)
543 {
544  int result = -1;
545 
546  if (index < vector_.size() && context_)
547  {
548  ContextGuard context_guard(*context_);
549  MADARA_GUARD_TYPE guard(mutex_);
550  result = context_->set_jpeg(vector_[index], value, size, settings);
551  }
552  return result;
553 }
554 
556  size_t index, knowledge::KnowledgeRecord::Integer value)
557 {
558  int result = -1;
559 
560  if (index < vector_.size() && context_)
561  {
562  ContextGuard context_guard(*context_);
563  MADARA_GUARD_TYPE guard(mutex_);
564  result = context_->set(vector_[index], value, settings_);
565  }
566 
567  return result;
568 }
569 
572  const KnowledgeUpdateSettings& settings)
573 {
574  int result = -1;
575 
576  if (index < vector_.size() && context_)
577  {
578  ContextGuard context_guard(*context_);
579  MADARA_GUARD_TYPE guard(mutex_);
580  result = context_->set(vector_[index], value, settings);
581  }
582 
583  return result;
584 }
585 
587  size_t index, size_t sub_index, knowledge::KnowledgeRecord::Integer value)
588 {
589  int result = -1;
590 
591  if (index < vector_.size() && context_)
592  {
593  ContextGuard context_guard(*context_);
594  MADARA_GUARD_TYPE guard(mutex_);
595  result = context_->set_index(vector_[index], sub_index, value, settings_);
596  }
597 
598  return result;
599 }
600 
602  size_t sub_index, knowledge::KnowledgeRecord::Integer value,
603  const KnowledgeUpdateSettings& settings)
604 {
605  int result = -1;
606 
607  if (index < vector_.size() && context_)
608  {
609  ContextGuard context_guard(*context_);
610  MADARA_GUARD_TYPE guard(mutex_);
611  result = context_->set_index(vector_[index], sub_index, value, settings);
612  }
613 
614  return result;
615 }
616 
618  const madara::knowledge::KnowledgeRecord::Integer* value, uint32_t size)
619 {
620  int result = -1;
621 
622  if (index < vector_.size() && context_)
623  {
624  ContextGuard context_guard(*context_);
625  MADARA_GUARD_TYPE guard(mutex_);
626  result = context_->set(vector_[index], value, size, settings_);
627  }
628 
629  return result;
630 }
631 
633  const madara::knowledge::KnowledgeRecord::Integer* value, uint32_t size,
634  const KnowledgeUpdateSettings& settings)
635 {
636  int result = -1;
637 
638  if (index < vector_.size() && context_)
639  {
640  ContextGuard context_guard(*context_);
641  MADARA_GUARD_TYPE guard(mutex_);
642  result = context_->set(vector_[index], value, size, settings);
643  }
644 
645  return result;
646 }
647 
649  size_t index, const std::vector<KnowledgeRecord::Integer>& value)
650 {
651  int result = -1;
652 
653  if (index < vector_.size() && context_)
654  {
655  ContextGuard context_guard(*context_);
656  MADARA_GUARD_TYPE guard(mutex_);
657  result = context_->set(vector_[index], value, settings_);
658  }
659 
660  return result;
661 }
662 
664  const std::vector<KnowledgeRecord::Integer>& value,
665  const KnowledgeUpdateSettings& settings)
666 {
667  int result = -1;
668 
669  if (index < vector_.size() && context_)
670  {
671  ContextGuard context_guard(*context_);
672  MADARA_GUARD_TYPE guard(mutex_);
673  result = context_->set(vector_[index], value, settings);
674  }
675 
676  return result;
677 }
678 
679 int madara::knowledge::containers::Vector::set(size_t index, double value)
680 {
681  int result = -1;
682 
683  if (index < vector_.size() && context_)
684  {
685  ContextGuard context_guard(*context_);
686  MADARA_GUARD_TYPE guard(mutex_);
687  result = context_->set(vector_[index], value, settings_);
688  }
689 
690  return result;
691 }
692 
694  size_t index, double value, const KnowledgeUpdateSettings& settings)
695 {
696  int result = -1;
697 
698  if (index < vector_.size() && context_)
699  {
700  ContextGuard context_guard(*context_);
701  MADARA_GUARD_TYPE guard(mutex_);
702  result = context_->set(vector_[index], value, settings);
703  }
704 
705  return result;
706 }
707 
709  size_t index, size_t sub_index, double value)
710 {
711  int result = -1;
712 
713  if (index < vector_.size() && context_)
714  {
715  ContextGuard context_guard(*context_);
716  MADARA_GUARD_TYPE guard(mutex_);
717  result = context_->set_index(vector_[index], sub_index, value, settings_);
718  }
719 
720  return result;
721 }
722 
724  size_t sub_index, double value, const KnowledgeUpdateSettings& settings)
725 {
726  int result = -1;
727 
728  if (index < vector_.size() && context_)
729  {
730  ContextGuard context_guard(*context_);
731  MADARA_GUARD_TYPE guard(mutex_);
732  result = context_->set_index(vector_[index], sub_index, value, settings);
733  }
734 
735  return result;
736 }
737 
739  size_t index, const double* value, uint32_t size)
740 {
741  int result = -1;
742 
743  if (index < vector_.size() && context_)
744  {
745  ContextGuard context_guard(*context_);
746  MADARA_GUARD_TYPE guard(mutex_);
747  result = context_->set(vector_[index], value, size, settings_);
748  }
749 
750  return result;
751 }
752 
754  const double* value, uint32_t size, const KnowledgeUpdateSettings& settings)
755 {
756  int result = -1;
757 
758  if (index < vector_.size() && context_)
759  {
760  ContextGuard context_guard(*context_);
761  MADARA_GUARD_TYPE guard(mutex_);
762  result = context_->set(vector_[index], value, size, settings);
763  }
764 
765  return result;
766 }
767 
769  size_t index, const std::vector<double>& value)
770 {
771  int result = -1;
772 
773  if (index < vector_.size() && context_)
774  {
775  ContextGuard context_guard(*context_);
776  MADARA_GUARD_TYPE guard(mutex_);
777  result = context_->set(vector_[index], value, settings_);
778  }
779 
780  return result;
781 }
782 
784  const std::vector<double>& value, const KnowledgeUpdateSettings& settings)
785 {
786  int result = -1;
787 
788  if (index < vector_.size() && context_)
789  {
790  ContextGuard context_guard(*context_);
791  MADARA_GUARD_TYPE guard(mutex_);
792  result = context_->set(vector_[index], value, settings);
793  }
794 
795  return result;
796 }
797 
799  size_t index, const std::string& value)
800 {
801  int result = -1;
802 
803  if (index < vector_.size() && context_)
804  {
805  ContextGuard context_guard(*context_);
806  MADARA_GUARD_TYPE guard(mutex_);
807  result = context_->set(vector_[index], value, settings_);
808  }
809 
810  return result;
811 }
812 
814  const std::string& value, const KnowledgeUpdateSettings& settings)
815 {
816  int result = -1;
817 
818  if (index < vector_.size() && context_)
819  {
820  ContextGuard context_guard(*context_);
821  MADARA_GUARD_TYPE guard(mutex_);
822  result = context_->set(vector_[index], value, settings);
823  }
824 
825  return result;
826 }
827 
829  size_t index, uint32_t quality, const KnowledgeReferenceSettings& settings)
830 {
831  if (index < vector_.size() && context_)
832  {
833  ContextGuard context_guard(*context_);
834  MADARA_GUARD_TYPE guard(mutex_);
835  context_->set_quality(vector_[index].get_name(), quality, true, settings);
836  }
837 }
838 
840 {
841  bool result(false);
842 
844  "Vector::is_true: Checking for truth\n");
845 
846  if (context_)
847  {
848  ContextGuard context_guard(*context_);
849  MADARA_GUARD_TYPE guard(mutex_);
850 
851  result = true;
852 
854  "Vector::is_true: context was not null. Result changed to %d\n",
855  (int)result);
856 
857  for (size_t index = 0; index < vector_.size(); ++index)
858  {
860  "Vector::is_true: checking index %d, is_false of %d. \n", (int)result,
861  (int)context_->get(vector_[index]).is_false());
862 
863  if (context_->get(vector_[index]).is_false())
864  {
866  "Vector::is_true: result is false, breaking\n");
867 
868  result = false;
869  break;
870  }
871  }
872 
873  if (vector_.size() == 0)
874  result = false;
875  }
876 
878  "Vector::is_true: final result is %d\n", (int)result);
879 
880  return result;
881 }
882 
884 {
885  return !is_true();
886 }
887 
889 {
890  return is_true();
891 }
892 
894 {
895  return is_false();
896 }
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
Definition: Logger.h:20
const ThreadSafeContext * context_
A thread-safe guard for a context or knowledge base.
Definition: ContextGuard.h:24
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
This class encapsulates an entry in a KnowledgeBase.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
uint32_t type(void) const
returns the type of the value
std::vector< Integer > to_integers(void) const
converts the value to a vector of integers
double to_double(void) const
converts the value to a float/double.
bool is_binary_file_type(void) const
returns true if the knowledge record has a binary file type
Integer to_integer(void) const
converts the value to an integer.
unsigned char * to_unmanaged_buffer(size_t &size) const
returns an unmanaged buffer that the user will have to take care of (this is a copy of the internal v...
std::vector< double > to_doubles(void) const
converts the value to a vector of doubles
Settings for applying knowledge updates.
Settings for applying knowledge updates.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the current value of a variable.
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
Optimized reference to a variable within the knowledge base.
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
This class is an abstract base class for all containers.
Definition: BaseContainer.h:34
KnowledgeUpdateSettings settings_
Settings for modifications.
std::string name_
Prefix of variable.
MADARA_LOCK_TYPE mutex_
guard for access and changes
This class stores a vector of KaRL variables.
Definition: Vector.h:36
VariableReference size_
Reference to the size field of the vector space.
Definition: Vector.h:621
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
Definition: Vector.cpp:131
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true.
Definition: Vector.cpp:888
std::vector< VariableReference > vector_
Values of the array.
Definition: Vector.h:616
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.
Definition: Vector.cpp:828
int set_index(size_t index, size_t sub_index, madara::knowledge::KnowledgeRecord::Integer value)
Sets an index within an array to a specified value.
Definition: Vector.cpp:586
void modify(void)
Mark the vector as modified.
Definition: Vector.cpp:43
knowledge::KnowledgeRecord operator[](size_t index) const
Retrieves a copy of the record from the map.
Definition: Vector.cpp:420
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
Definition: Vector.cpp:402
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
Definition: Vector.cpp:57
int set_jpeg(size_t index, const unsigned char *value, size_t size)
Atomically sets the value of an index to a JPEG image.
Definition: Vector.cpp:525
bool is_true(void) const
Determines if all values in the vector are true.
Definition: Vector.cpp:839
void exchange(Vector &other, bool refresh_keys=true, bool delete_keys=true)
Exchanges the vector at this location with the vector at another location.
Definition: Vector.cpp:287
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Vector.h:611
int set_file(size_t index, const unsigned char *value, size_t size)
Atomically sets the value of an index to an arbitrary string.
Definition: Vector.cpp:494
bool is_false(void) const
Determines if the value of the vector is false.
Definition: Vector.cpp:883
virtual void modify_(void)
Polymorphic modify method used by collection containers.
Definition: Vector.cpp:89
virtual BaseContainer * clone(void) const
Clones this container.
Definition: Vector.cpp:100
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
Definition: Vector.cpp:200
void transfer_to(Vector &other)
Transfers elements from this vector to another.
Definition: Vector.cpp:376
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 ...
Definition: Vector.cpp:893
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
Definition: Vector.cpp:94
void push_back(KnowledgeRecord value)
Pushes the value to the end of the array after incrementing the array size.
Definition: Vector.cpp:153
int set(size_t index, madara::knowledge::KnowledgeRecord::Integer value=madara::knowledge::KnowledgeRecord::MODIFIED)
Sets a knowledge variable to a specified value.
Definition: Vector.cpp:555
virtual ~Vector()
Destructor.
Definition: Vector.cpp:41
Vector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
Definition: Vector.cpp:4
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
Definition: Vector.cpp:450
void operator=(const Vector &rhs)
Assignment operator.
Definition: Vector.cpp:116
int read_file(size_t index, const std::string &filename)
Read a file into the index.
Definition: Vector.cpp:464
knowledge::KnowledgeRecord to_record(size_t index) const
Retrieves a copy of the record from the map.
Definition: Vector.cpp:436
size_t size(void) const
Returns the size of the local vector.
Definition: Vector.inl:23
constexpr string_t string
Provides functions and classes for the distributed knowledge base.
::std::vector< KnowledgeRecord > KnowledgeVector