MADARA  3.2.3
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/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;
44 
46 
52  class MADARA_EXPORT Variables
53  {
54  public:
57 
62  : context_ (0)
63  {
64  }
65 
69  Variables (const Variables & rhs)
70  : context_ (rhs.context_)
71  {
72  }
73 
77  void operator= (Variables & rhs);
78 
85  ThreadSafeContext * get_context (void);
86 
93  knowledge::KnowledgeRecord get (const std::string & key,
94  const KnowledgeReferenceSettings & settings =
96 
103  knowledge::KnowledgeRecord get (const VariableReference & variable,
104  const KnowledgeReferenceSettings & settings =
106 
113  VariableReference get_ref (const std::string & key,
114  const KnowledgeReferenceSettings & settings =
116 
124  int set (const std::string & key,
126  const KnowledgeUpdateSettings & settings =
128  false, true, false, false));
129 
137  int set (const VariableReference & variable,
139  const KnowledgeUpdateSettings & settings =
141  false, true, false, false));
142 
151  int set (const std::string & key,
153  uint32_t size,
154  const KnowledgeUpdateSettings & settings =
156  false, true, false, false));
157 
166  int set (const VariableReference & variable,
168  uint32_t size,
169  const KnowledgeUpdateSettings & settings =
171  false, true, false, false));
172 
180  int set (const std::string & key,
181  const std::vector <KnowledgeRecord::Integer> & value,
182  const KnowledgeUpdateSettings & settings =
184  false, true, false, false));
185 
193  int set (const VariableReference & variable,
194  const std::vector <KnowledgeRecord::Integer> & value,
195  const KnowledgeUpdateSettings & settings =
197  false, true, false, false));
198 
206  int set (const std::string & key, double value,
207  const KnowledgeUpdateSettings & settings =
209  false, true, false, false));
210 
218  int set (const VariableReference & variable, double value,
219  const KnowledgeUpdateSettings & settings =
221  false, true, false, false));
222 
231  int set (const std::string & key,
232  const double * value,
233  uint32_t size,
234  const KnowledgeUpdateSettings & settings =
236  false, true, false, false));
237 
246  int set (const VariableReference & variable,
247  const double * value,
248  uint32_t size,
249  const KnowledgeUpdateSettings & settings =
251  false, true, false, false));
252 
260  int set (const std::string & key,
261  const std::vector <double> & value,
262  const KnowledgeUpdateSettings & settings =
264  false, true, false, false));
265 
273  int set (const VariableReference & variable,
274  const std::vector <double> & value,
275  const KnowledgeUpdateSettings & settings =
277  false, true, false, false));
278 
286  int set (const std::string & key, const std::string & value,
287  const KnowledgeUpdateSettings & settings =
289  false, true, false, false));
290 
298  int set (const VariableReference & variable, const std::string & value,
299  const KnowledgeUpdateSettings & settings =
301  false, true, false, false));
302 
310  int set (const std::string & key,
312  const KnowledgeUpdateSettings & settings =
314  false, true, false, false));
315 
323  int set (const VariableReference & variable,
325  const KnowledgeUpdateSettings & settings =
327  false, true, false, false));
328 
335  knowledge::KnowledgeRecord inc (const std::string & key,
336  const KnowledgeUpdateSettings & settings =
338  false, true, false, false));
339 
346  knowledge::KnowledgeRecord inc (const VariableReference & variable,
347  const KnowledgeUpdateSettings & settings =
349  false, true, false, false));
350 
357  knowledge::KnowledgeRecord dec (const std::string & key,
358  const KnowledgeUpdateSettings & settings =
360  false, true, false, false));
361 
368  knowledge::KnowledgeRecord dec (const VariableReference & variable,
369  const KnowledgeUpdateSettings & settings =
371  false, true, false, false));
372 
395  void to_string (std::string & target,
396  const std::string & array_delimiter = ",",
397  const std::string & record_delimiter = ";\n",
398  const std::string & key_val_delimiter = "=") const;
399 
404  void print (unsigned int level = 0) const;
405 
412  void print (const std::string & statement, unsigned int level = 0) const;
413 
421  madara::knowledge::KnowledgeRecord retrieve_index (
422  const std::string & key,
423  size_t index,
424  const KnowledgeReferenceSettings & settings =
426 
434  madara::knowledge::KnowledgeRecord retrieve_index (
435  const VariableReference & variable,
436  size_t index,
437  const KnowledgeReferenceSettings & settings =
439 
447  std::string expand_statement (const std::string & statement) const;
448 
453  void apply_modified (
454  const KnowledgeUpdateSettings & settings =
456 
464  bool exists (const std::string & key,
465  const KnowledgeReferenceSettings & settings =
466  KnowledgeReferenceSettings (false)) const;
467 
475  bool exists (const VariableReference & variable,
476  const KnowledgeReferenceSettings & settings =
477  KnowledgeReferenceSettings (false)) const;
478 
479 #ifndef _MADARA_NO_KARL_
480 
496  compile (const std::string & expression);
497 
514  const std::string & expression,
515  const KnowledgeUpdateSettings & settings =
517 
530  CompiledExpression & expression,
531  const KnowledgeUpdateSettings & settings =
533 
539  void define_function (const std::string & name,
541 
548  void define_function (const std::string & name,
549  knowledge::KnowledgeRecord (*func) (const char *, FunctionArguments &, Variables &));
550 
551 #ifdef _MADARA_JAVA_
552 
557  void define_function (const std::string & name, jobject callable);
558 #endif
559 
560 #ifdef _MADARA_PYTHON_CALLBACKS_
561 
566  void define_function (const std::string & name, boost::python::object callable);
567 #endif
568 
574  void define_function (const std::string & name,
575  const std::string & expression);
576 
582  void define_function (const std::string & name,
583  const CompiledExpression & expression);
584 
585 #endif // _MADARA_NO_KARL_
586 
601  size_t to_vector (const std::string & subject,
602  unsigned int start,
603  unsigned int end,
604  std::vector <KnowledgeRecord> & target);
605 
613  void get_matches (
614  const std::string & prefix,
615  const std::string & suffix,
616  VariableReferences & matches);
617 
628  size_t to_map (const std::string & subject,
629  std::map <std::string, knowledge::KnowledgeRecord> & target);
630 
636  int64_t save_as_karl (const std::string & filename) const;
637 
643  int64_t save_context (const std::string & filename);
644 
652  int64_t save_checkpoint (const std::string & filename,
653  bool reset_modifieds = true);
654 
661  int64_t load_context (const std::string & filename,
662  const KnowledgeUpdateSettings & settings =
663  KnowledgeUpdateSettings (true, true, true, false));
664 
671  ssize_t write_file (const std::string & knowledge_key,
672  const std::string & filename);
673 
674  private:
679  };
680  }
681 }
682 
683 #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
static struct madara::knowledge::tags::string_t string
ThreadSafeContext * context_
Variables context that is directly used by the KaRL engine.
madara::knowledge::KnowledgeRecord VALUE_TYPE
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.
ssize_t write_file(const std::string &filename, void *buffer, size_t size)
Writes a file with provided contents.
Definition: Utility.cpp:547