GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-java.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2007-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_ov_java_h)
27 #define octave_ov_java_h 1
28 
29 #include "octave-config.h"
30 
31 #include "ov.h"
32 #include "ovl.h"
33 
34 namespace octave
35 {
36  class type_info;
37 }
38 
39 typedef void *voidptr;
40 
41 class OCTINTERP_API octave_java : public octave_base_value
42 {
43 public:
44 
45  octave_java (void);
46 
47  octave_java (const voidptr& obj, void *cls = nullptr);
48 
49  octave_java (const octave_java& jobj)
50  : octave_base_value (jobj), java_object (nullptr), java_class (nullptr)
51  {
52  init (jobj.java_object, jobj.java_class);
53  }
54 
55  ~octave_java (void) { release (); }
56 
57  void * to_java (void) const { return java_object; }
58  void * to_class (void) const { return java_class; }
59 
60  std::string java_class_name (void) const { return java_classname; }
61 
62  octave_base_value * clone (void) const { return new octave_java (*this); }
63  octave_base_value * empty_clone (void) const { return new octave_java (); }
64 
65  bool is_instance_of (const std::string&) const;
66 
67  bool is_defined (void) const { return true; }
68 
69  bool is_constant (void) const { return true; }
70 
71  bool isstruct (void) const { return false; }
72 
73  bool isjava (void) const { return true; }
74 
75  string_vector map_keys (void) const;
76 
77  dim_vector dims (void) const;
78 
79  void print (std::ostream& os, bool pr_as_read_syntax = false);
80 
81  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
82 
83  bool save_ascii (std::ostream& os);
84 
85  bool load_ascii (std::istream& is);
86 
87  bool save_binary (std::ostream& os, bool save_as_floats);
88 
89  bool load_binary (std::istream& is, bool swap,
91 
92  bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
93  bool save_as_floats);
94 
95  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
96 
97  // We don't need to override all three forms of subsref. The using
98  // declaration will avoid warnings about partially-overloaded virtual
99  // functions.
101 
103  subsref (const std::string& type,
104  const std::list<octave_value_list>& idx, int nargout);
105 
107  subsref (const std::string& type, const std::list<octave_value_list>& idx)
108  {
109  octave_value_list retval = subsref (type, idx, 1);
110  return (retval.length () > 0 ? retval(0) : octave_value ());
111  }
112 
113  octave_value subsasgn (const std::string& type,
114  const std::list<octave_value_list>& idx,
115  const octave_value& rhs);
116 
117  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
118 
119  bool is_java_string (void) const;
120 
121  octave_value do_javaMethod (void *jni_env, const std::string& name,
122  const octave_value_list& args);
123 
125  do_javaMethod (const std::string& name, const octave_value_list& args);
126 
127  static octave_value
128  do_javaMethod (void *jni_env, const std::string& class_name,
129  const std::string& name, const octave_value_list& args);
130 
131  static octave_value
132  do_javaMethod (const std::string& class_name, const std::string& name,
133  const octave_value_list& args);
134 
135  static octave_value
136  do_javaObject (void *jni_env, const std::string& name,
137  const octave_value_list& args);
138 
139  static octave_value
140  do_javaObject (const std::string& name, const octave_value_list& args);
141 
142  octave_value do_java_get (void *jni_env, const std::string& name);
143 
144  octave_value do_java_get (const std::string& name);
145 
146  static octave_value
147  do_java_get (void *jni_env, const std::string& class_name,
148  const std::string& name);
149 
150  static octave_value
151  do_java_get (const std::string& class_name, const std::string& name);
152 
153  octave_value do_java_set (void *jni_env, const std::string& name,
154  const octave_value& val);
155 
156  octave_value do_java_set (const std::string& name, const octave_value& val);
157 
158  static octave_value
159  do_java_set (void *jni_env, const std::string& class_name,
160  const std::string& name, const octave_value& val);
161 
162  static octave_value
163  do_java_set (const std::string& class_name, const std::string& name,
164  const octave_value& val);
165 
166 private:
167 
168  void init (void *jobj, void *jcls);
169 
170  void release (void);
171 
172 private:
173 
174  void *java_object;
175 
176  void *java_class;
177 
178  std::string java_classname;
179 
180 public:
181 
182  int type_id (void) const { return t_id; }
183  std::string type_name (void) const { return t_name; }
184  std::string class_name (void) const { return java_classname; }
185 
186  static int static_type_id (void) { return t_id; }
187  static std::string static_type_name (void) { return t_name; }
188  static std::string static_class_name (void) { return "<unknown>"; }
190 
191 private:
192 
193  static int t_id;
194  static const std::string t_name;
195 };
196 
197 extern OCTINTERP_API bool Vjava_matrix_autoconversion;
198 
199 extern OCTINTERP_API bool Vjava_unsigned_autoconversion;
200 
201 extern OCTINTERP_API bool Vdebug_java;
202 
203 #endif
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-base.cc:201
static const std::string t_name
Definition: ov-base.h:874
void release(void)
Definition: ov-base.h:824
virtual bool is_instance_of(const std::string &) const
Definition: ov-base.h:618
static int t_id
Definition: ov-base.h:874
static const std::string t_name
Definition: ov-java.h:194
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
static int t_id
Definition: ov-java.h:193
static octave_value do_java_set(void *jni_env, const std::string &class_name, const std::string &name, const octave_value &val)
static octave_value do_java_set(const std::string &class_name, const std::string &name, const octave_value &val)
octave_value do_java_set(void *jni_env, const std::string &name, const octave_value &val)
static octave_value do_javaObject(const std::string &name, const octave_value_list &args)
int type_id(void) const
Definition: ov-java.h:182
static octave_value do_java_get(void *jni_env, const std::string &class_name, const std::string &name)
static void register_type(octave::type_info &)
void * java_class
Definition: ov-java.h:176
void print(std::ostream &os, bool pr_as_read_syntax=false)
std::string java_class_name(void) const
Definition: ov-java.h:60
bool is_constant(void) const
Definition: ov-java.h:69
void release(void)
bool save_ascii(std::ostream &os)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
bool save_binary(std::ostream &os, bool save_as_floats)
bool is_defined(void) const
Definition: ov-java.h:67
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-java.h:107
octave_java(void)
static octave_value do_java_get(const std::string &class_name, const std::string &name)
void * java_object
Definition: ov-java.h:174
void * to_java(void) const
Definition: ov-java.h:57
octave_java(const voidptr &obj, void *cls=nullptr)
octave_value do_javaMethod(const std::string &name, const octave_value_list &args)
octave_value do_javaMethod(void *jni_env, const std::string &name, const octave_value_list &args)
void * to_class(void) const
Definition: ov-java.h:58
octave_value convert_to_str_internal(bool pad, bool force, char type) const
octave_value do_java_get(void *jni_env, const std::string &name)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
octave_base_value * empty_clone(void) const
Definition: ov-java.h:63
std::string java_classname
Definition: ov-java.h:178
octave_base_value * clone(void) const
Definition: ov-java.h:62
static std::string static_class_name(void)
Definition: ov-java.h:188
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
void init(void *jobj, void *jcls)
bool isjava(void) const
Definition: ov-java.h:73
std::string type_name(void) const
Definition: ov-java.h:183
octave_java(const octave_java &jobj)
Definition: ov-java.h:49
bool isstruct(void) const
Definition: ov-java.h:71
static octave_value do_javaMethod(const std::string &class_name, const std::string &name, const octave_value_list &args)
static octave_value do_javaObject(void *jni_env, const std::string &name, const octave_value_list &args)
std::string class_name(void) const
Definition: ov-java.h:184
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout)
~octave_java(void)
Definition: ov-java.h:55
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
dim_vector dims(void) const
bool load_ascii(std::istream &is)
octave_value do_java_get(const std::string &name)
static std::string static_type_name(void)
Definition: ov-java.h:187
static octave_value do_javaMethod(void *jni_env, const std::string &class_name, const std::string &name, const octave_value_list &args)
octave_value do_java_set(const std::string &name, const octave_value &val)
static int static_type_id(void)
Definition: ov-java.h:186
string_vector map_keys(void) const
QString name
int64_t octave_hdf5_id
OCTINTERP_API bool Vjava_matrix_autoconversion
Definition: ov-java.cc:221
OCTINTERP_API bool Vjava_unsigned_autoconversion
Definition: ov-java.cc:222
void * voidptr
Definition: ov-java.h:39
OCTINTERP_API bool Vdebug_java
Definition: ov-java.cc:223
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811