MADARA  3.1.8
ThreadSafeContext.h
Go to the documentation of this file.
1 #ifndef MADARA_THREADSAFECONTEXT_H
2 #define MADARA_THREADSAFECONTEXT_H
3 
11 #include "ace/Guard_T.h"
12 #include "ace/Recursive_Thread_Mutex.h"
13 #include "ace/Condition_Recursive_Thread_Mutex.h"
14 #include "ace/Synch.h"
16 #include "madara/logger/Logger.h"
17 
18 #ifndef ACE_LACKS_PRAGMA_ONCE
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 
22 #include <string>
23 #include <map>
25 
26 #include "madara/MADARA_export.h"
27 #include "madara/LockType.h"
36 
37 #ifdef _MADARA_JAVA_
38 #include "madara_jni.h"
39 #endif
40 
41 #ifdef _MADARA_PYTHON_CALLBACKS_
42 #include "boost/python/object.hpp"
43 #endif
44 
45 namespace madara
46 {
47  namespace expression
48  {
49  class Interpreter;
50  class CompositeArrayReference;
51  class VariableNode;
52  }
53 
54  namespace knowledge
55  {
56  namespace rcw
57  {
58  class BaseTracker;
59  }
60 
67  typedef std::map <std::string, bool> CopySet;
68 
72  typedef std::vector <std::string> PrefixVector;
73 
75  class KnowledgeBaseImpl;
76 
82  class MADARA_Export ThreadSafeContext
83  {
84  public:
85  friend class KnowledgeBaseImpl;
88  friend class rcw::BaseTracker;
89 
94 
98  ~ThreadSafeContext (void);
99 
107  get (const std::string & key,
108  const KnowledgeReferenceSettings & settings =
109  KnowledgeReferenceSettings ()) const;
110 
118  get (const VariableReference & variable,
119  const KnowledgeReferenceSettings & settings =
120  KnowledgeReferenceSettings ()) const;
121 
122  private:
130  with (const std::string & key,
131  const KnowledgeReferenceSettings & settings =
133 
141  with (const VariableReference & variable,
142  const KnowledgeReferenceSettings & settings =
151  with (const std::string & key,
152  const KnowledgeReferenceSettings & settings =
153  KnowledgeReferenceSettings ()) const;
154 
162  with (const VariableReference & variable,
163  const KnowledgeReferenceSettings & settings =
164  KnowledgeReferenceSettings ()) const;
165 
166  template<typename T>
167  using MethodType = std::shared_ptr<T> (KnowledgeRecord::*) (void);
168 
169  template<typename T, MethodType<T> Get, typename K>
170  std::shared_ptr<T> get_shared(K&& key,
171  const KnowledgeReferenceSettings & settings)
172  {
173  auto rec = with (std::forward<K>(key), settings);
174  if (rec) {
175  return (rec->*Get) ();
176  }
177  return nullptr;
178  }
179 
180  template<typename T>
181  using ConstMethodType = std::shared_ptr<T> (KnowledgeRecord::*) (void) const;
182 
183  template<typename T, ConstMethodType<T> Get, typename K>
184  std::shared_ptr<T> get_shared(K&& key,
185  const KnowledgeReferenceSettings & settings) const
186  {
187  auto rec = with (std::forward<K>(key), settings);
188  if (rec) {
189  return (rec->*Get) ();
190  }
191  return nullptr;
192  }
193 
194  public:
199  std::shared_ptr<std::string> share_string(const std::string & key,
200  const KnowledgeReferenceSettings & settings =
202  {
203  return get_shared<std::string, &KnowledgeRecord::share_string>(key, settings);
204  }
205 
210  std::shared_ptr<std::string> share_string(const VariableReference & key,
211  const KnowledgeReferenceSettings & settings =
213  {
214  return get_shared<std::string, &KnowledgeRecord::share_string>(key, settings);
215  }
216 
221  std::shared_ptr<std::string> take_string(const std::string & key,
222  const KnowledgeReferenceSettings & settings =
224  {
225  return get_shared<std::string, &KnowledgeRecord::take_string>(key, settings);
226  }
227 
232  std::shared_ptr<std::string> take_string(const VariableReference & key,
233  const KnowledgeReferenceSettings & settings =
235  {
236  return get_shared<std::string, &KnowledgeRecord::take_string>(key, settings);
237  }
238 
243  std::shared_ptr<std::vector<KnowledgeRecord::Integer>>
245  const KnowledgeReferenceSettings & settings =
247  {
248  return get_shared<std::vector<KnowledgeRecord::Integer>,
249  &KnowledgeRecord::share_integers>(key, settings);
250  }
251 
256  std::shared_ptr<std::vector<KnowledgeRecord::Integer>>
258  const KnowledgeReferenceSettings & settings =
260  {
261  return get_shared<std::vector<KnowledgeRecord::Integer>,
262  &KnowledgeRecord::share_integers>(key, settings);
263  }
264 
269  std::shared_ptr<std::vector<KnowledgeRecord::Integer>>
271  const KnowledgeReferenceSettings & settings =
273  {
274  return get_shared<std::vector<KnowledgeRecord::Integer>,
275  &KnowledgeRecord::take_integers>(key, settings);
276  }
277 
282  std::shared_ptr<std::vector<KnowledgeRecord::Integer>>
284  const KnowledgeReferenceSettings & settings =
286  {
287  return get_shared<std::vector<KnowledgeRecord::Integer>,
288  &KnowledgeRecord::take_integers>(key, settings);
289  }
290 
295  std::shared_ptr<std::vector<double>>
297  const KnowledgeReferenceSettings & settings =
299  {
300  return get_shared<std::vector<double>,
301  &KnowledgeRecord::share_doubles>(key, settings);
302  }
303 
308  std::shared_ptr<std::vector<double>>
310  const KnowledgeReferenceSettings & settings =
312  {
313  return get_shared<std::vector<double>,
314  &KnowledgeRecord::share_doubles>(key, settings);
315  }
316 
321  std::shared_ptr<std::vector<double>>
323  const KnowledgeReferenceSettings & settings =
325  {
326  return get_shared<std::vector<double>,
327  &KnowledgeRecord::take_doubles>(key, settings);
328  }
329 
334  std::shared_ptr<std::vector<double>>
336  const KnowledgeReferenceSettings & settings =
338  {
339  return get_shared<std::vector<double>,
340  &KnowledgeRecord::take_doubles>(key, settings);
341  }
342 
347  std::shared_ptr<std::vector<unsigned char>>
349  const KnowledgeReferenceSettings & settings =
351  {
352  return get_shared<std::vector<unsigned char>,
353  &KnowledgeRecord::share_binary>(key, settings);
354  }
355 
360  std::shared_ptr<std::vector<unsigned char>>
362  const KnowledgeReferenceSettings & settings =
364  {
365  return get_shared<std::vector<unsigned char>,
366  &KnowledgeRecord::share_binary>(key, settings);
367  }
368 
373  std::shared_ptr<std::vector<unsigned char>>
375  const KnowledgeReferenceSettings & settings =
377  {
378  return get_shared<std::vector<unsigned char>,
379  &KnowledgeRecord::take_binary>(key, settings);
380  }
381 
386  std::shared_ptr<std::vector<unsigned char>>
388  const KnowledgeReferenceSettings & settings =
390  {
391  return get_shared<std::vector<unsigned char>,
392  &KnowledgeRecord::take_binary>(key, settings);
393  }
394 
404  get_ref (const std::string & key,
405  const KnowledgeReferenceSettings & settings =
407 
416  get_ref (const std::string & key,
417  const KnowledgeReferenceSettings & settings =
418  KnowledgeReferenceSettings ()) const;
419 
427  KnowledgeRecord retrieve_index (const std::string & key,
428  size_t index,
429  const KnowledgeReferenceSettings & settings =
431 
439  KnowledgeRecord retrieve_index (
440  const VariableReference & variable,
441  size_t index,
442  const KnowledgeReferenceSettings & settings =
444 
454  KnowledgeRecord * get_record (const std::string & key,
455  const KnowledgeReferenceSettings & settings =
457 
466  int set_xml (const std::string & key,
467  const char * value, size_t size,
468  const KnowledgeUpdateSettings & settings =
470 
479  int set_xml (const VariableReference & variable,
480  const char * value, size_t size,
481  const KnowledgeUpdateSettings & settings =
483 
492  int set_jpeg (const std::string & key,
493  const unsigned char * value, size_t size,
494  const KnowledgeUpdateSettings & settings =
496 
505  int set_jpeg (const VariableReference & variable,
506  const unsigned char * value, size_t size,
507  const KnowledgeUpdateSettings & settings =
509 
518  int set_file (const std::string & key,
519  const unsigned char * value, size_t size,
520  const KnowledgeUpdateSettings & settings =
522 
531  int set_file (const VariableReference & variable,
532  const unsigned char * value, size_t size,
533  const KnowledgeUpdateSettings & settings =
535 
544  int set_text (const std::string & key,
545  const char * value, size_t size,
546  const KnowledgeUpdateSettings & settings =
548 
557  int set_text (const VariableReference & variable,
558  const char * value, size_t size,
559  const KnowledgeUpdateSettings & settings =
561 
570  template<typename T>
571  int set_index (const std::string & key,
572  size_t index, T&& value,
573  const KnowledgeUpdateSettings & settings =
575 
584  template<typename T>
585  int set_index (const VariableReference & variable,
586  size_t index, T&& value,
587  const KnowledgeUpdateSettings & settings =
589 
599  template<typename T>
600  int set_index_unsafe (const VariableReference & variable,
601  size_t index, T&& value,
602  const KnowledgeUpdateSettings & settings =
604 
613  template<typename T>
614  int set (const std::string & key,
615  T && value,
616  const KnowledgeUpdateSettings & settings =
618 
626  template<typename T>
627  int set (const VariableReference & variable,
628  T && value,
629  const KnowledgeUpdateSettings & settings =
631 
640  template<typename T>
641  int set (const std::string & key,
642  const T * value,
643  uint32_t size,
644  const KnowledgeUpdateSettings & settings =
646 
655  template<typename T>
656  int set (const VariableReference & variable,
657  const T * value,
658  uint32_t size,
659  const KnowledgeUpdateSettings & settings =
661 
671  template<typename T>
672  int set_unsafe (const VariableReference & variable,
673  T && value,
674  const KnowledgeUpdateSettings & settings =
676 
687  template<typename T>
688  int set_unsafe (const VariableReference & variable,
689  const T * array,
690  size_t size,
691  const KnowledgeUpdateSettings & settings =
693 
701  int
702  read_file (
703  const std::string & key,
704  const std::string & filename,
705  const KnowledgeUpdateSettings & settings =
707 
715  int
716  read_file (
717  const VariableReference & variable,
718  const std::string & filename,
719  const KnowledgeUpdateSettings & settings =
721 
732  int set_if_unequal (const std::string & key,
734  uint32_t quality, uint64_t clock,
735  const KnowledgeUpdateSettings & settings =
737 
748  int set_if_unequal (const std::string & key,
749  double value,
750  uint32_t quality, uint64_t clock,
751  const KnowledgeUpdateSettings & settings =
753 
764  int set_if_unequal (const std::string & key,
765  const std::string & value,
766  uint32_t quality, uint64_t clock,
767  const KnowledgeUpdateSettings & settings =
769 
780  int update_record_from_external (
781  const std::string & key, const knowledge::KnowledgeRecord & rhs,
782  const KnowledgeUpdateSettings & settings =
783  KnowledgeUpdateSettings (true));
784 
795  int update_record_from_external (
796  const VariableReference & target,
797  const knowledge::KnowledgeRecord & new_value,
798  const KnowledgeUpdateSettings & settings =
799  KnowledgeUpdateSettings (true));
800 
807  uint32_t get_quality (const std::string & key,
808  const KnowledgeReferenceSettings & settings =
810 
817  uint32_t get_write_quality (const std::string & key,
818  const KnowledgeReferenceSettings & settings =
820 
829  uint32_t set_quality (const std::string & key,
830  uint32_t quality, bool force_update,
831  const KnowledgeReferenceSettings & settings);
832 
836  void set_changed (void);
837 
844  void set_write_quality (const std::string & key, uint32_t quality,
845  const KnowledgeReferenceSettings & settings);
846 
852  const knowledge::KnowledgeRecords & get_modifieds (void) const;
853 
858  void add_modifieds (const VariableReferences & modifieds) const;
859 
868  VariableReferences save_modifieds (void) const;
869 
875  std::string debug_modifieds (void) const;
876 
882  const knowledge::KnowledgeRecords & get_local_modified (void) const;
883 
888  void reset_modified (void);
889 
894  void reset_checkpoint (void) const;
895 
899  void apply_modified (void);
900 
907  void mark_modified (const VariableReference & variable,
908  const KnowledgeUpdateSettings & settings = KnowledgeUpdateSettings());
909 
916  void mark_modified (const std::string & key,
917  const KnowledgeUpdateSettings & settings = KnowledgeUpdateSettings ());
918 
925  void mark_to_send (const VariableReference & variable,
926  const KnowledgeUpdateSettings & settings = KnowledgeUpdateSettings());
927 
934  void mark_to_send (const std::string & key,
935  const KnowledgeUpdateSettings & settings = KnowledgeUpdateSettings ());
936 
943  void mark_to_checkpoint (const VariableReference & variable,
944  const KnowledgeUpdateSettings & settings = KnowledgeUpdateSettings());
945 
952  void mark_to_checkpoint (const std::string & key,
953  const KnowledgeUpdateSettings & settings = KnowledgeUpdateSettings ());
954 
959  void reset_modified (const std::string & key);
960 
968  const KnowledgeUpdateSettings & settings =
970 
978  const KnowledgeUpdateSettings & settings =
980 
985  void wait_for_change (bool extra_release = false);
986 
994  const KnowledgeUpdateSettings & settings =
996 
1004  const KnowledgeUpdateSettings & settings =
1006 
1016  bool clear (const std::string & key,
1017  const KnowledgeReferenceSettings & settings =
1019 
1034  bool delete_variable (const std::string & key,
1035  const KnowledgeReferenceSettings & settings =
1037 
1043  void delete_prefix (const std::string & prefix,
1044  const KnowledgeReferenceSettings & settings =
1046 
1052  bool delete_expression (const std::string & expression);
1053 
1060  bool exists (const std::string & key,
1061  const KnowledgeReferenceSettings & settings =
1062  KnowledgeReferenceSettings ()) const;
1063 
1071  bool exists (const VariableReference & variable,
1072  const KnowledgeReferenceSettings & settings =
1073  KnowledgeReferenceSettings (false)) const;
1074 
1079  void print (unsigned int level) const;
1080 
1087  void print (const std::string & statement, unsigned int level) const;
1088 
1094  void clear (bool erase = false);
1095 
1100  void lock (void) const;
1101 
1105  void unlock (void) const;
1106 
1113  uint64_t inc_clock (const KnowledgeUpdateSettings & settings =
1115 
1123  uint64_t inc_clock (const std::string & key,
1124  const KnowledgeUpdateSettings & settings =
1126 
1132  uint64_t set_clock (uint64_t clock);
1133 
1142  uint64_t set_clock (const std::string & key,
1143  uint64_t clock,
1144  const KnowledgeReferenceSettings & settings =
1146 
1151  uint64_t get_clock (void) const;
1152 
1159  uint64_t get_clock (
1160  const std::string & key,
1161  const KnowledgeReferenceSettings & settings =
1162  KnowledgeReferenceSettings ()) const;
1163 
1168  void signal (bool lock = true) const;
1169 
1177  std::string expand_statement (const std::string & statement) const;
1178 
1188  void copy (const ThreadSafeContext & source,
1189  const KnowledgeRequirements & settings);
1190 
1191 
1211  void copy (const ThreadSafeContext & source,
1212  const CopySet & copy_set = CopySet (),
1213  bool clean_copy = false);
1214 
1215 
1216 #ifndef _MADARA_NO_KARL_
1217 
1225  compile (const std::string & expression);
1226 
1233  void define_function (const std::string & name,
1235  const KnowledgeReferenceSettings & settings =
1237 
1245  void define_function (const std::string & name,
1246  knowledge::KnowledgeRecord (*func) (const char *, FunctionArguments &, Variables &),
1247  const KnowledgeReferenceSettings & settings =
1249 
1250 #ifdef _MADARA_JAVA_
1251 
1257  void define_function (const std::string & name, jobject callable,
1258  const KnowledgeReferenceSettings & settings =
1260 #endif
1261 
1262 #ifdef _MADARA_PYTHON_CALLBACKS_
1263 
1269  void define_function (const std::string & name, boost::python::object callable,
1270  const KnowledgeReferenceSettings & settings =
1272 #endif
1273 
1280  void define_function (const std::string & name,
1281  const std::string & expression,
1282  const KnowledgeReferenceSettings & settings =
1284 
1291  void define_function (const std::string & name,
1292  const CompiledExpression & expression,
1293  const KnowledgeReferenceSettings & settings =
1295 
1302  Function * retrieve_function (const std::string & name,
1303  const KnowledgeReferenceSettings & settings =
1305 
1314  knowledge::KnowledgeRecord evaluate (CompiledExpression expression,
1315  const KnowledgeUpdateSettings & settings =
1317 
1326  knowledge::KnowledgeRecord evaluate (
1328  const KnowledgeUpdateSettings & settings =
1330 
1331 #endif // _MADARA_NO_KARL_
1332 
1355  void to_string (std::string & target,
1356  const std::string & array_delimiter = ",",
1357  const std::string & record_delimiter = ";\n",
1358  const std::string & key_val_delimiter = "=") const;
1359 
1360 
1375  size_t to_vector (const std::string & subject,
1376  unsigned int start,
1377  unsigned int end,
1378  std::vector <KnowledgeRecord> & target);
1379 
1387  void get_matches (
1388  const std::string & prefix,
1389  const std::string & suffix,
1390  VariableReferences & matches);
1391 
1402  size_t to_map (const std::string & subject,
1403  std::map <std::string, knowledge::KnowledgeRecord> & target);
1404 
1409  void add_logger (const std::string & filename);
1410 
1415  int get_log_level (void);
1416 
1421  void set_log_level (int level);
1422 
1427  logger::Logger & get_logger (void) const;
1428 
1433  void attach_logger (logger::Logger & logger) const;
1434 
1451  size_t to_map (const std::string & prefix,
1452  const std::string & delimiter,
1453  const std::string & suffix,
1454  std::vector <std::string> & next_keys,
1455  std::map <std::string, knowledge::KnowledgeRecord> & result,
1456  bool just_keys);
1457 
1466  knowledge::KnowledgeMap to_map (const std::string &prefix) const;
1467 
1479  knowledge::KnowledgeMap to_map_stripped (const std::string &prefix) const;
1480 
1481 
1490  int64_t save_context (const std::string & filename,
1491  const std::string & id = "") const;
1492 
1500  int64_t save_context (const CheckpointSettings & settings) const;
1501 
1507  int64_t save_as_json (const std::string & filename) const;
1508 
1514  int64_t save_as_json (const CheckpointSettings & settings) const;
1515 
1521  int64_t save_as_karl (const std::string & filename) const;
1522 
1528  int64_t save_as_karl (const CheckpointSettings & settings) const;
1529 
1540  int64_t load_context (const std::string & filename,
1541  std::string & id,
1542  const KnowledgeUpdateSettings & settings =
1543  KnowledgeUpdateSettings (true, true, true, false));
1544 
1555  int64_t load_context (const std::string & filename,
1556  FileHeader & meta,
1557  const KnowledgeUpdateSettings & settings =
1558  KnowledgeUpdateSettings (true, true, true, false));
1559 
1568  int64_t load_context (CheckpointSettings & checkpoint_settings,
1569  const KnowledgeUpdateSettings & update_settings =
1570  KnowledgeUpdateSettings (true, true, true, false));
1571 
1581  int64_t save_checkpoint (const std::string & filename,
1582  const std::string & id = "") const;
1583 
1593  int64_t save_checkpoint (
1594  const CheckpointSettings & settings) const;
1595 
1607  KnowledgeMap &get_map_unsafe (void) { return map_; }
1608 
1621  const KnowledgeMap &get_map_unsafe (void) const { return map_; }
1622 
1623  protected:
1624  private:
1633  void mark_to_send_unsafe (const std::string & key,
1635  const KnowledgeUpdateSettings & settings = KnowledgeUpdateSettings ());
1636 
1644  void mark_to_checkpoint_unsafe (const std::string & key,
1646  const KnowledgeUpdateSettings & settings = KnowledgeUpdateSettings ());
1647 
1654  void mark_and_signal (const char * name,
1655  knowledge::KnowledgeRecord * record,
1656  const KnowledgeUpdateSettings & settings = KnowledgeUpdateSettings());
1657 
1658  template<typename... Args>
1659  int set_unsafe_impl (const VariableReference & variable,
1660  const KnowledgeUpdateSettings & settings,
1661  Args&&... args);
1662 
1663  template<typename T>
1664  int set_index_unsafe_impl (const VariableReference & variable,
1665  size_t index, T&& value,
1666  const KnowledgeUpdateSettings & settings =
1668 
1669  std::pair<KnowledgeMap::const_iterator, KnowledgeMap::const_iterator>
1670  get_prefix_range(const std::string &prefix) const;
1671 
1672  std::pair<KnowledgeMap::iterator, KnowledgeMap::iterator>
1673  get_prefix_range(const std::string &prefix);
1674 
1677  mutable MADARA_LOCK_TYPE mutex_;
1678  mutable MADARA_CONDITION_TYPE changed_;
1679  std::vector< std::string> expansion_splitters_;
1680  mutable uint64_t clock_;
1683 
1686 
1689 
1692  };
1693  }
1694 }
1695 
1696 #include "ThreadSafeContext.inl"
1697 
1698 #endif
This class encapsulates an entry in a KnowledgeBase.
std::map< std::string, bool > CopySet
Typedef for set of copyable keys.
This class provides a distributed knowledge base implementation.
madara::knowledge::KnowledgeMap map_
Hash table containing variable names and values.
Defines a file header which is the default for KaRL checkpointing.
Definition: FileHeader.h:35
std::shared_ptr< std::vector< double > > share_doubles() const
Returns a shared_ptr, sharing with the internal one.
std::shared_ptr< T >(KnowledgeRecord::*)(void) MethodType
std::shared_ptr< std::vector< unsigned char > > share_binary() const
Returns a shared_ptr, sharing with the internal one.
Defines a terminal node of that references the current value stored in a variable.
Definition: VariableNode.h:28
std::vector< std::string > expansion_splitters_
This class stores a function definition.
Definition: Functions.h:44
std::shared_ptr< std::vector< double > > share_doubles(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
std::shared_ptr< std::vector< Integer > > share_integers() const
Returns a shared_ptr, sharing with the internal one.
MADARA_Export int read_file(const std::string &filename, void *&buffer, size_t &size, bool add_zero_char=false)
Reads a file into a provided void pointer.
Definition: Utility.cpp:747
Base type for Trackers.
Definition: BaseTracker.h:62
std::shared_ptr< std::vector< unsigned char > > share_binary(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
This class stores variables and their values for use by any entity needing state information in a thr...
std::shared_ptr< std::vector< double > > take_doubles(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
Holds settings for checkpoints to load or save.
std::shared_ptr< T >(KnowledgeRecord::*)(void) const ConstMethodType
Provides knowledge logging services to files and terminals.
Definition: GlobalLogger.h:11
Optimized reference to a variable within the knowledge base.
Compiled, optimized KaRL logic.
std::vector< KnowledgeRecord > FunctionArguments
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > take_integers(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
A multi-threaded logger for logging to one or more destinations.
Definition: Logger.h:88
std::shared_ptr< std::string > take_string(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, while resetting this record to empty.
std::shared_ptr< std::vector< double > > take_doubles()
Returns a shared_ptr, while resetting this record to empty.
std::shared_ptr< std::string > take_string(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, while resetting this record to empty.
std::shared_ptr< std::vector< double > > take_doubles(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
KnowledgeMap & get_map_unsafe(void)
NOT THREAD SAFE!
std::shared_ptr< T > get_shared(K &&key, const KnowledgeReferenceSettings &settings)
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > take_integers(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > share_integers(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
FunctionMap functions_
map of function names to functions
Holds settings requirements for knowledge, usually in copying.
void set_log_level(int level)
Sets the log level.
Definition: LogMacros.h:205
Parses incoming expression strings into a parse tree and generates an expression tree from the parse ...
Definition: Interpreter.h:42
::std::map< std::string, KnowledgeRecord * > KnowledgeRecords
std::shared_ptr< std::vector< unsigned char > > take_binary()
Returns a shared_ptr, while resetting this record to empty.
::std::map< std::string, KnowledgeRecord > KnowledgeMap
std::shared_ptr< std::vector< KnowledgeRecord::Integer > > share_integers(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
An abstract base class defines a simple abstract implementation of an expression tree node...
Definition: ComponentNode.h:35
knowledge::KnowledgeRecords local_changed_map_
std::shared_ptr< std::vector< Integer > > take_integers()
Returns a shared_ptr, while resetting this record to empty.
std::shared_ptr< std::string > share_string(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
static constexpr struct madara::knowledge::tags::string_t string
int get_log_level(void)
Gets the log level.
Definition: LogMacros.h:214
std::vector< VariableReference > VariableReferences
a vector of variable references
std::map< std::string, Function > FunctionMap
Definition: FunctionMap.h:17
MADARA_Export bool exists(const char *originator, uint64_t clock, uint32_t update_number, OriginatorFragmentMap &map)
Checks if a fragment already exists within a fragment map.
knowledge::KnowledgeRecords changed_map_
logger::Logger * logger_
Logger for printing.
std::shared_ptr< std::vector< unsigned char > > take_binary(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
Provides functions and classes for the distributed knowledge base.
std::shared_ptr< T > get_shared(K &&key, const KnowledgeReferenceSettings &settings) const
std::shared_ptr< std::vector< unsigned char > > share_binary(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
Settings for applying knowledge updates.
Copyright (c) 2015 Carnegie Mellon University.
std::shared_ptr< std::string > share_string(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.
std::shared_ptr< std::vector< unsigned char > > take_binary(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Returns a shared_ptr, sharing with the internal one.
Settings for applying knowledge updates.
const KnowledgeMap & get_map_unsafe(void) const
NOT THREAD SAFE!
Provides an interface for external functions into the MADARA KaRL variable settings.
madara::expression::Interpreter * interpreter_
KaRL interpreter.
std::vector< std::string > PrefixVector
Typedef for vector of prefixes to use for a generic task.
Defines a terminal node of that references the current value stored in a variable.
std::shared_ptr< std::vector< double > > share_doubles(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Returns a shared_ptr, sharing with the internal one.