reactive_function.h
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5  */
6 
7 #ifndef REACTIVE_FUNCTION_H
8 #define REACTIVE_FUNCTION_H
9 
11 #include <sol/sol.hpp>
12 
13 class TimeseriesRef;
14 class CreatedSeriesBase;
15 class CreatedSeriesTime;
16 class CreatedSeriesXY;
17 
18 namespace PJ
19 {
21 {
23 
24  std::pair<double, double> at(unsigned i) const;
25 
26  void set(unsigned index, double x, double y);
27 
28  double atTime(double t) const;
29 
30  unsigned size() const;
31 
32  void clear() const;
33 
35 };
36 
37 //-----------------------
38 
40 {
41  CreatedSeriesBase(PlotDataMapRef* data_map, const std::string& name, bool timeseries);
42 
43  std::pair<double, double> at(unsigned i) const;
44 
45  void clear();
46 
47  void push_back(double x, double y);
48 
49  unsigned size() const;
50 
52 };
53 
55 {
56  CreatedSeriesTime(PlotDataMapRef* data_map, const std::string& name);
57 };
58 
60 {
61  CreatedSeriesXY(PlotDataMapRef* data_map, const std::string& name);
62 };
63 
64 //-----------------------
65 
67 {
68 public:
69  ReactiveLuaFunction(PlotDataMapRef* data_map, QString lua_global, QString lua_function,
70  QString lua_library);
71 
72  const char* name() const override
73  {
74  return "ReactiveLuaFunction";
75  }
76 
77  int numInputs() const override
78  {
79  return -1;
80  }
81 
82  int numOutputs() const override
83  {
84  return -1;
85  }
86 
87  void reset() override;
88 
89  void setTimeTracker(double time_tracker_value);
90 
91  void calculate() override;
92 
93  const std::vector<std::string>& createdCurves() const
94  {
95  return _created_curves;
96  }
97 
98  bool xmlSaveState(QDomDocument& doc, QDomElement& parent_element) const override;
99 
100  bool xmlLoadState(const QDomElement& parent_element) override;
101 
102  QString getGlobalCode()
103  {
104  return QString::fromStdString(_global_code);
105  }
106 
107  QString getFunctionCode()
108  {
109  return QString::fromStdString(_function_code);
110  }
111 
112 protected:
113  void prepareLua();
114 
115  double _tracker_value = 0;
116  std::string _global_code;
117  std::string _function_code;
118  std::string _library_code;
119 
120  std::vector<std::string> _created_curves;
121 
124 
128 
129 private:
130  void init();
131 };
132 
133 } // namespace PJ
134 
135 #endif // REACTIVE_FUNCTION_H
PJ::ReactiveLuaFunction::xmlSaveState
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
Definition: reactive_function.cpp:89
PJ::TimeseriesBase
Definition: timeseries.h:16
PJ::ReactiveLuaFunction::_created_curves
std::vector< std::string > _created_curves
Definition: reactive_function.h:120
PJ::ReactiveLuaFunction::_function_code
std::string _function_code
Definition: reactive_function.h:117
PJ::ReactiveLuaFunction::reset
void reset() override
Definition: reactive_function.cpp:62
PJ::ReactiveLuaFunction::_library_code
std::string _library_code
Definition: reactive_function.h:118
PJ::ReactiveLuaFunction::_created_scatter
sol::usertype< CreatedSeriesXY > _created_scatter
Definition: reactive_function.h:127
PJ::ReactiveLuaFunction::_global_code
std::string _global_code
Definition: reactive_function.h:116
PJ::ReactiveLuaFunction::_lua_function
sol::protected_function _lua_function
Definition: reactive_function.h:123
PJ::TimeseriesRef::clear
void clear() const
Definition: reactive_function.cpp:198
PJ::CreatedSeriesBase::CreatedSeriesBase
CreatedSeriesBase(PlotDataMapRef *data_map, const std::string &name, bool timeseries)
Definition: reactive_function.cpp:203
PJ::CreatedSeriesTime::CreatedSeriesTime
CreatedSeriesTime(PlotDataMapRef *data_map, const std::string &name)
Definition: reactive_function.cpp:237
PJ::ReactiveLuaFunction::_lua_engine
sol::state _lua_engine
Definition: reactive_function.h:122
sol::basic_protected_function
Definition: forward.hpp:1159
PJ::CreatedSeriesTime
Definition: reactive_function.h:54
PJ::CreatedSeriesBase::at
std::pair< double, double > at(unsigned i) const
Definition: reactive_function.cpp:216
PJ::CreatedSeriesXY
Definition: reactive_function.h:59
PJ::ReactiveLuaFunction::init
void init()
Definition: reactive_function.cpp:14
PJ::ReactiveLuaFunction::_created_timeseries
sol::usertype< CreatedSeriesTime > _created_timeseries
Definition: reactive_function.h:126
mqtt_test_proto.x
x
Definition: mqtt_test_proto.py:34
PJ::ReactiveLuaFunction::name
const char * name() const override
Name of the plugin type, NOT the particular instance.
Definition: reactive_function.h:72
PJ::ReactiveLuaFunction::prepareLua
void prepareLua()
Definition: reactive_function.cpp:99
PJ::ReactiveLuaFunction
Definition: reactive_function.h:66
mqtt_test_proto.y
y
Definition: mqtt_test_proto.py:35
PJ::ReactiveLuaFunction::_timeseries_ref
sol::usertype< TimeseriesRef > _timeseries_ref
Definition: reactive_function.h:125
PJ::CreatedSeriesXY::CreatedSeriesXY
CreatedSeriesXY(PlotDataMapRef *data_map, const std::string &name)
Definition: reactive_function.cpp:242
PJ::ReactiveLuaFunction::calculate
void calculate() override
Definition: reactive_function.cpp:71
PJ::TimeseriesRef
Definition: reactive_function.h:20
transform_function.h
PJ::ReactiveLuaFunction::_tracker_value
double _tracker_value
Definition: reactive_function.h:115
PJ::CreatedSeriesBase::_plot_data
PJ::PlotDataXY * _plot_data
Definition: reactive_function.h:51
PJ::TimeseriesRef::TimeseriesRef
TimeseriesRef(PlotData *data)
Definition: reactive_function.cpp:171
PJ::ReactiveLuaFunction::numOutputs
int numOutputs() const override
Definition: reactive_function.h:82
PJ::TimeseriesRef::_plot_data
PJ::PlotData * _plot_data
Definition: reactive_function.h:34
sol.hpp
PJ::CreatedSeriesBase::size
unsigned size() const
Definition: reactive_function.cpp:232
PJ::ReactiveLuaFunction::setTimeTracker
void setTimeTracker(double time_tracker_value)
Definition: reactive_function.cpp:66
PJ::CreatedSeriesBase::push_back
void push_back(double x, double y)
Definition: reactive_function.cpp:227
PJ::TransformFunction
Generic interface for a multi input - multi output transformation function. Contrariwise to other plu...
Definition: transform_function.h:22
PJ::ReactiveLuaFunction::createdCurves
const std::vector< std::string > & createdCurves() const
Definition: reactive_function.h:93
PJ::ReactiveLuaFunction::ReactiveLuaFunction
ReactiveLuaFunction(PlotDataMapRef *data_map, QString lua_global, QString lua_function, QString lua_library)
Definition: reactive_function.cpp:52
PJ::CreatedSeriesBase::clear
void clear()
Definition: reactive_function.cpp:222
sol::basic_usertype
Definition: forward.hpp:1139
PJ::ReactiveLuaFunction::xmlLoadState
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
Definition: reactive_function.cpp:94
PJ
Definition: dataloader_base.h:16
mqtt_test.data
dictionary data
Definition: mqtt_test.py:22
PJ::ReactiveLuaFunction::getFunctionCode
QString getFunctionCode()
Definition: reactive_function.h:107
PJ::ReactiveLuaFunction::getGlobalCode
QString getGlobalCode()
Definition: reactive_function.h:102
PJ::PlotDataMapRef
Definition: plotdata.h:34
sol::state
Definition: sol.hpp:28238
PJ::TimeseriesRef::set
void set(unsigned index, double x, double y)
Definition: reactive_function.cpp:181
PJ::TimeseriesRef::at
std::pair< double, double > at(unsigned i) const
Definition: reactive_function.cpp:175
PJ::PlotDataBase
Definition: plotdatabase.h:122
PJ::CreatedSeriesBase
Definition: reactive_function.h:39
PJ::ReactiveLuaFunction::numInputs
int numInputs() const override
Definition: reactive_function.h:77
PJ::TimeseriesRef::size
unsigned size() const
Definition: reactive_function.cpp:193
PJ::TimeseriesRef::atTime
double atTime(double t) const
Definition: reactive_function.cpp:187


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46