MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
types_polyglot.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef MYSQLSHDK_SCRIPTING_POLYGLOT_POLYGLOT_WRAPPERS_TYPES_POLYGLOT_H_
27#define MYSQLSHDK_SCRIPTING_POLYGLOT_POLYGLOT_WRAPPERS_TYPES_POLYGLOT_H_
28
29#include <memory>
30
32
37
38#include "utils/utils_json.h"
39
40namespace shcore {
41namespace polyglot {
42
43class Polyglot_language;
44
45/**
46 * Utility class to allow wrapping a Polyglot object to be used from the C++.
47 */
49 public:
50 Polyglot_object() = delete;
51
52 Polyglot_object(const Polyglot_type_bridger *type_bridger, poly_thread thread,
53 poly_context context, poly_value object,
54 const std::string &class_name);
55
58
61
62 virtual ~Polyglot_object() = default;
63
64 std::string class_name() const;
65
66 void append_json(JSON_dumper &dumper) const;
67
68 std::vector<std::string> get_members() const;
69
70 Value get_member(const std::string &prop) const;
71 poly_value get_poly_member(const std::string &prop) const;
72 bool has_member(const std::string &prop) const;
73 void set_member(const std::string &prop, Value value);
74 void set_poly_member(const std::string &prop, poly_value value);
75
76 Value get_property(const std::string &prop) const;
77
78 void set_property(const std::string &prop, Value value);
79
80 Value call(const std::string &name, const std::vector<Value> &args);
81
82 poly_value get() const { return m_object.get(); }
83 bool remove_member(const std::string &name);
84
85 bool is_exception() const;
86 void throw_exception() const;
87
88 private:
90 poly_thread m_thread;
91 poly_context m_context;
93 std::string m_class_name;
94};
95
96/**
97 * Utility class to allow wrapping a Polyglot function to be used from C++.
98 */
100 public:
102
103 Polyglot_function(std::weak_ptr<Polyglot_language> language,
104 poly_value function);
105
108
111
113
114 const std::string &name() const { return m_name; }
115
116 Value invoke(const std::vector<Value> &args);
117
118 private:
119 std::weak_ptr<Polyglot_language> m_language;
120 poly_reference m_function;
121 std::string m_name;
122};
123
124} // namespace polyglot
125} // namespace shcore
126
127#endif // MYSQLSHDK_SCRIPTING_POLYGLOT_POLYGLOT_WRAPPERS_TYPES_POLYGLOT_H_
Definition: utils_json.h:49
Utility class to allow wrapping a Polyglot function to be used from C++.
Definition: types_polyglot.h:99
std::weak_ptr< Polyglot_language > m_language
Definition: types_polyglot.h:119
~Polyglot_function()
Definition: types_polyglot.cc:170
const std::string & name() const
Definition: types_polyglot.h:114
Polyglot_function operator=(const Polyglot_function &)=delete
Polyglot_function(const Polyglot_function &)=delete
std::string m_name
Definition: types_polyglot.h:121
Polyglot_function operator=(Polyglot_function &&)=delete
Polyglot_function(Polyglot_function &&)=delete
poly_reference m_function
Definition: types_polyglot.h:120
Value invoke(const std::vector< Value > &args)
Definition: types_polyglot.cc:177
Utility class to allow wrapping a Polyglot object to be used from the C++.
Definition: types_polyglot.h:48
std::string m_class_name
Definition: types_polyglot.h:93
Value get_property(const std::string &prop) const
poly_value get() const
Definition: types_polyglot.h:82
Polyglot_object(Polyglot_object &&)=delete
Value get_member(const std::string &prop) const
Definition: types_polyglot.cc:73
virtual ~Polyglot_object()=default
void throw_exception() const
Definition: types_polyglot.cc:148
void set_poly_member(const std::string &prop, poly_value value)
Definition: types_polyglot.cc:97
Store m_object
Definition: types_polyglot.h:92
Polyglot_object(const Polyglot_object &)=delete
std::vector< std::string > get_members() const
Definition: types_polyglot.cc:53
poly_thread m_thread
Definition: types_polyglot.h:90
const Polyglot_type_bridger * m_types
Definition: types_polyglot.h:89
Polyglot_object & operator=(Polyglot_object &&)=delete
poly_context m_context
Definition: types_polyglot.h:91
poly_value get_poly_member(const std::string &prop) const
Definition: types_polyglot.cc:77
Polyglot_object & operator=(const Polyglot_object &)=delete
bool is_exception() const
Definition: types_polyglot.cc:140
void set_property(const std::string &prop, Value value)
void set_member(const std::string &prop, Value value)
Definition: types_polyglot.cc:93
void append_json(JSON_dumper &dumper) const
Definition: types_polyglot.cc:47
std::string class_name() const
Definition: types_polyglot.cc:45
bool remove_member(const std::string &name)
Definition: types_polyglot.cc:131
bool has_member(const std::string &prop) const
Definition: types_polyglot.cc:85
Value call(const std::string &name, const std::vector< Value > &args)
Definition: types_polyglot.cc:103
Helper class to handle polyglot values made permanent.
Definition: polyglot_store.h:47
poly_reference get() const noexcept
Definition: polyglot_store.h:70
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Definition: file_system_exceptions.h:34
Pointer to a function that may be implemented in any language.
Definition: jit_executor_value.h:130
Definition: jit_executor_type_conversion.h:37