MADARA  3.4.1
ThreadSafeContext.h
Go to the documentation of this file.
1 #ifndef MADARA_THREADSAFECONTEXT_H
2 #define MADARA_THREADSAFECONTEXT_H
3 
12 #include "madara/logger/Logger.h"
13 
14 #include <string>
15 #include <map>
16 #include <memory>
17 #include <fstream>
19 
20 #include "madara/MadaraExport.h"
21 #include "madara/LockType.h"
32 
33 #ifdef _MADARA_JAVA_
34 #include "madara_jni.h"
35 #endif
36 
37 #ifdef _MADARA_PYTHON_CALLBACKS_
38 #include "madara/Boost.h"
39 #include "boost/python/object.hpp"
40 #endif
41 
42 namespace madara
43 {
44 namespace expression
45 {
46 class Interpreter;
47 class CompositeArrayReference;
48 class VariableNode;
49 }
50 
51 namespace knowledge
52 {
53 
60 typedef std::map<std::string, bool> CopySet;
61 
65 typedef std::vector<std::string> PrefixVector;
66 
68 class KnowledgeBaseImpl;
69 
75 class MADARA_EXPORT ThreadSafeContext
76 {
77 public:
78  friend class KnowledgeBaseImpl;
81 
86 
90  ~ThreadSafeContext(void);
91 
100  const std::string& key, const KnowledgeReferenceSettings& settings =
102 
111  const KnowledgeReferenceSettings& settings =
113 
123  const std::string& key, const KnowledgeReferenceSettings& settings =
125 
135  const VariableReference& variable,
136  const KnowledgeReferenceSettings& settings =
138 
139 private:
147  const std::string& key, const KnowledgeReferenceSettings& settings =
149 
157  const KnowledgeReferenceSettings& settings =
167  const std::string& key, const KnowledgeReferenceSettings& settings =
169 
178  const VariableReference& variable,
179  const KnowledgeReferenceSettings& settings =
181 
182  template<typename T>
183  using MethodType = std::shared_ptr<T> (KnowledgeRecord::*)(void);
184 
185  template<typename T, MethodType<T> Get, typename K>
186  std::shared_ptr<T> get_shared(
187  K&& key, const KnowledgeReferenceSettings& settings)
188  {
189  auto rec = with(std::forward<K>(key), settings);
190  if (rec)
191  {
192  return (rec->*Get)();
193  }
194  return nullptr;
195  }
196 
197  template<typename T>
198  using ConstMethodType = std::shared_ptr<T> (KnowledgeRecord::*)(void) const;
199 
200  template<typename T, ConstMethodType<T> Get, typename K>
201  std::shared_ptr<T> get_shared(
202  K&& key, const KnowledgeReferenceSettings& settings) const
203  {
204  auto rec = with(std::forward<K>(key), settings);
205  if (rec)
206  {
207  return (rec->*Get)();
208  }
209  return nullptr;
210  }
211 
212 public:
217  std::shared_ptr<const std::string> share_string(
218  const std::string& key, const KnowledgeReferenceSettings& settings =
220  {
221  return get_shared<const std::string, &KnowledgeRecord::share_string>(
222  key, settings);
223  }
224 
229  std::shared_ptr<const std::string> share_string(
230  const VariableReference& key, const KnowledgeReferenceSettings& settings =
232  {
233  return get_shared<const std::string, &KnowledgeRecord::share_string>(
234  key, settings);
235  }
236 
241  std::shared_ptr<const std::vector<KnowledgeRecord::Integer>> share_integers(
242  const std::string& key, const KnowledgeReferenceSettings& settings =
244  {
245  return get_shared<const std::vector<KnowledgeRecord::Integer>,
246  &KnowledgeRecord::share_integers>(key, settings);
247  }
248 
253  std::shared_ptr<const std::vector<KnowledgeRecord::Integer>> share_integers(
254  const VariableReference& key, const KnowledgeReferenceSettings& settings =
256  {
257  return get_shared<const std::vector<KnowledgeRecord::Integer>,
258  &KnowledgeRecord::share_integers>(key, settings);
259  }
260 
265  std::shared_ptr<const std::vector<double>> share_doubles(
266  const std::string& key, const KnowledgeReferenceSettings& settings =
268  {
269  return get_shared<const std::vector<double>,
270  &KnowledgeRecord::share_doubles>(key, settings);
271  }
272 
277  std::shared_ptr<const std::vector<double>> share_doubles(
278  const VariableReference& key, const KnowledgeReferenceSettings& settings =
280  {
281  return get_shared<const std::vector<double>,
282  &KnowledgeRecord::share_doubles>(key, settings);
283  }
284 
289  std::shared_ptr<const std::vector<unsigned char>> share_binary(
290  const std::string& key, const KnowledgeReferenceSettings& settings =
292  {
293  return get_shared<const std::vector<unsigned char>,
294  &KnowledgeRecord::share_binary>(key, settings);
295  }
296 
301  std::shared_ptr<const std::vector<unsigned char>> share_binary(
302  const VariableReference& key, const KnowledgeReferenceSettings& settings =
304  {
305  return get_shared<const std::vector<unsigned char>,
306  &KnowledgeRecord::share_binary>(key, settings);
307  }
308 
317  VariableReference get_ref(
318  const std::string& key, const KnowledgeReferenceSettings& settings =
320 
328  VariableReference get_ref(
329  const std::string& key, const KnowledgeReferenceSettings& settings =
331 
339  KnowledgeRecord retrieve_index(const std::string& key, size_t index,
340  const KnowledgeReferenceSettings& settings =
342 
350  KnowledgeRecord retrieve_index(const VariableReference& variable,
351  size_t index,
352  const KnowledgeReferenceSettings& settings =
354 
364  KnowledgeRecord* get_record(
365  const std::string& key, const KnowledgeReferenceSettings& settings =
367 
376  int set_xml(const std::string& key, const char* value, size_t size,
378 
387  int set_xml(const VariableReference& variable, const char* value, size_t size,
389 
398  int set_jpeg(const std::string& key, const unsigned char* value, size_t size,
400 
409  int set_jpeg(const VariableReference& variable, const unsigned char* value,
410  size_t size,
412 
421  int set_file(const std::string& key, const unsigned char* value, size_t size,
423 
432  int set_file(const VariableReference& variable, const unsigned char* value,
433  size_t size,
435 
444  int set_text(const std::string& key, const char* value, size_t size,
446 
455  int set_text(const VariableReference& variable, const char* value,
456  size_t size,
458 
467  template<typename T>
468  int set_index(const std::string& key, size_t index, T&& value,
470 
479  template<typename T>
480  int set_index(const VariableReference& variable, size_t index, T&& value,
482 
492  template<typename T>
493  int set_index_unsafe(const VariableReference& variable, size_t index,
494  T&& value,
496 
505  template<typename T>
506  int set(const std::string& key, T&& value,
508 
516  template<typename T>
517  int set(const VariableReference& variable, T&& value,
519 
528  template<typename T>
529  int set(const std::string& key, const T* value, uint32_t size,
531 
540  template<typename T>
541  int set(const VariableReference& variable, const T* value, uint32_t size,
543 
553  template<typename T>
554  int set_unsafe(const VariableReference& variable, T&& value,
556 
567  template<typename T>
568  int set_unsafe(const VariableReference& variable, const T* array, size_t size,
570 
578  int read_file(const std::string& key, const std::string& filename,
580 
588  int read_file(const VariableReference& variable, const std::string& filename,
590 
601  int set_if_unequal(const std::string& key,
602  madara::knowledge::KnowledgeRecord::Integer value, uint32_t quality,
603  uint64_t clock,
605 
616  int set_if_unequal(const std::string& key, double value, uint32_t quality,
617  uint64_t clock,
619 
630  int set_if_unequal(const std::string& key, const std::string& value,
631  uint32_t quality, uint64_t clock,
633 
644  int update_record_from_external(const std::string& key,
645  const knowledge::KnowledgeRecord& rhs,
646  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings(true));
647 
658  int update_record_from_external(const VariableReference& target,
659  const knowledge::KnowledgeRecord& new_value,
660  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings(true));
661 
668  uint32_t get_quality(
669  const std::string& key, const KnowledgeReferenceSettings& settings =
671 
678  uint32_t get_write_quality(
679  const std::string& key, const KnowledgeReferenceSettings& settings =
681 
690  uint32_t set_quality(const std::string& key, uint32_t quality,
691  bool force_update, const KnowledgeReferenceSettings& settings);
692 
696  void set_changed(void);
697 
704  void set_write_quality(const std::string& key, uint32_t quality,
705  const KnowledgeReferenceSettings& settings);
706 
712  const VariableReferenceMap& get_modifieds(void) const;
713 
720  KnowledgeMap get_modifieds_current(
721  const std::map<std::string, bool> & send_list, bool reset = true);
722 
727  void add_modifieds(const VariableReferences& modifieds) const;
728 
737  VariableReferences save_modifieds(void) const;
738 
744  std::string debug_modifieds(void) const;
745 
751  const VariableReferenceMap& get_local_modified(void) const;
752 
757  void reset_modified(void);
758 
763  void reset_checkpoint(void) const;
764 
768  void apply_modified(void);
769 
776  void mark_modified(const VariableReference& variable,
778 
785  void mark_modified(const std::string& key,
787 
794  void mark_to_send(const VariableReference& variable,
796 
803  void mark_to_send(const std::string& key,
805 
812  void mark_to_checkpoint(const VariableReference& variable,
814 
821  void mark_to_checkpoint(const std::string& key,
823 
828  void reset_modified(const std::string& key);
829 
838 
847 
852  void wait_for_change(bool extra_release = false);
853 
862 
871 
881  bool clear(
882  const std::string& key, const KnowledgeReferenceSettings& settings =
884 
892  bool clear(const VariableReference& variable);
893 
908  bool delete_variable(
909  const std::string& key, const KnowledgeReferenceSettings& settings =
911 
928  bool delete_variable(
929  const VariableReference& var, const KnowledgeReferenceSettings& settings =
931 
947  void delete_variables(KnowledgeMap::iterator begin,
948  KnowledgeMap::iterator end,
949  const KnowledgeReferenceSettings& settings =
951 
957  void delete_prefix(
958  const std::string& prefix, const KnowledgeReferenceSettings& settings =
960 
966  bool delete_expression(const std::string& expression);
967 
974  bool exists(
975  const std::string& key, const KnowledgeReferenceSettings& settings =
977 
985  bool exists(const VariableReference& variable,
987  false)) const;
988 
993  void print(unsigned int level) const;
994 
1001  void print(const std::string& statement, unsigned int level) const;
1002 
1008  void clear(bool erase = false);
1009 
1016  void lock(void) const;
1017 
1025  bool try_lock(void) const;
1026 
1030  void unlock(void) const;
1031 
1038  uint64_t inc_clock(
1039  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings());
1040 
1048  uint64_t inc_clock(const std::string& key,
1049  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings());
1050 
1056  uint64_t set_clock(uint64_t clock);
1057 
1066  uint64_t set_clock(const std::string& key, uint64_t clock,
1067  const KnowledgeReferenceSettings& settings =
1069 
1074  uint64_t get_clock(void) const;
1075 
1082  uint64_t get_clock(
1083  const std::string& key, const KnowledgeReferenceSettings& settings =
1084  KnowledgeReferenceSettings()) const;
1085 
1090  void signal(bool lock = true) const;
1091 
1099  std::string expand_statement(const std::string& statement) const;
1100 
1111  void copy(const ThreadSafeContext& source, const KnowledgeRequirements& reqs,
1112  const KnowledgeUpdateSettings& settings);
1113 
1134  void copy(const ThreadSafeContext& source,
1135  const CopySet& copy_set = CopySet(), bool clean_copy = false,
1136  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings());
1137 
1138 #ifndef _MADARA_NO_KARL_
1139 
1147  CompiledExpression compile(const std::string& expression);
1148 
1155  void define_function(const std::string& name,
1157  const KnowledgeReferenceSettings& settings =
1159 
1167  void define_function(const std::string& name,
1169  const char*, FunctionArguments&, Variables&),
1170  const KnowledgeReferenceSettings& settings =
1172 
1173 #ifdef _MADARA_JAVA_
1180  void define_function(const std::string& name, jobject callable,
1181  const KnowledgeReferenceSettings& settings =
1183 #endif
1184 
1185 #ifdef _MADARA_PYTHON_CALLBACKS_
1192  void define_function(const std::string& name, boost::python::object callable,
1193  const KnowledgeReferenceSettings& settings =
1195 #endif
1196 
1203  void define_function(const std::string& name, const std::string& expression,
1204  const KnowledgeReferenceSettings& settings =
1206 
1213  void define_function(const std::string& name,
1214  const CompiledExpression& expression,
1215  const KnowledgeReferenceSettings& settings =
1217 
1224  Function* retrieve_function(
1225  const std::string& name, const KnowledgeReferenceSettings& settings =
1227 
1237  knowledge::KnowledgeRecord evaluate(CompiledExpression expression,
1238  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings());
1239 
1250  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings());
1251 
1252 #endif // _MADARA_NO_KARL_
1253 
1276  void to_string(std::string& target, const std::string& array_delimiter = ",",
1277  const std::string& record_delimiter = ";\n",
1278  const std::string& key_val_delimiter = "=") const;
1279 
1294  size_t to_vector(const std::string& subject, unsigned int start,
1295  unsigned int end, std::vector<KnowledgeRecord>& target);
1296 
1304  void get_matches(const std::string& prefix, const std::string& suffix,
1305  VariableReferences& matches);
1306 
1317  size_t to_map(const std::string& subject,
1318  std::map<std::string, knowledge::KnowledgeRecord>& target);
1319 
1324  void add_logger(const std::string& filename);
1325 
1330  int get_log_level(void);
1331 
1336  void set_log_level(int level);
1337 
1342  logger::Logger& get_logger(void) const;
1343 
1348  void attach_logger(logger::Logger& logger) const;
1349 
1366  size_t to_map(const std::string& prefix, const std::string& delimiter,
1367  const std::string& suffix, std::vector<std::string>& next_keys,
1368  std::map<std::string, knowledge::KnowledgeRecord>& result,
1369  bool just_keys);
1370 
1379  knowledge::KnowledgeMap to_map(const std::string& prefix) const;
1380 
1392  knowledge::KnowledgeMap to_map_stripped(const std::string& prefix) const;
1393 
1403  int64_t save_context(
1404  const std::string& filename, const std::string& id = "") const;
1405 
1414  int64_t save_context(const CheckpointSettings& settings) const;
1415 
1421  int64_t save_as_json(const std::string& filename) const;
1422 
1428  int64_t save_as_json(const CheckpointSettings& settings) const;
1429 
1435  int64_t save_as_karl(const std::string& filename) const;
1436 
1442  int64_t save_as_karl(const CheckpointSettings& settings) const;
1443 
1454  int64_t load_context(const std::string& filename, std::string& id,
1456  true, true, true, false));
1457 
1469  int64_t load_context(const std::string& filename, FileHeader& meta,
1471  true, true, true, false));
1472 
1482  int64_t load_context(CheckpointSettings& checkpoint_settings,
1483  const KnowledgeUpdateSettings& update_settings = KnowledgeUpdateSettings(
1484  true, true, true, false));
1485 
1493  KnowledgeRecord evaluate_file(CheckpointSettings& checkpoint_settings,
1494  const KnowledgeUpdateSettings& update_settings = KnowledgeUpdateSettings(
1495  true, true, true, false));
1496 
1502  std::string file_to_string(CheckpointSettings& checkpoint_settings);
1503 
1514  int64_t save_checkpoint(
1515  const std::string& filename, const std::string& id = "") const;
1516 
1526  int64_t save_checkpoint(const CheckpointSettings& settings) const;
1527 
1537  std::unique_ptr<BaseStreamer> attach_streamer(
1538  std::unique_ptr<BaseStreamer> streamer)
1539  {
1540  MADARA_GUARD_TYPE guard(mutex_);
1541 
1542  using std::swap;
1543  swap(streamer, streamer_);
1544 
1545  return streamer;
1546  }
1547 
1560  {
1561  return map_;
1562  }
1563 
1576  const KnowledgeMap& get_map_unsafe(void) const
1577  {
1578  return map_;
1579  }
1580 
1581  template<typename Callable>
1582  auto invoke(const std::string& key, Callable&& callable,
1584  -> decltype(utility::invoke_(
1585  std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
1586  {
1587  MADARA_GUARD_TYPE guard(mutex_);
1588  auto ref = get_ref(key, settings);
1589  return utility::invoke_(std::forward<Callable>(callable), *ref.get_record_unsafe());
1590  }
1591 
1592  template<typename Callable>
1593  auto invoke(const VariableReference& key, Callable&& callable,
1595  -> decltype(utility::invoke_(
1596  std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
1597  {
1598  MADARA_GUARD_TYPE guard(mutex_);
1599  (void)settings;
1600  return utility::invoke_(std::forward<Callable>(callable), *key.get_record_unsafe());
1601  }
1602 
1603  template<typename Callable>
1604  auto invoke(const std::string& key, Callable&& callable,
1606  const -> decltype(utility::invoke_(
1607  std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
1608  {
1609  MADARA_GUARD_TYPE guard(mutex_);
1610  const KnowledgeRecord* ptr = with(key, settings);
1611  if (ptr)
1612  {
1613  return utility::invoke_(std::forward<Callable>(callable), *ptr);
1614  }
1615  const KnowledgeRecord empty;
1616  return utility::invoke_(std::forward<Callable>(callable), empty);
1617  }
1618 
1619  template<typename Callable>
1620  auto invoke(const VariableReference& key, Callable&& callable,
1622  const -> decltype(utility::invoke_(
1623  std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
1624  {
1625  MADARA_GUARD_TYPE guard(mutex_);
1626  (void)settings;
1627  return utility::invoke_(std::forward<Callable>(callable),
1628  const_cast<const KnowledgeRecord&>(*key.get_record_unsafe()));
1629  }
1630 
1631  template<typename Callable>
1632  auto cinvoke(const std::string& key, Callable&& callable,
1634  const -> decltype(utility::invoke_(
1635  std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
1636  {
1637  return invoke(key, std::forward<Callable>(callable), settings);
1638  }
1639 
1640  template<typename Callable>
1641  auto cinvoke(const VariableReference& key, Callable&& callable,
1643  const -> decltype(utility::invoke_(
1644  std::forward<Callable>(callable), std::declval<KnowledgeRecord&>()))
1645  {
1646  return invoke(key, std::forward<Callable>(callable), settings);
1647  }
1648 
1658  template<typename Func>
1659  void for_each(Func&& func) const
1660  {
1661  MADARA_GUARD_TYPE guard(mutex_);
1662 
1663  std::for_each(map_.begin(), map_.end(), func);
1664  }
1665 
1666 protected:
1667 private:
1675  void mark_to_send_unsafe(VariableReference ref,
1676  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings());
1677 
1684  void mark_to_checkpoint_unsafe(VariableReference ref,
1685  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings());
1686 
1692  void mark_and_signal(VariableReference ref,
1693  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings());
1694 
1695  template<typename... Args>
1696  int set_unsafe_impl(const VariableReference& variable,
1697  const KnowledgeUpdateSettings& settings, Args&&... args);
1698 
1699  template<typename T>
1700  int set_index_unsafe_impl(const VariableReference& variable, size_t index,
1701  T&& value,
1702  const KnowledgeUpdateSettings& settings = KnowledgeUpdateSettings());
1703 
1704  std::pair<KnowledgeMap::const_iterator, KnowledgeMap::const_iterator>
1705  get_prefix_range(const std::string& prefix) const;
1706 
1707  std::pair<KnowledgeMap::iterator, KnowledgeMap::iterator> get_prefix_range(
1708  const std::string& prefix);
1709 
1712  mutable MADARA_LOCK_TYPE mutex_;
1713  mutable MADARA_CONDITION_TYPE changed_;
1714  std::vector<std::string> expansion_splitters_;
1715  mutable uint64_t clock_;
1718 
1721 
1724 
1727 
1729  std::unique_ptr<BaseStreamer> streamer_ = nullptr;
1730 };
1731 }
1732 }
1733 
1734 #include "ThreadSafeContext.inl"
1735 
1736 #endif
VariableReferenceMap map_
An abstract base class defines a simple abstract implementation of an expression tree node.
Definition: ComponentNode.h:37
Defines a terminal node of that references the current value stored in a variable.
Parses incoming expression strings into a parse tree and generates an expression tree from the parse ...
Definition: Interpreter.h:43
Defines a terminal node of that references the current value stored in a variable.
Definition: VariableNode.h:29
Holds settings for checkpoints to load or save.
Compiled, optimized KaRL logic.
Defines a file header which is the default for KaRL checkpointing.
Definition: FileHeader.h:37
This class stores a function definition.
Definition: Functions.h:46
This class provides a distributed knowledge base implementation.
This class encapsulates an entry in a KnowledgeBase.
std::shared_ptr< const std::vector< double > > share_doubles() const
std::shared_ptr< const std::vector< unsigned char > > share_binary() const
std::shared_ptr< const std::vector< Integer > > share_integers() const
Settings for applying knowledge updates.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
std::shared_ptr< const std::string > share_string(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
std::shared_ptr< T > get_shared(K &&key, const KnowledgeReferenceSettings &settings)
void for_each(Func &&func) const
Call given Callable on each element in this context.
std::shared_ptr< const std::string > share_string(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
auto invoke(const VariableReference &key, Callable &&callable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
std::shared_ptr< T > get_shared(K &&key, const KnowledgeReferenceSettings &settings) const
auto cinvoke(const VariableReference &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
madara::expression::Interpreter * interpreter_
KaRL interpreter.
std::shared_ptr< const std::vector< double > > share_doubles(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
logger::Logger * logger_
Logger for printing.
auto invoke(const std::string &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
std::shared_ptr< const std::vector< unsigned char > > share_binary(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
std::unique_ptr< BaseStreamer > attach_streamer(std::unique_ptr< BaseStreamer > streamer)
Attach a streaming provider object, inherited from BaseStreamer, such as CheckpointStreamer.
FunctionMap functions_
map of function names to functions
madara::knowledge::KnowledgeMap map_
Hash table containing variable names and values.
auto invoke(const VariableReference &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
std::shared_ptr< const std::vector< KnowledgeRecord::Integer > > share_integers(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
const KnowledgeMap & get_map_unsafe(void) const
NOT THREAD SAFE!
std::shared_ptr< T >(KnowledgeRecord::*)(void) const ConstMethodType
std::shared_ptr< const std::vector< unsigned char > > share_binary(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
auto cinvoke(const std::string &key, Callable &&callable, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
auto invoke(const std::string &key, Callable &&callable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings()) -> decltype(utility::invoke_(std::forward< Callable >(callable), std::declval< KnowledgeRecord & >()))
std::shared_ptr< const std::vector< KnowledgeRecord::Integer > > share_integers(const VariableReference &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
std::vector< std::string > expansion_splitters_
KnowledgeMap & get_map_unsafe(void)
NOT THREAD SAFE!
void define_function(const std::string &name, knowledge::KnowledgeRecord(*func)(const char *, FunctionArguments &, Variables &), const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Defines a named function that can distinguish the name it was called with in MADARA.
std::shared_ptr< T >(KnowledgeRecord::*)(void) MethodType
std::shared_ptr< const std::vector< double > > share_doubles(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Optimized reference to a variable within the knowledge base.
KnowledgeRecord * get_record_unsafe(void) const
Returns a pointer to the variable's KnowledgeRecord Do not use this pointer unless you've locked the ...
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
A multi-threaded logger for logging to one or more destinations.
Definition: Logger.h:165
constexpr string_t string
Provides functions and classes for the distributed knowledge base.
std::map< std::string, bool > CopySet
Typedef for set of copyable keys.
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
Definition: GetRecord.h:121
std::map< const char *, VariableReference, utility::ComparisonLessThan > VariableReferenceMap
a map of variable references
std::vector< std::string > PrefixVector
Typedef for vector of prefixes to use for a generic task.
std::map< std::string, Function > FunctionMap
Definition: FunctionMap.h:17
std::vector< KnowledgeRecord > FunctionArguments
::std::map< std::string, KnowledgeRecord > KnowledgeMap
std::vector< VariableReference > VariableReferences
a vector of variable references
Provides knowledge logging services to files and terminals.
Definition: GlobalLogger.h:12
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.
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:15
std::string file_to_string(const std::string &filename)
Reads a file into a string.
Definition: Utility.cpp:324
auto invoke_(Func func, Arg0 &&arg0) -> decltype(std::forward< Arg0 >(arg0).*func)
Definition: StlHelper.h:193
int read_file(const std::string &filename, void *&buffer, size_t &size, bool add_zero_char)
Reads a file into a provided void pointer.
Definition: Utility.cpp:418
Copyright(c) 2020 Galois.
Holds settings requirements for knowledge, usually in copying.