example_0505.cpp
См. документацию.
1 #include <pyhrol.h>
2 #include "myclass.h"
3 
4 using namespace std;
5 using namespace pyhrol;
6 
7 namespace disambiguate
8 {
9 
10 class MyClass2: public MyClass
11 {
12 public:
13  const string &message() const
14  {
15  return m_msg;
16  }
17 
18  void set_message(const string &msg)
19  {
20  m_msg = msg;
21  }
22 
23  MyClass2(const string &msg)
24  : MyClass(msg.c_str())
25  {
26  }
27 };
28 
29 } //disambiguate
30 
31 using namespace disambiguate;
32 
33 class PyType: public TypeSequence<MyClass2>, public TypeWrapper<MyClass2>
34 {
36  : TypeBase<MyClass2>("MyClass", "help")
37  {
38  m_add_method<PyType, &PyType::say>("say", NULL);
39  }
40 
41  void say(const Ptr<MyClass2> &obj, Tuples &_args) const
42  {
45 
46  obj->say();
47 
49  }
50 
51  virtual void constructor(MyClass2 &obj, Tuples &_args) const
52  {
53  const char *msg;
54  PYHROL_PARSE_TUPLE_1(NULL, _args, msg)
57 
58  new (&obj) MyClass2(msg);
59 
61  }
62 
63  virtual void destructor(MyClass2 &obj) const
64  {
65  obj.~MyClass2();
66  }
67 
68  virtual void concat(const Ptr<MyClass2> &res, Tuples &_args) const
69  {
70  const char *arg;
71  int64_t num;
73 
74  PYHROL_PARSE_TUPLE_1(NULL, _args, arg)
75  PYHROL_PARSE_TUPLE_2(NULL, _args, like_me.cls, like_me.pobj)
76  PYHROL_PARSE_TUPLE_1(NULL, _args, num)
79 
80  ostringstream ostr;
81  ostr << res->message();
82  switch (_args.parsed_variant())
83  {
84  case 0:
85  ostr << arg;
86  break;
87  case 1:
88  ostr << like_me->message();
89  break;
90  case 2:
91  ostr << num;
92  break;
93  }
94  res->set_message(ostr.str());
95 
97  }
98 
99  virtual void concat(const Ptr<MyClass2> &dst, const Ptr<const MyClass2> &left, Tuples &_args) const
100  {
101  const char *arg;
102  int64_t num;
104 
105  PYHROL_PARSE_TUPLE_1(NULL, _args, arg)
106  PYHROL_PARSE_TUPLE_2(NULL, _args, like_me.cls, like_me.pobj)
107  PYHROL_PARSE_TUPLE_1(NULL, _args, num)
110 
111  ostringstream ostr;
112  ostr << left->message();
113  switch (_args.parsed_variant())
114  {
115  case 0:
116  ostr << arg;
117  break;
118  case 1:
119  ostr << like_me->message();
120  break;
121  case 2:
122  ostr << num;
123  break;
124  }
125  new(&*dst) MyClass2(ostr.str());
126 
128  }
129 
130  virtual void assign(const Ptr<MyClass2> &dst, Tuples &_args, Py_ssize_t begin, Py_ssize_t end) const
131  {
132  const char *arg;
133  int64_t num;
135 
136  PYHROL_PARSE_TUPLE_1(NULL, _args, arg)
137  PYHROL_PARSE_TUPLE_2(NULL, _args, like_me.cls, like_me.pobj)
138  PYHROL_PARSE_TUPLE_1(NULL, _args, num)
141 
142  check_range(dst->message().length(), begin, end);
143 
144  ostringstream ostr;
145  switch (_args.parsed_variant())
146  {
147  case 0:
148  ostr << arg;
149  break;
150  case 1:
151  ostr << like_me->message();
152  break;
153  case 2:
154  ostr << num;
155  break;
156  }
157 
158  string res = dst->message().substr(0, begin);
159  res += ostr.str();
160  res += dst->message().substr(end);
161  dst->set_message(res);
162 
164  }
165 
166  virtual void contains(bool &res, const Ptr<const MyClass2> &src, Tuples &_args) const
167  {
168  const char *arg;
169  int64_t num;
171 
172  PYHROL_PARSE_TUPLE_1(NULL, _args, arg)
173  PYHROL_PARSE_TUPLE_2(NULL, _args, like_me.cls, like_me.pobj)
174  PYHROL_PARSE_TUPLE_1(NULL, _args, num)
177 
178  ostringstream ostr;
179  switch (_args.parsed_variant())
180  {
181  case 0:
182  ostr << arg;
183  break;
184  case 1:
185  ostr << like_me->message();
186  break;
187  case 2:
188  ostr << num;
189  break;
190  }
191 
192  res = src->message().find(ostr.str()) != string::npos;
193 
195  }
196 
197  static void init() __attribute__ ((constructor))
198  {
199  m_get(new PyType);
200  }
201 };
#define PYHROL_AFTER_BUILD_VALUE(container)
Definition: pyhrol_macro.h:18
virtual void constructor(MyClass2 &obj, Tuples &_args) const
#define PYHROL_AFTER_EXECUTE_DEFAULT(container)
Definition: pyhrol_macro.h:26
Definition: myclass.h:6
virtual void assign(const Ptr< MyClass2 > &dst, Tuples &_args, Py_ssize_t begin, Py_ssize_t end) const
#define PYHROL_AFTER_PARSE_TUPLE(container)
Definition: pyhrol_macro.h:9
MyClass2(const string &msg)
void say(const Ptr< MyClass2 > &obj, Tuples &_args) const
#define PYHROL_PARSE_TUPLE_2(description, container, arg1, arg2)
#define PYHROL_PARSE_TUPLE_1(description, container, arg1)
virtual void contains(bool &res, const Ptr< const MyClass2 > &src, Tuples &_args) const
virtual void destructor(MyClass2 &obj) const
virtual void concat(const Ptr< MyClass2 > &res, Tuples &_args) const
void set_message(const string &msg)
static void init() __attribute__((constructor))
virtual void concat(const Ptr< MyClass2 > &dst, const Ptr< const MyClass2 > &left, Tuples &_args) const
void check_range(size_t limit, Py_ssize_t begin, Py_ssize_t end)
const string & message() const
virtual const uint8_t parsed_variant() const =0
void say()
Definition: myclass.cpp:7