MADARA  3.4.1
Variables.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_EXTERNAL_FUNCTION_VARIABLES_H_
3 #define _MADARA_EXTERNAL_FUNCTION_VARIABLES_H_
4 
5 #include <string>
6 #include "madara/MadaraExport.h"
14 
15 #ifdef _MADARA_PYTHON_CALLBACKS_
16 #include "madara/Boost.h"
17 #include "boost/python/object.hpp"
18 #endif
19 
20 #ifdef _MADARA_JAVA_
21 #include <jni.h>
22 #include "madara_jni.h"
23 #endif
24 
33 namespace madara
34 {
35 namespace expression
36 {
37 class CompositeFunctionNode;
38 }
39 
40 namespace knowledge
41 {
42 class ThreadSafeContext;
43 class KnowledgeRecordFilters;
44 
46 
52 class MADARA_EXPORT Variables
53 {
54 public:
57 
61  Variables(ThreadSafeContext* new_context = 0) : context_(new_context) {}
62 
66  Variables(const Variables& rhs) : context_(rhs.context_) {}
67 
71  void operator=(Variables& rhs);
72 
79  ThreadSafeContext* get_context(void);
80 
88  const std::string& key, const KnowledgeReferenceSettings& settings =
90 
98  const KnowledgeReferenceSettings& settings =
100 
107  VariableReference get_ref(
108  const std::string& key, const KnowledgeReferenceSettings& settings =
110 
118  int set(const std::string& key,
120  const KnowledgeUpdateSettings& settings =
121  knowledge::KnowledgeUpdateSettings(false, true, false, false));
122 
130  int set(const VariableReference& variable,
132  const KnowledgeUpdateSettings& settings =
133  knowledge::KnowledgeUpdateSettings(false, true, false, false));
134 
143  int set(const std::string& key,
144  const madara::knowledge::KnowledgeRecord::Integer* value, uint32_t size,
145  const KnowledgeUpdateSettings& settings =
146  knowledge::KnowledgeUpdateSettings(false, true, false, false));
147 
156  int set(const VariableReference& variable,
157  const madara::knowledge::KnowledgeRecord::Integer* value, uint32_t size,
158  const KnowledgeUpdateSettings& settings =
159  knowledge::KnowledgeUpdateSettings(false, true, false, false));
160 
168  int set(const std::string& key,
169  const std::vector<KnowledgeRecord::Integer>& value,
170  const KnowledgeUpdateSettings& settings =
171  knowledge::KnowledgeUpdateSettings(false, true, false, false));
172 
180  int set(const VariableReference& variable,
181  const std::vector<KnowledgeRecord::Integer>& value,
182  const KnowledgeUpdateSettings& settings =
183  knowledge::KnowledgeUpdateSettings(false, true, false, false));
184 
192  int set(const std::string& key, double value,
193  const KnowledgeUpdateSettings& settings =
194  knowledge::KnowledgeUpdateSettings(false, true, false, false));
195 
203  int set(const VariableReference& variable, double value,
204  const KnowledgeUpdateSettings& settings =
205  knowledge::KnowledgeUpdateSettings(false, true, false, false));
206 
215  int set(const std::string& key, const double* value, uint32_t size,
216  const KnowledgeUpdateSettings& settings =
217  knowledge::KnowledgeUpdateSettings(false, true, false, false));
218 
227  int set(const VariableReference& variable, const double* value, uint32_t size,
228  const KnowledgeUpdateSettings& settings =
229  knowledge::KnowledgeUpdateSettings(false, true, false, false));
230 
238  int set(const std::string& key, const std::vector<double>& value,
239  const KnowledgeUpdateSettings& settings =
240  knowledge::KnowledgeUpdateSettings(false, true, false, false));
241 
249  int set(const VariableReference& variable, const std::vector<double>& value,
250  const KnowledgeUpdateSettings& settings =
251  knowledge::KnowledgeUpdateSettings(false, true, false, false));
252 
260  int set(const std::string& key, const std::string& value,
261  const KnowledgeUpdateSettings& settings =
262  knowledge::KnowledgeUpdateSettings(false, true, false, false));
263 
271  int set(const VariableReference& variable, const std::string& value,
272  const KnowledgeUpdateSettings& settings =
273  knowledge::KnowledgeUpdateSettings(false, true, false, false));
274 
282  int set(const std::string& key,
284  const KnowledgeUpdateSettings& settings =
285  knowledge::KnowledgeUpdateSettings(false, true, false, false));
286 
294  int set(const VariableReference& variable,
296  const KnowledgeUpdateSettings& settings =
297  knowledge::KnowledgeUpdateSettings(false, true, false, false));
298 
306  const KnowledgeUpdateSettings& settings =
307  knowledge::KnowledgeUpdateSettings(false, true, false, false));
308 
315  knowledge::KnowledgeRecord inc(const VariableReference& variable,
316  const KnowledgeUpdateSettings& settings =
317  knowledge::KnowledgeUpdateSettings(false, true, false, false));
318 
326  const KnowledgeUpdateSettings& settings =
327  knowledge::KnowledgeUpdateSettings(false, true, false, false));
328 
335  knowledge::KnowledgeRecord dec(const VariableReference& variable,
336  const KnowledgeUpdateSettings& settings =
337  knowledge::KnowledgeUpdateSettings(false, true, false, false));
338 
361  void to_string(std::string& target, const std::string& array_delimiter = ",",
362  const std::string& record_delimiter = ";\n",
363  const std::string& key_val_delimiter = "=") const;
364 
369  void print(unsigned int level = 0) const;
370 
377  void print(const std::string& statement, unsigned int level = 0) const;
378 
386  madara::knowledge::KnowledgeRecord retrieve_index(const std::string& key,
387  size_t index,
388  const KnowledgeReferenceSettings& settings =
390 
398  madara::knowledge::KnowledgeRecord retrieve_index(
399  const VariableReference& variable, size_t index,
400  const KnowledgeReferenceSettings& settings =
402 
410  std::string expand_statement(const std::string& statement) const;
411 
416  void apply_modified(const KnowledgeUpdateSettings& settings =
418 
426  bool exists(const std::string& key,
428  false)) const;
429 
437  bool exists(const VariableReference& variable,
439  false)) const;
440 
441 #ifndef _MADARA_NO_KARL_
442 
457  CompiledExpression compile(const std::string& expression);
458 
475  const std::string& expression, const KnowledgeUpdateSettings& settings =
477 
490  CompiledExpression& expression, const KnowledgeUpdateSettings& settings =
492 
498  void define_function(const std::string& name,
500 
508  const std::string& name, knowledge::KnowledgeRecord (*func)(const char*,
510 
511 #ifdef _MADARA_JAVA_
517  void define_function(const std::string& name, jobject callable);
518 #endif
519 
520 #ifdef _MADARA_PYTHON_CALLBACKS_
526  void define_function(const std::string& name, boost::python::object callable);
527 #endif
528 
534  void define_function(const std::string& name, const std::string& expression);
535 
541  void define_function(
542  const std::string& name, const CompiledExpression& expression);
543 
544 #endif // _MADARA_NO_KARL_
545 
560  size_t to_vector(const std::string& subject, unsigned int start,
561  unsigned int end, std::vector<KnowledgeRecord>& target);
562 
570  void get_matches(const std::string& prefix, const std::string& suffix,
571  VariableReferences& matches);
572 
583  size_t to_map(const std::string& subject,
584  std::map<std::string, knowledge::KnowledgeRecord>& target);
585 
591  int64_t save_as_karl(const std::string& filename) const;
592 
598  int64_t save_context(const std::string& filename);
599 
607  int64_t save_checkpoint(
608  const std::string& filename, bool reset_modifieds = true);
609 
616  int64_t load_context(const std::string& filename,
618  true, true, true, false));
619 
626  ssize_t write_file(
627  const std::string& knowledge_key, const std::string& filename);
628 
629 private:
634 };
635 }
636 }
637 
638 #endif
const ThreadSafeContext * context_
A composite node that calls a function.
Compiled, optimized KaRL logic.
Provides map of data types to a filter chain to apply to the data.
void operator=(const KnowledgeRecordFilters &rhs)
Assignment operator.
This class encapsulates an entry in a KnowledgeBase.
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...
Optimized reference to a variable within the knowledge base.
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
void define_function(const std::string &name, knowledge::KnowledgeRecord(*func)(const char *, FunctionArguments &, Variables &))
Defines a named function that can distinguish the name it was called with in MADARA.
Variables(ThreadSafeContext *new_context=0)
Constructor.
Definition: Variables.h:61
Variables(const Variables &rhs)
Constructor.
Definition: Variables.h:66
ThreadSafeContext * context_
Variables context that is directly used by the KaRL engine.
Definition: Variables.h:633
constexpr string_t string
Provides functions and classes for the distributed knowledge base.
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
Definition: GetRecord.h:121
madara::knowledge::KnowledgeRecord VALUE_TYPE
Definition: Functions.h:37
std::vector< KnowledgeRecord > FunctionArguments
std::vector< VariableReference > VariableReferences
a vector of variable references
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.
ssize_t write_file(const std::string &filename, void *buffer, size_t size)
Writes a file with provided contents.
Definition: Utility.cpp:487
Copyright(c) 2020 Galois.