MADARA  3.2.3
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_file (i, 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  std::lock(*context_, *other.context_, mutex_, other.mutex_);
405 
406  ContextGuard context_guard (*context_, std::adopt_lock);
407  ContextGuard other_context_guard (*other.context_, std::adopt_lock);
408  MADARA_GUARD_TYPE guard (mutex_, std::adopt_lock),
409  guard2 (other.mutex_, std::adopt_lock);
410 
411 
412  if (refresh_keys)
413  {
414  other.resize ();
415  this->resize ();
416  }
417 
418  size_t other_size = other.vector_.size ();
419  size_t this_size = this->vector_.size ();
420 
421  for (size_t i = 0; i < this_size; ++i)
422  {
423  // temp = this[i];
425 
426  if (i < other_size)
427  {
428  auto val = other.context_->get (other.vector_[i], other.settings_);
429  // this[i] = other[i];
430  context_->set (this->vector_[i], std::move(val),
431  settings_);
432 
433  // other[i] = temp;
434  other.context_->set (other.vector_[i], std::move(temp),
435  other.settings_);
436  }
437  else
438  {
439  if (delete_keys)
440  {
441  std::stringstream buffer;
442  buffer << this->name_;
443 
444  buffer << delimiter_;
445  buffer << i;
446  this->context_->delete_variable (buffer.str (), other.settings_);
447  }
448  else
449  {
451  this->context_->set (this->vector_[i], empty, this->settings_);
452  }
453 
454  {
455  std::stringstream buffer;
456  buffer << other.name_;
457  buffer << delimiter_;
458  buffer << i;
459 
460  // other[i] = temp;
461  other.context_->set (buffer.str (), std::move(temp), other.settings_);
462  }
463  }
464 
465  }
466 
467  // copy the other vector's elements to this vector's location
468  for (size_t i = this_size; i < other_size; ++i)
469  {
470  std::stringstream buffer;
471  buffer << this->name_;
472  buffer << delimiter_;
473  buffer << i;
474  context_->set (buffer.str (),
475  other.context_->get (other.vector_[i], other.settings_),
476  this->settings_);
477  }
478 
479  // set the size appropriately
480  this->context_->set (this->size_, other_size, this->settings_);
481  other.context_->set (other.size_, this_size, other.settings_);
482 
483  if (refresh_keys)
484  {
485  this->resize (-1, true);
486  other.resize (-1, true);
487  }
488  }
489 }
490 
491 void
493 {
494  if (context_ && other.context_)
495  {
496  std::lock(*context_, *other.context_, mutex_, other.mutex_);
497 
498  ContextGuard context_guard (*context_, std::adopt_lock);
499  ContextGuard other_context_guard (*other.context_, std::adopt_lock);
500  MADARA_GUARD_TYPE guard (mutex_, std::adopt_lock),
501  guard2 (other.mutex_, std::adopt_lock);
502 
503 
504  size_t other_size = other.vector_.size ();
505  size_t this_size = this->vector_.size ();
506 
507  size_t size = other_size + this_size;
508  other.resize ((int)size);
509 
510  for (size_t i = 0, j = other_size; i < this_size; ++i, ++j)
511  {
512  other.context_->set (other.vector_[j], (*this)[i], other.settings_);
513  }
514 
515  this->resize (0, true);
516  }
517 }
518 
519 void
521  KnowledgeVector & target) const
522 {
523  if (context_)
524  {
525  ContextGuard context_guard (*context_);
526  MADARA_GUARD_TYPE guard (mutex_);
527 
528  target.resize (vector_.size ());
529 
530  for (size_t i = 0; i < vector_.size (); ++i)
531  {
532  target[i].deep_copy ((*this)[i]);
533  }
534  }
535 }
536 
539  size_t index) const
540 {
542  KnowledgeUpdateSettings keep_local (true);
543 
544  if (index < vector_.size () && context_)
545  {
546  ContextGuard context_guard (*context_);
547  MADARA_GUARD_TYPE guard (mutex_);
548  result = context_->get (vector_[index], keep_local);
549  }
550 
551  return result;
552 }
553 
556  size_t index) const
557 {
559 
560  if (index < vector_.size () && context_)
561  {
562  ContextGuard context_guard (*context_);
563  MADARA_GUARD_TYPE guard (mutex_);
564  result = context_->get (vector_[index], settings_);
565  }
566 
567  return result;
568 }
569 
570 bool
572  size_t index) const
573 {
574  bool result (false);
575 
576  if (index < vector_.size () && context_)
577  {
578  ContextGuard context_guard (*context_);
579  MADARA_GUARD_TYPE guard (mutex_);
580  result = context_->exists (vector_[index]);
581  }
582 
583  return result;
584 }
585 
586 int
588  size_t index,
589  const std::string & filename)
590 {
591  int result = -1;
592 
593  if (index < vector_.size () && context_)
594  {
595  ContextGuard context_guard (*context_);
596  MADARA_GUARD_TYPE guard (mutex_);
597  result = context_->read_file (vector_[index], filename, settings_);
598  }
599 
600  return result;
601 }
602 
603 int
605  size_t index,
606  const std::string & filename,
607  const KnowledgeUpdateSettings & settings)
608 {
609  int result = -1;
610 
611  if (index < vector_.size () && context_)
612  {
613  ContextGuard context_guard (*context_);
614  MADARA_GUARD_TYPE guard (mutex_);
615  result = context_->read_file (vector_[index], filename, settings);
616  }
617 
618  return result;
619 }
620 
621 int
623  size_t index,
624  const unsigned char * value, size_t size)
625 {
626  int result = -1;
627 
628  if (index < vector_.size () && context_)
629  {
630  ContextGuard context_guard (*context_);
631  MADARA_GUARD_TYPE guard (mutex_);
632  result = context_->set_file (vector_[index], value, size, settings_);
633  }
634 
635  return result;
636 }
637 
638 int
640  size_t index,
641  const unsigned char * value, size_t size,
642  const KnowledgeUpdateSettings & settings)
643 {
644  int result = -1;
645 
646  if (index < vector_.size () && context_)
647  {
648  ContextGuard context_guard (*context_);
649  MADARA_GUARD_TYPE guard (mutex_);
650  result = context_->set_file (vector_[index], value, size, settings);
651  }
652 
653  return result;
654 }
655 
656 int
658  size_t index,
659  const unsigned char * value, size_t size)
660 {
661  int result = -1;
662 
663  if (index < vector_.size () && context_)
664  {
665  ContextGuard context_guard (*context_);
666  MADARA_GUARD_TYPE guard (mutex_);
667  result = context_->set_jpeg (vector_[index], value, size, settings_);
668  }
669 
670  return result;
671 }
672 
673 int
675  size_t index,
676  const unsigned char * value, size_t size,
677  const KnowledgeUpdateSettings & settings)
678 {
679  int result = -1;
680 
681  if (index < vector_.size () && context_)
682  {
683  ContextGuard context_guard (*context_);
684  MADARA_GUARD_TYPE guard (mutex_);
685  result = context_->set_jpeg (vector_[index], value, size, settings);
686  }
687  return result;
688 }
689 
690 int
692  size_t index,
694 {
695  int result = -1;
696 
697  if (index < vector_.size () && context_)
698  {
699  ContextGuard context_guard (*context_);
700  MADARA_GUARD_TYPE guard (mutex_);
701  result = context_->set (vector_[index], value, settings_);
702  }
703 
704  return result;
705 }
706 
707 int
709  size_t index,
711  const KnowledgeUpdateSettings & settings)
712 {
713  int result = -1;
714 
715  if (index < vector_.size () && context_)
716  {
717  ContextGuard context_guard (*context_);
718  MADARA_GUARD_TYPE guard (mutex_);
719  result = context_->set (vector_[index], value, settings);
720  }
721 
722  return result;
723 }
724 
725 int
727  size_t index,
728  size_t sub_index,
730 {
731  int result = -1;
732 
733  if (index < vector_.size () && context_)
734  {
735  ContextGuard context_guard (*context_);
736  MADARA_GUARD_TYPE guard (mutex_);
737  result = context_->set_index (vector_[index], sub_index, value, settings_);
738  }
739 
740  return result;
741 }
742 
743 int
745  size_t index,
746  size_t sub_index,
748  const KnowledgeUpdateSettings & settings)
749 {
750  int result = -1;
751 
752  if (index < vector_.size () && context_)
753  {
754  ContextGuard context_guard (*context_);
755  MADARA_GUARD_TYPE guard (mutex_);
756  result = context_->set_index (vector_[index], sub_index, value, settings);
757  }
758 
759  return result;
760 }
761 
762 int
764  size_t index,
766  uint32_t size)
767 {
768  int result = -1;
769 
770  if (index < vector_.size () && context_)
771  {
772  ContextGuard context_guard (*context_);
773  MADARA_GUARD_TYPE guard (mutex_);
774  result = context_->set (vector_[index], value, size, settings_);
775  }
776 
777  return result;
778 }
779 
780 int
782  size_t index,
784  uint32_t size,
785  const KnowledgeUpdateSettings & settings)
786 {
787  int result = -1;
788 
789  if (index < vector_.size () && context_)
790  {
791  ContextGuard context_guard (*context_);
792  MADARA_GUARD_TYPE guard (mutex_);
793  result = context_->set (vector_[index], value, size, settings);
794  }
795 
796  return result;
797 }
798 
799 int
801  size_t index,
802  const std::vector <KnowledgeRecord::Integer> & value)
803 {
804  int result = -1;
805 
806  if (index < vector_.size () && context_)
807  {
808  ContextGuard context_guard (*context_);
809  MADARA_GUARD_TYPE guard (mutex_);
810  result = context_->set (vector_[index], value, settings_);
811  }
812 
813  return result;
814 }
815 
816 int
818  size_t index,
819  const std::vector <KnowledgeRecord::Integer> & value,
820  const KnowledgeUpdateSettings & settings)
821 {
822  int result = -1;
823 
824  if (index < vector_.size () && context_)
825  {
826  ContextGuard context_guard (*context_);
827  MADARA_GUARD_TYPE guard (mutex_);
828  result = context_->set (vector_[index], value, settings);
829  }
830 
831  return result;
832 }
833 
834 int
836  size_t index,
837  double value)
838 {
839  int result = -1;
840 
841  if (index < vector_.size () && context_)
842  {
843  ContextGuard context_guard (*context_);
844  MADARA_GUARD_TYPE guard (mutex_);
845  result = context_->set (vector_[index], value, settings_);
846  }
847 
848  return result;
849 }
850 
851 int
853  size_t index,
854  double value,
855  const KnowledgeUpdateSettings & settings)
856 {
857  int result = -1;
858 
859  if (index < vector_.size () && context_)
860  {
861  ContextGuard context_guard (*context_);
862  MADARA_GUARD_TYPE guard (mutex_);
863  result = context_->set (vector_[index], value, settings);
864  }
865 
866  return result;
867 }
868 
869 int
871  size_t index,
872  size_t sub_index,
873  double value)
874 {
875  int result = -1;
876 
877  if (index < vector_.size () && context_)
878  {
879  ContextGuard context_guard (*context_);
880  MADARA_GUARD_TYPE guard (mutex_);
881  result = context_->set_index (vector_[index], sub_index, value, settings_);
882  }
883 
884  return result;
885 }
886 
887 int
889  size_t index,
890  size_t sub_index,
891  double value,
892  const KnowledgeUpdateSettings & settings)
893 {
894  int result = -1;
895 
896  if (index < vector_.size () && context_)
897  {
898  ContextGuard context_guard (*context_);
899  MADARA_GUARD_TYPE guard (mutex_);
900  result = context_->set_index (vector_[index], sub_index, value, settings);
901  }
902 
903  return result;
904 }
905 
906 int
908  size_t index,
909  const double * value,
910  uint32_t size)
911 {
912  int result = -1;
913 
914  if (index < vector_.size () && context_)
915  {
916  ContextGuard context_guard (*context_);
917  MADARA_GUARD_TYPE guard (mutex_);
918  result = context_->set (vector_[index], value, size, settings_);
919  }
920 
921  return result;
922 }
923 
924 int
926  size_t index,
927  const double * value,
928  uint32_t size,
929  const KnowledgeUpdateSettings & settings)
930 {
931  int result = -1;
932 
933  if (index < vector_.size () && context_)
934  {
935  ContextGuard context_guard (*context_);
936  MADARA_GUARD_TYPE guard (mutex_);
937  result = context_->set (vector_[index], value, size, settings);
938  }
939 
940  return result;
941 }
942 
943 int
945  size_t index,
946  const std::vector <double> & value)
947 {
948  int result = -1;
949 
950  if (index < vector_.size () && context_)
951  {
952  ContextGuard context_guard (*context_);
953  MADARA_GUARD_TYPE guard (mutex_);
954  result = context_->set (vector_[index], value, settings_);
955  }
956 
957  return result;
958 }
959 
960 int
962  size_t index,
963  const std::vector <double> & value,
964  const KnowledgeUpdateSettings & settings)
965 {
966  int result = -1;
967 
968  if (index < vector_.size () && context_)
969  {
970  ContextGuard context_guard (*context_);
971  MADARA_GUARD_TYPE guard (mutex_);
972  result = context_->set (vector_[index], value, settings);
973  }
974 
975  return result;
976 }
977 
978 int
980  size_t index,
981  const std::string & value)
982 {
983  int result = -1;
984 
985  if (index < vector_.size () && context_)
986  {
987  ContextGuard context_guard (*context_);
988  MADARA_GUARD_TYPE guard (mutex_);
989  result = context_->set (vector_[index], value, settings_);
990  }
991 
992  return result;
993 }
994 
995 int
997  size_t index,
998  const std::string & value,
999  const KnowledgeUpdateSettings & settings)
1000 {
1001  int result = -1;
1002 
1003  if (index < vector_.size () && context_)
1004  {
1005  ContextGuard context_guard (*context_);
1006  MADARA_GUARD_TYPE guard (mutex_);
1007  result = context_->set (vector_[index], value, settings);
1008  }
1009 
1010  return result;
1011 }
1012 
1013 void
1015  size_t index,
1016  uint32_t quality,
1017  const KnowledgeReferenceSettings & settings)
1018 {
1019  if (index < vector_.size () && context_)
1020  {
1021  ContextGuard context_guard (*context_);
1022  MADARA_GUARD_TYPE guard (mutex_);
1023  context_->set_quality (vector_[index].get_name (), quality,
1024  true, settings);
1025  }
1026 }
1027 
1028 
1029 bool
1031 {
1032  bool result (false);
1033 
1035  "Vector::is_true: Checking for truth\n");
1036 
1037  if (context_)
1038  {
1039  ContextGuard context_guard (*context_);
1040  MADARA_GUARD_TYPE guard (mutex_);
1041 
1042  result = true;
1043 
1045  "Vector::is_true: context was not null. Result changed to %d\n",
1046  (int)result);
1047 
1048  for (size_t index = 0; index < vector_.size (); ++index)
1049  {
1050 
1052  "Vector::is_true: checking index %d, is_false of %d. \n",
1053  (int)result, (int)context_->get (vector_[index]).is_false ());
1054 
1055  if (context_->get (vector_[index]).is_false ())
1056  {
1058  "Vector::is_true: result is false, breaking\n");
1059 
1060  result = false;
1061  break;
1062  }
1063  }
1064 
1065  if (vector_.size () == 0)
1066  result = false;
1067  }
1068 
1070  "Vector::is_true: final result is %d\n", (int)result);
1071 
1072  return result;
1073 }
1074 
1075 bool
1077 {
1078  return !is_true ();
1079 }
1080 
1081 
1082 bool
1084 {
1085  return is_true ();
1086 }
1087 
1088 bool
1090 {
1091  return is_false ();
1092 }
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
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:571
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:726
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:555
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:622
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:1030
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:657
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
static struct madara::knowledge::tags::string_t string
bool is_false(void) const
Determines if the value of the vector is false.
Definition: Vector.cpp:1076
void copy_to(KnowledgeVector &target) const
Copies the vector elements to an STL vector of Knowledge Records.
Definition: Vector.cpp:520
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
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:691
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:1014
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
Integer to_integer(void) const
converts the value to an integer.
int read_file(size_t index, const std::string &filename)
Read a file into the index.
Definition: Vector.cpp:587
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:1089
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:538
Settings for applying knowledge updates.
void transfer_to(Vector &other)
Transfers elements from this vector to another.
Definition: Vector.cpp:492
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
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:1083
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...