MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
polyglot_object_bridge.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 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_NATIVE_WRAPPERS_POLYGLOT_OBJECT_BRIDGE_H_
27#define MYSQLSHDK_SCRIPTING_POLYGLOT_NATIVE_WRAPPERS_POLYGLOT_OBJECT_BRIDGE_H_
28
29#include <string>
30#include <vector>
31
33#include "utils/utils_json.h"
34
35namespace shcore {
36namespace polyglot {
37
39 public:
40 virtual ~Object_bridge() = default;
41
42 virtual std::string class_name() const = 0;
43
44 virtual std::string &append_descr(std::string &s_out, int indent = -1,
45 int quote_strings = 0) const;
46
47 virtual std::string &append_repr(std::string &s_out) const;
48
49 virtual void append_json(shcore::JSON_dumper &dumper) const;
50
51 //! Returns the list of members that this object has
52 virtual std::vector<std::string> get_members() const;
53
54 //! Verifies if the object has a member
55 virtual bool has_member(const std::string &prop) const;
56
57 //! Sets the value of a member
58 virtual void set_member(const std::string & /*prop*/, Value /*value*/) {}
59
60 //! Returns the value of a member
61 virtual bool is_indexed() const { return false; }
62
63 //! Returns the value of a member
64 virtual Value get_member(size_t /*index*/) const { return {}; }
65
66 //! Sets the value of a member
67 virtual void set_member(size_t /*index*/, Value /*value*/) {}
68
69 //! Returns the number of indexable members
70 virtual size_t length() const { return 0; }
71
72 //! Returns true if a method with the given name exists.
73 bool has_method(const std::string &name) const;
74
75 //! Returns the value of a member
76 virtual Value get_member(const std::string & /*prop*/) const { return {}; }
77
78 //! Calls the named method with the given args
79 virtual Value call(const std::string & /*name*/,
80 const Argument_list & /*args*/) {
81 return {};
82 }
83
84 private:
85 virtual const std::vector<std::string> *properties() const { return nullptr; }
86 virtual const std::vector<std::string> *methods() const { return nullptr; }
87};
88
89typedef std::shared_ptr<Object_bridge> Object_bridge_t;
90
91} // namespace polyglot
92} // namespace shcore
93
94#endif // MYSQLSHDK_SCRIPTING_POLYGLOT_NATIVE_WRAPPERS_POLYGLOT_OBJECT_BRIDGE_H_
Definition: utils_json.h:49
Definition: polyglot_object_bridge.h:38
virtual size_t length() const
Returns the number of indexable members.
Definition: polyglot_object_bridge.h:70
virtual const std::vector< std::string > * methods() const
Definition: polyglot_object_bridge.h:86
virtual Value call(const std::string &, const Argument_list &)
Calls the named method with the given args.
Definition: polyglot_object_bridge.h:79
virtual bool is_indexed() const
Returns the value of a member.
Definition: polyglot_object_bridge.h:61
bool has_method(const std::string &name) const
Returns true if a method with the given name exists.
Definition: polyglot_object_bridge.cc:55
virtual ~Object_bridge()=default
virtual void append_json(shcore::JSON_dumper &dumper) const
Definition: polyglot_object_bridge.cc:33
virtual std::vector< std::string > get_members() const
Returns the list of members that this object has.
Definition: polyglot_object_bridge.cc:63
virtual void set_member(const std::string &, Value)
Sets the value of a member.
Definition: polyglot_object_bridge.h:58
virtual Value get_member(const std::string &) const
Returns the value of a member.
Definition: polyglot_object_bridge.h:76
virtual const std::vector< std::string > * properties() const
Definition: polyglot_object_bridge.h:85
virtual std::string class_name() const =0
virtual std::string & append_repr(std::string &s_out) const
Definition: polyglot_object_bridge.cc:44
virtual void set_member(size_t, Value)
Sets the value of a member.
Definition: polyglot_object_bridge.h:67
virtual Value get_member(size_t) const
Returns the value of a member.
Definition: polyglot_object_bridge.h:64
virtual std::string & append_descr(std::string &s_out, int indent=-1, int quote_strings=0) const
Definition: polyglot_object_bridge.cc:39
virtual bool has_member(const std::string &prop) const
Verifies if the object has a member.
Definition: polyglot_object_bridge.cc:48
std::shared_ptr< Object_bridge > Object_bridge_t
Definition: polyglot_object_bridge.h:89
Definition: file_system_exceptions.h:34
std::vector< Value > Argument_list
Definition: jit_executor_value.h:429
Pointer to a function that may be implemented in any language.
Definition: jit_executor_value.h:130