Minsky
dataOp.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2021
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef DATAOP_H
21 #define DATAOP_H
22 
23 #include "operation.h"
24 
25 namespace minsky
26 {
28  class DataOp: public ItemT<DataOp, Operation<minsky::OperationType::data>>,
29  public NamedOp
30  {
32  friend struct SchemaHelper;
33  void updateBB() override {bb.update(*this);}
34  void draw(cairo_t* cairo) const override {
35  if (description().empty())
36  OperationBase::draw(cairo);
37  else
38  drawUserFunction(cairo);
39  }
40 
41  public:
42  ~DataOp() {}
43 
44  const DataOp& operator=(const DataOp& x);
45 
46  std::map<double, double> data;
47  void readData(const std::string& fileName);
49  void initRandom(double xmin, double xmax, unsigned numSamples);
51  double interpolate(double) const;
55  double deriv(double) const;
56  Units units(bool check) const override {return m_ports[1]->units(check);}
57 
58  void pack(classdesc::pack_t& x, const std::string& d) const override;
59  void unpack(classdesc::unpack_t& x, const std::string& d) override;
60  };
61 
62 }
63 
64 #include "dataOp.cd"
65 #include "dataOp.xcd"
66 #endif
void draw(cairo_t *) const override
draw this item into a cairo context
Definition: operation.cc:230
void readData(const std::string &fileName)
Definition: dataOp.cc:32
virtual float x() const
Definition: item.cc:107
void drawUserFunction(cairo_t *cairo) const
Definition: operation.cc:143
double interpolate(double) const
interpolates y data between x values bounding the argument
Definition: dataOp.cc:59
CLASSDESC_ACCESS(DataOp)
base class for operations that have names
Definition: operation.h:101
BoundingBox bb
canvas bounding box.
Definition: item.h:195
void update(const Item &x)
Definition: item.cc:46
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
void pack(classdesc::pack_t &x, const std::string &d) const override
Definition: dataOp.cc:96
void initRandom(double xmin, double xmax, unsigned numSamples)
initialise with uniform random numbers
Definition: dataOp.cc:51
represents the units (in sense of dimensional analysis) of a variable.
Definition: units.h:34
virtual std::string description() const
name of the associated data operation
Definition: operation.cc:573
void unpack(classdesc::unpack_t &x, const std::string &d) override
Definition: dataOp.cc:99
const DataOp & operator=(const DataOp &x)
ItemPortVector m_ports
Definition: item.h:156
void updateBB() override
Definition: dataOp.h:33
std::map< double, double > data
Definition: dataOp.h:46
Units units(bool check) const override
compute the dimensional units
Definition: dataOp.h:56
void draw(cairo_t *cairo) const override
draw this item into a cairo context
Definition: dataOp.h:34
legacy data importer object
Definition: dataOp.h:28
double deriv(double) const
derivative of the interpolate function. At the data points, the derivative is defined as the weighted...
Definition: dataOp.cc:80