MADARA  3.1.8
ExternFunctionVariables.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/MADARA_export.h"
14 
15 #ifdef _MADARA_PYTHON_CALLBACKS_
16 #include "boost/python/object.hpp"
17 #endif
18 
19 #ifdef _MADARA_JAVA_
20  #include <jni.h>
21  #include "madara_jni.h"
22 #endif
23 
32 namespace madara
33 {
34  namespace expression
35  {
36  class CompositeFunctionNode;
37  }
38 
39  namespace knowledge
40  {
41  class ThreadSafeContext;
43 
45 
51  class MADARA_Export Variables
52  {
53  public:
56 
61  : context_ (0)
62  {
63  }
64 
68  Variables (const Variables & rhs)
69  : context_ (rhs.context_)
70  {
71  }
72 
76  void operator= (Variables & rhs);
77 
84  ThreadSafeContext * get_context (void);
85 
92  knowledge::KnowledgeRecord get (const std::string & key,
93  const KnowledgeReferenceSettings & settings =
95 
102  knowledge::KnowledgeRecord get (const VariableReference & variable,
103  const KnowledgeReferenceSettings & settings =
105 
112  VariableReference get_ref (const std::string & key,
113  const KnowledgeReferenceSettings & settings =
115 
123  int set (const std::string & key,
125  const KnowledgeUpdateSettings & settings =
127  false, true, false, false));
128 
136  int set (const VariableReference & variable,
138  const KnowledgeUpdateSettings & settings =
140  false, true, false, false));
141 
150  int set (const std::string & key,
152  uint32_t size,
153  const KnowledgeUpdateSettings & settings =
155  false, true, false, false));
156 
165  int set (const VariableReference & variable,
167  uint32_t size,
168  const KnowledgeUpdateSettings & settings =
170  false, true, false, false));
171 
179  int set (const std::string & key,
180  const std::vector <KnowledgeRecord::Integer> & value,
181  const KnowledgeUpdateSettings & settings =
183  false, true, false, false));
184 
192  int set (const VariableReference & variable,
193  const std::vector <KnowledgeRecord::Integer> & value,
194  const KnowledgeUpdateSettings & settings =
196  false, true, false, false));
197 
205  int set (const std::string & key, double value,
206  const KnowledgeUpdateSettings & settings =
208  false, true, false, false));
209 
217  int set (const VariableReference & variable, double value,
218  const KnowledgeUpdateSettings & settings =
220  false, true, false, false));
221 
230  int set (const std::string & key,
231  const double * value,
232  uint32_t size,
233  const KnowledgeUpdateSettings & settings =
235  false, true, false, false));
236 
245  int set (const VariableReference & variable,
246  const double * value,
247  uint32_t size,
248  const KnowledgeUpdateSettings & settings =
250  false, true, false, false));
251 
259  int set (const std::string & key,
260  const std::vector <double> & value,
261  const KnowledgeUpdateSettings & settings =
263  false, true, false, false));
264 
272  int set (const VariableReference & variable,
273  const std::vector <double> & value,
274  const KnowledgeUpdateSettings & settings =
276  false, true, false, false));
277 
285  int set (const std::string & key, const std::string & value,
286  const KnowledgeUpdateSettings & settings =
288  false, true, false, false));
289 
297  int set (const VariableReference & variable, const std::string & value,
298  const KnowledgeUpdateSettings & settings =
300  false, true, false, false));
301 
309  int set (const std::string & key,
311  const KnowledgeUpdateSettings & settings =
313  false, true, false, false));
314 
322  int set (const VariableReference & variable,
324  const KnowledgeUpdateSettings & settings =
326  false, true, false, false));
327 
334  knowledge::KnowledgeRecord inc (const std::string & key,
335  const KnowledgeUpdateSettings & settings =
337  false, true, false, false));
338 
345  knowledge::KnowledgeRecord inc (const VariableReference & variable,
346  const KnowledgeUpdateSettings & settings =
348  false, true, false, false));
349 
356  knowledge::KnowledgeRecord dec (const std::string & key,
357  const KnowledgeUpdateSettings & settings =
359  false, true, false, false));
360 
367  knowledge::KnowledgeRecord dec (const VariableReference & variable,
368  const KnowledgeUpdateSettings & settings =
370  false, true, false, false));
371 
394  void to_string (std::string & target,
395  const std::string & array_delimiter = ",",
396  const std::string & record_delimiter = ";\n",
397  const std::string & key_val_delimiter = "=") const;
398 
403  void print (unsigned int level = 0) const;
404 
411  void print (const std::string & statement, unsigned int level = 0) const;
412 
420  madara::knowledge::KnowledgeRecord retrieve_index (
421  const std::string & key,
422  size_t index,
423  const KnowledgeReferenceSettings & settings =
425 
433  madara::knowledge::KnowledgeRecord retrieve_index (
434  const VariableReference & variable,
435  size_t index,
436  const KnowledgeReferenceSettings & settings =
438 
446  std::string expand_statement (const std::string & statement) const;
447 
452  void apply_modified (
453  const KnowledgeUpdateSettings & settings =
455 
463  bool exists (const std::string & key,
464  const KnowledgeReferenceSettings & settings =
465  KnowledgeReferenceSettings (false)) const;
466 
474  bool exists (const VariableReference & variable,
475  const KnowledgeReferenceSettings & settings =
476  KnowledgeReferenceSettings (false)) const;
477 
478 #ifndef _MADARA_NO_KARL_
479 
494  compile (const std::string & expression);
495 
511  const std::string & expression,
512  const KnowledgeUpdateSettings & settings =
514 
526  CompiledExpression & expression,
527  const KnowledgeUpdateSettings & settings =
529 
535  void define_function (const std::string & name,
537 
544  void define_function (const std::string & name,
545  knowledge::KnowledgeRecord (*func) (const char *, FunctionArguments &, Variables &));
546 
547 #ifdef _MADARA_JAVA_
548 
553  void define_function (const std::string & name, jobject callable);
554 #endif
555 
556 #ifdef _MADARA_PYTHON_CALLBACKS_
557 
562  void define_function (const std::string & name, boost::python::object callable);
563 #endif
564 
570  void define_function (const std::string & name,
571  const std::string & expression);
572 
578  void define_function (const std::string & name,
579  const CompiledExpression & expression);
580 
581 #endif // _MADARA_NO_KARL_
582 
597  size_t to_vector (const std::string & subject,
598  unsigned int start,
599  unsigned int end,
600  std::vector <KnowledgeRecord> & target);
601 
609  void get_matches (
610  const std::string & prefix,
611  const std::string & suffix,
612  VariableReferences & matches);
613 
624  size_t to_map (const std::string & subject,
625  std::map <std::string, knowledge::KnowledgeRecord> & target);
626 
632  int64_t save_as_karl (const std::string & filename) const;
633 
639  int64_t save_context (const std::string & filename);
640 
648  int64_t save_checkpoint (const std::string & filename,
649  bool reset_modifieds = true);
650 
657  int64_t load_context (const std::string & filename,
658  const KnowledgeUpdateSettings & settings =
659  KnowledgeUpdateSettings (true, true, true, false));
660 
667  ssize_t write_file (const std::string & knowledge_key,
668  const std::string & filename);
669 
670  private:
675  };
676  }
677 }
678 
679 #endif
This class encapsulates an entry in a KnowledgeBase.
ThreadSafeContext * context_
Context used by this filter.
This class stores variables and their values for use by any entity needing state information in a thr...
A composite node that calls a function.
Optimized reference to a variable within the knowledge base.
Compiled, optimized KaRL logic.
Provides map of data types to a filter chain to apply to the data.
std::vector< KnowledgeRecord > FunctionArguments
MADARA_Export ssize_t write_file(const std::string &filename, void *buffer, size_t size)
Writes a file with provided contents.
Definition: Utility.cpp:779
ThreadSafeContext * context_
Variables context that is directly used by the KaRL engine.
madara::knowledge::KnowledgeRecord VALUE_TYPE
static constexpr struct madara::knowledge::tags::string_t string
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.
Provides functions and classes for the distributed knowledge base.
void operator=(const KnowledgeRecordFilters &rhs)
Assignment operator.
Settings for applying knowledge updates.
Copyright (c) 2015 Carnegie Mellon University.
Settings for applying knowledge updates.
Provides an interface for external functions into the MADARA KaRL variable settings.
Variables(const Variables &rhs)
Constructor.