Minsky
itemRS.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2019
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 ITEMRS_H
21 #define ITEMRS_H
22 #include "item.h"
23 #include "lasso.h"
24 #include "RESTProcess_base.h"
25 #include "signature.h"
26 #include "item.rcd"
27 
28 #include "group.h"
29 #include "group.rcd"
30 #include "lasso.h"
31 #include "lasso.rcd"
32 #include "noteBase.rcd"
33 #include "operation.h"
34 #include "operation.rcd"
35 #include "operationType.rcd"
36 #include "plot.h"
37 #include "plot.rcd"
38 #include "plot.xcd"
39 #include "port.rcd"
40 #include "wire.h"
41 #include "wire.rcd"
42 #include "units.rcd"
43 #include "nobble.h"
44 
46 
47 using namespace std;
48 
49 namespace classdesc
50 {
51  template <>
52  struct RESTProcessPtr<minsky::ItemPtr>: public RESTProcessBase
53  {
57  RESTProcessBase* RPItem() const
58  {
59  RESTProcess_t rp;
60  ptr->RESTProcess(rp,"");
61  auto i=rp.find("");
62  if (i!=rp.end())
63  return i->second.get();
64  return nullptr;
65  }
66 
67  RESTProcessPtr(minsky::ItemPtr& ptr): ptr(ptr) {}
68  json_pack_t process(const string& remainder, const json_pack_t& arguments) override
69  {
70  if (auto rp=RPItem())
71  return rp->process(remainder, arguments);
72  return {};
73  }
74  json_pack_t signature() const override
75  {
76  json_pack_t r;
77  if (ptr)
78  {
79  vector<classdesc::Signature> signature{{ptr->classType(),{}}, {ptr->classType(),{ptr->classType()}}};
80  r<<signature;
81  }
82  return r;
83  }
84  json_pack_t list() const override {
85  if (auto rp=RPItem())
86  return rp->list();
87  return json_pack_t(json5_parser::mArray());
88  }
89  json_pack_t type() const override {
90  if (auto rp=RPItem())
91  return rp->type();
92  return json_pack_t("void");}
93 
94  };
95 }
96 
97 namespace minsky
98 {
99  using classdesc::RESTProcess_t;
100  using classdesc::json_pack_t;
101  using std::string;
102 
103  template <class T, class B>
104  void ItemT<T,B>::RESTProcess(RESTProcess_t& rp, const string& d)
105  {
106  ::RESTProcess(rp,d,dynamic_cast<T&>(*this));
107  }
108 
109  template <class T, class B>
110  void ItemT<T,B>::RESTProcess(RESTProcess_t& rp, const string& d) const
111  {
112  ::RESTProcess(rp,d,dynamic_cast<const T&>(*this));
113  }
114 
115  template <class T, class B>
116  void ItemT<T,B>::json_pack(json_pack_t& j) const
117  {
118  ::json_pack(j,"",dynamic_cast<const T&>(*this));
119  }
120 
121 }
122 
123 #endif
RESTProcessPtr(minsky::ItemPtr &ptr)
Definition: itemRS.h:67
json_pack_t signature() const override
Definition: itemRS.h:74
STL namespace.
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
void RESTProcess(RESTProcess_t &t, const string &d, minsky::VariableValues &a)
Definition: minsky.cc:1811
json_pack_t list() const override
Definition: itemRS.h:84
json_pack_t type() const override
Definition: itemRS.h:89
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
RESTProcessBase * RPItem() const
returns the RESTProcess item corresponding to this, if it exists, null if it doesn&#39;t ownership not re...
Definition: itemRS.h:57
json_pack_t process(const string &remainder, const json_pack_t &arguments) override
Definition: itemRS.h:68