MADARA  3.1.8
Vector.cpp
Go to the documentation of this file.
1 #include "Vector.h"
3 
4 
6  const KnowledgeUpdateSettings & settings,
7  const std::string & delimiter)
8 : BaseContainer ("", settings), context_ (0), delimiter_ (delimiter)
9 {
10 }
11 
13  const std::string & name,
15  int size,
16  bool delete_vars,
17  const KnowledgeUpdateSettings & settings,
18  const std::string & delimiter)
19  : BaseContainer (name, settings), context_ (&(knowledge.get_context ())),
20  delimiter_ (delimiter)
21 {
22  size_ = get_size_ref ();
23  resize (size, delete_vars);
24 }
25 
27  const std::string & name,
29  int size,
30  bool delete_vars,
31  const KnowledgeUpdateSettings & settings,
32  const std::string & delimiter)
33  : BaseContainer (name, settings), context_ (knowledge.get_context ()),
34  delimiter_ (delimiter)
35 {
36  size_ = get_size_ref ();
37  resize (size, delete_vars);
38 }
39 
41  : BaseContainer (rhs), context_ (rhs.context_),
42  vector_ (rhs.vector_),
43  size_ (rhs.size_),
45 {
46 
47 }
48 
49 
51 {
52 }
53 
54 void
56 {
57  if (context_ && name_ != "")
58  {
59  ContextGuard context_guard (*context_);
60  MADARA_GUARD_TYPE guard (mutex_);
61 
62  for (size_t index = 0; index < vector_.size (); ++index)
63  context_->mark_modified (vector_[index]);
64 
66  }
67 }
68 
71 {
72  std::stringstream result;
73 
74  result << "Vector: ";
75 
76  if (context_)
77  {
78  ContextGuard context_guard (*context_);
79  MADARA_GUARD_TYPE guard (mutex_);
80  size_t elements = vector_.size ();
81 
82  result << this->name_;
83  result << " [" << elements << "]";
84  result << " = [";
85 
86  if (elements > 0)
87  {
88  result << context_->get (vector_[0]).to_string ();
89 
90  for (size_t index = 1; index < elements; ++index)
91  {
92  result << ", " << context_->get (vector_[index]).to_string ();
93  }
94  }
95 
96  result << "]";
97  }
98 
99  return result.str ();
100 }
101 
102 
103 void
105 {
106  modify ();
107 }
108 
111 {
112  return get_debug_info ();
113 }
114 
117 {
118  return new Vector (*this);
119 }
120 
121 void
123 {
124  if (context_ && name_ != "" && index < vector_.size ())
125  {
126  ContextGuard context_guard (*context_);
127  MADARA_GUARD_TYPE guard (mutex_);
128 
129  context_->mark_modified (vector_[index]);
130  }
131 }
132 
133 void
135  const Vector & rhs)
136 {
137  if (this != &rhs)
138  {
139  MADARA_GUARD_TYPE guard (mutex_), guard2 (rhs.mutex_);
140 
141  this->context_ = rhs.context_;
142  this->name_ = rhs.name_;
143  this->settings_ = rhs.settings_;
144  this->size_ = rhs.size_;
145  this->vector_ = rhs.vector_;
146  }
147 }
148 
149 
152 {
153  VariableReference ref;
154 
155  if (context_ && name_ != "")
156  {
157  KnowledgeUpdateSettings keep_local (true);
158  std::stringstream buffer;
159 
160  ContextGuard context_guard (*context_);
161  MADARA_GUARD_TYPE guard (mutex_);
162 
163  buffer << name_;
164  buffer << delimiter_;
165  buffer << "size";
166 
167  ref = context_->get_ref (buffer.str (), keep_local);
168  }
169 
170  return ref;
171 }
172 
175 {
176  if (context_ && name_ != "")
177  {
178  ContextGuard context_guard (*context_);
179  MADARA_GUARD_TYPE guard (mutex_);
180 
181  if (!size_.is_valid ())
182  {
183  size_ = get_size_ref ();
184  }
185 
186  size_t i = size ();
187 
188  resize ((int)i + 1);
189 
191  {
192  set (i, value.to_double ());
193  }
194  else if (value.type () == knowledge::KnowledgeRecord::STRING)
195  {
196  set (i, value.to_string ());
197  }
198  else if (value.type () == knowledge::KnowledgeRecord::INTEGER_ARRAY)
199  {
200  set (i, value.to_integers ());
201  }
202  else if (value.type () == knowledge::KnowledgeRecord::DOUBLE_ARRAY)
203  {
204  set (i, value.to_doubles ());
205  }
206  else if (value.is_binary_file_type ())
207  {
208  size_t size;
209  unsigned char * unmanaged = value.to_unmanaged_buffer (size);
210  set (i, (char *)unmanaged, size);
211  delete [] unmanaged;
212  }
213  else
214  {
215  set (i, value.to_integer ());
216  }
217  }
218 }
219 
220 void
222  int size, bool delete_vars)
223 {
224  if (context_ && name_ != "")
225  {
226  ContextGuard context_guard (*context_);
227  MADARA_GUARD_TYPE guard (mutex_);
228 
229  if (!size_.is_valid ())
230  {
231  size_ = get_size_ref ();
232  }
233 
234  if (size >= 0)
235  {
236  size_t old_size = vector_.size ();
237 
238  if (old_size != (size_t)size)
239  {
240  vector_.resize (size);
241 
243 
244  if ((size_t)size > old_size)
245  {
246  for (; old_size < (size_t)size; ++old_size)
247  {
248  std::stringstream buffer;
249  buffer << name_;
250  buffer << delimiter_;
251  buffer << old_size;
252  vector_[old_size] = context_->get_ref (buffer.str (), settings_);
253  }
254  }
255  else if (delete_vars)
256  {
257  for (; (size_t)size < old_size; ++size)
258  {
259  std::stringstream buffer;
260  buffer << name_;
261  buffer << delimiter_;
262  buffer << size;
263 
264  context_->delete_variable (buffer.str (), settings_);
265  }
266  }
267  }
268  }
269  else
270  {
271  // dynamically allocate size from the context
272  size_t cur_size =
274 
275  size_t old_size = vector_.size ();
276 
277  if (old_size != cur_size)
278  {
279  vector_.resize (cur_size);
280 
281  if (cur_size > old_size)
282  {
283  for (; old_size < cur_size; ++old_size)
284  {
285  std::stringstream buffer;
286  buffer << name_;
287  buffer << delimiter_;
288  buffer << old_size;
289  vector_[old_size] = context_->get_ref (buffer.str (), settings_);
290  }
291  }
292  else if (delete_vars)
293  {
294  for (; cur_size < old_size; ++cur_size)
295  {
296  std::stringstream buffer;
297  buffer << name_;
298  buffer << delimiter_;
299  buffer << cur_size;
300 
301  context_->delete_variable (buffer.str (), settings_);
302  }
303  }
304  }
305  }
306  }
307 }
308 
309 size_t
311 {
312  MADARA_GUARD_TYPE guard (mutex_);
313  return vector_.size ();
314 }
315 
316 void
318  const std::string & var_name,
320 {
321  if (context_ != &(knowledge.get_context ()) || name_ != var_name)
322  {
323  context_ = &(knowledge.get_context ());
324 
325  ContextGuard context_guard (*context_);
326  MADARA_GUARD_TYPE guard (mutex_);
327 
328  name_ = var_name;
329 
330  vector_.clear ();
331 
332  size_ = get_size_ref ();
333 
334  resize (size);
335  }
336 }
337 
338 void
340  const std::string & var_name,
341  Variables & knowledge, int size)
342 {
343  if (context_ != knowledge.get_context () || name_ != var_name)
344  {
345  context_ = knowledge.get_context ();
346 
347  ContextGuard context_guard (*context_);
348  MADARA_GUARD_TYPE guard (mutex_);
349 
350  name_ = var_name;
351 
352  vector_.clear ();
353  resize (size);
354  }
355 }
356 
357 void
359  const std::string & var_name,
361 {
362  if (context_ != &knowledge || name_ != var_name)
363  {
364  context_ = &knowledge;
365 
366  ContextGuard context_guard (*context_);
367  MADARA_GUARD_TYPE guard (mutex_);
368 
369  name_ = var_name;
370 
371  vector_.clear ();
372  resize (size);
373  }
374 }
375 
376 void
378 const std::string & delimiter)
379 {
380  delimiter_ = delimiter;
381  if (context_)
382  {
383  ContextGuard context_guard (*context_);
384  MADARA_GUARD_TYPE guard (mutex_);
385 
386  vector_.clear ();
387  resize (-1);
388  }
389 }
390 
391 
394 {
395  return delimiter_;
396 }
397 
398 void
400  Vector & other, bool refresh_keys, bool delete_keys)
401 {
402  if (context_ && other.context_)
403  {
404  ContextGuard context_guard (*context_);
405  ContextGuard other_context_guard (*other.context_);
406  MADARA_GUARD_TYPE guard (mutex_), guard2 (other.mutex_);
407 
408  if (refresh_keys)
409  {
410  other.resize ();
411  this->resize ();
412  }
413 
414  size_t other_size = other.vector_.size ();
415  size_t this_size = this->vector_.size ();
416 
417  for (size_t i = 0; i < this_size; ++i)
418  {
419  // temp = this[i];
421 
422  if (i < other_size)
423  {
424  // this[i] = other[i];
425  context_->set (this->vector_[i],
426  context_->get (other.vector_[i], other.settings_),
427  settings_);
428 
429  // other[i] = temp;
430  other.context_->set (other.vector_[i], temp, other.settings_);
431  }
432  else
433  {
434  if (delete_keys)
435  {
436  std::stringstream buffer;
437  buffer << this->name_;
438  buffer << delimiter_;
439  buffer << i;
440  this->context_->delete_variable (buffer.str (), other.settings_);
441  }
442  else
443  {
445  this->context_->set (this->vector_[i], zero, this->settings_);
446  }
447 
448  {
449  std::stringstream buffer;
450  buffer << other.name_;
451  buffer << delimiter_;
452  buffer << i;
453 
454  // other[i] = temp;
455  other.context_->set (buffer.str (), temp, other.settings_);
456  }
457  }
458 
459  }
460 
461  // copy the other vector's elements to this vector's location
462  for (size_t i = this_size; i < other_size; ++i)
463  {
464  std::stringstream buffer;
465  buffer << this->name_;
466  buffer << delimiter_;
467  buffer << i;
468  context_->set (buffer.str (),
469  other.context_->get (other.vector_[i], other.settings_), this->settings_);
470  }
471 
472  // set the size appropriately
473  this->context_->set (this->size_,
474  knowledge::KnowledgeRecord::Integer (other_size), this->settings_);
475  other.context_->set (other.size_,
477 
478  if (refresh_keys)
479  {
480  this->resize (-1, true);
481  other.resize (-1, true);
482  }
483  }
484 }
485 
486 void
488 {
489  if (context_ && other.context_)
490  {
491  ContextGuard context_guard (*context_);
492  ContextGuard other_context_guard (*other.context_);
493  MADARA_GUARD_TYPE guard (mutex_);
494  MADARA_GUARD_TYPE guard2 (other.mutex_);
495 
496  size_t other_size = other.vector_.size ();
497  size_t this_size = this->vector_.size ();
498 
499  size_t size = other_size + this_size;
500  other.resize ((int)size);
501 
502  for (size_t i = 0, j = other_size; i < this_size; ++i, ++j)
503  {
504  other.context_->set (other.vector_[j], (*this)[i], other.settings_);
505  }
506 
507  this->resize (0, true);
508  }
509 }
510 
511 void
513  KnowledgeVector & target) const
514 {
515  if (context_)
516  {
517  ContextGuard context_guard (*context_);
518  MADARA_GUARD_TYPE guard (mutex_);
519 
520  target.resize (vector_.size ());
521 
522  for (size_t i = 0; i < vector_.size (); ++i)
523  {
524  target[i].deep_copy ((*this)[i]);
525  }
526  }
527 }
528 
531  size_t index) const
532 {
534  KnowledgeUpdateSettings keep_local (true);
535 
536  if (index < vector_.size () && context_)
537  {
538  ContextGuard context_guard (*context_);
539  MADARA_GUARD_TYPE guard (mutex_);
540  result = context_->get (vector_[index], keep_local);
541  }
542 
543  return result;
544 }
545 
548  size_t index) const
549 {
551 
552  if (index < vector_.size () && context_)
553  {
554  ContextGuard context_guard (*context_);
555  MADARA_GUARD_TYPE guard (mutex_);
556  result = context_->get (vector_[index], settings_);
557  }
558 
559  return result;
560 }
561 
562 bool
564  size_t index) const
565 {
566  bool result (false);
567 
568  if (index < vector_.size () && context_)
569  {
570  ContextGuard context_guard (*context_);
571  MADARA_GUARD_TYPE guard (mutex_);
572  result = context_->exists (vector_[index]);
573  }
574 
575  return result;
576 }
577 
578 int
580  size_t index,
581  const std::string & filename)
582 {
583  int result = -1;
584 
585  if (index < vector_.size () && context_)
586  {
587  ContextGuard context_guard (*context_);
588  MADARA_GUARD_TYPE guard (mutex_);
589  result = context_->read_file (vector_[index], filename, settings_);
590  }
591 
592  return result;
593 }
594 
595 int
597  size_t index,
598  const std::string & filename,
599  const KnowledgeUpdateSettings & settings)
600 {
601  int result = -1;
602 
603  if (index < vector_.size () && context_)
604  {
605  ContextGuard context_guard (*context_);
606  MADARA_GUARD_TYPE guard (mutex_);
607  result = context_->read_file (vector_[index], filename, settings);
608  }
609 
610  return result;
611 }
612 
613 int
615  size_t index,
616  const unsigned char * value, size_t size)
617 {
618  int result = -1;
619 
620  if (index < vector_.size () && context_)
621  {
622  ContextGuard context_guard (*context_);
623  MADARA_GUARD_TYPE guard (mutex_);
624  result = context_->set_file (vector_[index], value, size, settings_);
625  }
626 
627  return result;
628 }
629 
630 int
632  size_t index,
633  const unsigned char * value, size_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_file (vector_[index], value, size, settings);
643  }
644 
645  return result;
646 }
647 
648 int
650  size_t index,
651  const unsigned char * value, size_t size)
652 {
653  int result = -1;
654 
655  if (index < vector_.size () && context_)
656  {
657  ContextGuard context_guard (*context_);
658  MADARA_GUARD_TYPE guard (mutex_);
659  result = context_->set_jpeg (vector_[index], value, size, settings_);
660  }
661 
662  return result;
663 }
664 
665 int
667  size_t index,
668  const unsigned char * value, size_t size,
669  const KnowledgeUpdateSettings & settings)
670 {
671  int result = -1;
672 
673  if (index < vector_.size () && context_)
674  {
675  ContextGuard context_guard (*context_);
676  MADARA_GUARD_TYPE guard (mutex_);
677  result = context_->set_jpeg (vector_[index], value, size, settings);
678  }
679  return result;
680 }
681 
682 int
684  size_t index,
686 {
687  int result = -1;
688 
689  if (index < vector_.size () && context_)
690  {
691  ContextGuard context_guard (*context_);
692  MADARA_GUARD_TYPE guard (mutex_);
693  result = context_->set (vector_[index], value, settings_);
694  }
695 
696  return result;
697 }
698 
699 int
701  size_t index,
703  const KnowledgeUpdateSettings & settings)
704 {
705  int result = -1;
706 
707  if (index < vector_.size () && context_)
708  {
709  ContextGuard context_guard (*context_);
710  MADARA_GUARD_TYPE guard (mutex_);
711  result = context_->set (vector_[index], value, settings);
712  }
713 
714  return result;
715 }
716 
717 int
719  size_t index,
720  size_t sub_index,
722 {
723  int result = -1;
724 
725  if (index < vector_.size () && context_)
726  {
727  ContextGuard context_guard (*context_);
728  MADARA_GUARD_TYPE guard (mutex_);
729  result = context_->set_index (vector_[index], sub_index, value, settings_);
730  }
731 
732  return result;
733 }
734 
735 int
737  size_t index,
738  size_t sub_index,
740  const KnowledgeUpdateSettings & settings)
741 {
742  int result = -1;
743 
744  if (index < vector_.size () && context_)
745  {
746  ContextGuard context_guard (*context_);
747  MADARA_GUARD_TYPE guard (mutex_);
748  result = context_->set_index (vector_[index], sub_index, value, settings);
749  }
750 
751  return result;
752 }
753 
754 int
756  size_t index,
758  uint32_t size)
759 {
760  int result = -1;
761 
762  if (index < vector_.size () && context_)
763  {
764  ContextGuard context_guard (*context_);
765  MADARA_GUARD_TYPE guard (mutex_);
766  result = context_->set (vector_[index], value, size, settings_);
767  }
768 
769  return result;
770 }
771 
772 int
774  size_t index,
776  uint32_t size,
777  const KnowledgeUpdateSettings & settings)
778 {
779  int result = -1;
780 
781  if (index < vector_.size () && context_)
782  {
783  ContextGuard context_guard (*context_);
784  MADARA_GUARD_TYPE guard (mutex_);
785  result = context_->set (vector_[index], value, size, settings);
786  }
787 
788  return result;
789 }
790 
791 int
793  size_t index,
794  const std::vector <KnowledgeRecord::Integer> & value)
795 {
796  int result = -1;
797 
798  if (index < vector_.size () && context_)
799  {
800  ContextGuard context_guard (*context_);
801  MADARA_GUARD_TYPE guard (mutex_);
802  result = context_->set (vector_[index], value, settings_);
803  }
804 
805  return result;
806 }
807 
808 int
810  size_t index,
811  const std::vector <KnowledgeRecord::Integer> & value,
812  const KnowledgeUpdateSettings & settings)
813 {
814  int result = -1;
815 
816  if (index < vector_.size () && context_)
817  {
818  ContextGuard context_guard (*context_);
819  MADARA_GUARD_TYPE guard (mutex_);
820  result = context_->set (vector_[index], value, settings);
821  }
822 
823  return result;
824 }
825 
826 int
828  size_t index,
829  double value)
830 {
831  int result = -1;
832 
833  if (index < vector_.size () && context_)
834  {
835  ContextGuard context_guard (*context_);
836  MADARA_GUARD_TYPE guard (mutex_);
837  result = context_->set (vector_[index], value, settings_);
838  }
839 
840  return result;
841 }
842 
843 int
845  size_t index,
846  double value,
847  const KnowledgeUpdateSettings & settings)
848 {
849  int result = -1;
850 
851  if (index < vector_.size () && context_)
852  {
853  ContextGuard context_guard (*context_);
854  MADARA_GUARD_TYPE guard (mutex_);
855  result = context_->set (vector_[index], value, settings);
856  }
857 
858  return result;
859 }
860 
861 int
863  size_t index,
864  size_t sub_index,
865  double value)
866 {
867  int result = -1;
868 
869  if (index < vector_.size () && context_)
870  {
871  ContextGuard context_guard (*context_);
872  MADARA_GUARD_TYPE guard (mutex_);
873  result = context_->set_index (vector_[index], sub_index, value, settings_);
874  }
875 
876  return result;
877 }
878 
879 int
881  size_t index,
882  size_t sub_index,
883  double value,
884  const KnowledgeUpdateSettings & settings)
885 {
886  int result = -1;
887 
888  if (index < vector_.size () && context_)
889  {
890  ContextGuard context_guard (*context_);
891  MADARA_GUARD_TYPE guard (mutex_);
892  result = context_->set_index (vector_[index], sub_index, value, settings);
893  }
894 
895  return result;
896 }
897 
898 int
900  size_t index,
901  const double * value,
902  uint32_t size)
903 {
904  int result = -1;
905 
906  if (index < vector_.size () && context_)
907  {
908  ContextGuard context_guard (*context_);
909  MADARA_GUARD_TYPE guard (mutex_);
910  result = context_->set (vector_[index], value, size, settings_);
911  }
912 
913  return result;
914 }
915 
916 int
918  size_t index,
919  const double * value,
920  uint32_t size,
921  const KnowledgeUpdateSettings & settings)
922 {
923  int result = -1;
924 
925  if (index < vector_.size () && context_)
926  {
927  ContextGuard context_guard (*context_);
928  MADARA_GUARD_TYPE guard (mutex_);
929  result = context_->set (vector_[index], value, size, settings);
930  }
931 
932  return result;
933 }
934 
935 int
937  size_t index,
938  const std::vector <double> & value)
939 {
940  int result = -1;
941 
942  if (index < vector_.size () && context_)
943  {
944  ContextGuard context_guard (*context_);
945  MADARA_GUARD_TYPE guard (mutex_);
946  result = context_->set (vector_[index], value, settings_);
947  }
948 
949  return result;
950 }
951 
952 int
954  size_t index,
955  const std::vector <double> & value,
956  const KnowledgeUpdateSettings & settings)
957 {
958  int result = -1;
959 
960  if (index < vector_.size () && context_)
961  {
962  ContextGuard context_guard (*context_);
963  MADARA_GUARD_TYPE guard (mutex_);
964  result = context_->set (vector_[index], value, settings);
965  }
966 
967  return result;
968 }
969 
970 int
972  size_t index,
973  const std::string & value)
974 {
975  int result = -1;
976 
977  if (index < vector_.size () && context_)
978  {
979  ContextGuard context_guard (*context_);
980  MADARA_GUARD_TYPE guard (mutex_);
981  result = context_->set (vector_[index], value, settings_);
982  }
983 
984  return result;
985 }
986 
987 int
989  size_t index,
990  const std::string & value,
991  const KnowledgeUpdateSettings & settings)
992 {
993  int result = -1;
994 
995  if (index < vector_.size () && context_)
996  {
997  ContextGuard context_guard (*context_);
998  MADARA_GUARD_TYPE guard (mutex_);
999  result = context_->set (vector_[index], value, settings);
1000  }
1001 
1002  return result;
1003 }
1004 
1005 void
1007  size_t index,
1008  uint32_t quality,
1009  const KnowledgeReferenceSettings & settings)
1010 {
1011  if (index < vector_.size () && context_)
1012  {
1013  ContextGuard context_guard (*context_);
1014  MADARA_GUARD_TYPE guard (mutex_);
1015  context_->set_quality (vector_[index].get_name (), quality,
1016  true, settings);
1017  }
1018 }
1019 
1020 
1021 bool
1023 {
1024  bool result (false);
1025 
1027  "Vector::is_true: Checking for truth\n");
1028 
1029  if (context_)
1030  {
1031  ContextGuard context_guard (*context_);
1032  MADARA_GUARD_TYPE guard (mutex_);
1033 
1034  result = true;
1035 
1037  "Vector::is_true: context was not null. Result changed to %d\n",
1038  (int)result);
1039 
1040  for (size_t index = 0; index < vector_.size (); ++index)
1041  {
1042 
1044  "Vector::is_true: checking index %d, is_false of %d. \n",
1045  (int)result, (int)context_->get (vector_[index]).is_false ());
1046 
1047  if (context_->get (vector_[index]).is_false ())
1048  {
1050  "Vector::is_true: result is false, breaking\n");
1051 
1052  result = false;
1053  break;
1054  }
1055  }
1056 
1057  if (vector_.size () == 0)
1058  result = false;
1059  }
1060 
1062  "Vector::is_true: final result is %d\n", (int)result);
1063 
1064  return result;
1065 }
1066 
1067 bool
1069 {
1070  return !is_true ();
1071 }
1072 
1073 
1074 bool
1076 {
1077  return is_true ();
1078 }
1079 
1080 bool
1082 {
1083  return is_false ();
1084 }
This class encapsulates an entry in a KnowledgeBase.
std::string get_delimiter(void)
Gets the delimiter for adding and detecting subvariables.
Definition: Vector.cpp:393
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
VariableReference size_
Reference to the size field of the vector space.
Definition: Vector.h:617
int32_t type(void) const
returns the size of the value
std::string get_name(void) const
Returns the name of the container.
virtual ~Vector()
Destructor.
Definition: Vector.cpp:50
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
int set_file(const std::string &key, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to an arbitrary string.
int set_jpeg(const std::string &key, const unsigned char *value, size_t size, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to a JPEG image.
double to_double(void) const
converts the value to a float/double
std::string name_
Prefix of variable.
bool exists(size_t index) const
Checks to see if the index has ever been assigned a value.
Definition: Vector.cpp:563
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:718
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Vector.h:607
size_t size(void) const
Returns the size of the local vector.
Definition: Vector.cpp:310
bool is_binary_file_type(void) const
returns true if the knowledge record has a binary file type
This class stores variables and their values for use by any entity needing state information in a thr...
knowledge::KnowledgeRecord to_record(size_t index) const
Retrieves a copy of the record from the map.
Definition: Vector.cpp:547
Vector(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings(), const std::string &delimiter=".")
Default constructor.
Definition: Vector.cpp:5
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:614
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
Definition: Vector.cpp:110
std::string delimiter_
Delimiter for the prefix to subvars.
Definition: Vector.h:622
bool is_true(void) const
Determines if all values in the vector are true.
Definition: Vector.cpp:1022
void operator=(const Vector &rhs)
Assignment operator.
Definition: Vector.cpp:134
MADARA_LOCK_TYPE mutex_
guard for access and changes
std::vector< VariableReference > vector_
Values of the array.
Definition: Vector.h:612
Optimized reference to a variable within the knowledge base.
int set_index(const std::string &key, size_t index, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of an array index to a value.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
Definition: Logger.h:20
bool is_valid(void) const
Checks to see if the variable reference has been initialized.
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:649
bool exists(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically checks to see if a variable already exists.
::std::vector< KnowledgeRecord > KnowledgeVector
void set_delimiter(const std::string &delimiter)
Sets the delimiter for adding and detecting subvariables.
Definition: Vector.cpp:377
A thread-safe guard for a context or knowledge base.
Definition: ContextGuard.h:23
void resize(int size=-1, bool delete_vars=true)
Resizes the vector.
Definition: Vector.cpp:221
This class stores a vector of KaRL variables.
Definition: Vector.h:35
void modify(void)
Mark the vector as modified.
Definition: Vector.cpp:55
bool is_false(void) const
Determines if the value of the vector is false.
Definition: Vector.cpp:1068
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
Definition: Vector.cpp:512
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:44
std::vector< double > to_doubles(void) const
converts the value to a vector of doubles
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:683
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
Definition: Vector.cpp:70
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:1006
Integer to_integer(void) const
converts the value to an integer
static constexpr struct madara::knowledge::tags::string_t string
int read_file(size_t index, const std::string &filename)
Read a file into the index.
Definition: Vector.cpp:579
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.
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:1081
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int size=-1)
Sets the variable name that this refers to.
Definition: Vector.cpp:317
knowledge::KnowledgeRecord operator[](size_t index) const
Retrieves a copy of the record from the map.
Definition: Vector.cpp:530
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
Settings for applying knowledge updates.
void transfer_to(Vector &other)
Transfers elements from this vector to another.
Definition: Vector.cpp:487
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.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
Definition: Vector.cpp:104
virtual BaseContainer * clone(void) const
Clones this container.
Definition: Vector.cpp:116
void push_back(KnowledgeRecord value)
Pushes the value to the end of the array after incrementing the array size.
Definition: Vector.cpp:173
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:399
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.
Definition: BaseContainer.h:33
int read_file(const std::string &key, const std::string &filename, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically reads a file into a variable.
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...
VariableReference get_size_ref(void)
Returns a reference to the size field of the current name.
Definition: Vector.cpp:151
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:1075
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.
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...