26 #if defined (HAVE_CONFIG_H)
87 error (
"parents must be objects");
92 error (
"duplicate class in parent tree");
142 Cell c (parent_dims);
146 std::list<std::string> plist
155 error (
"class: parent class dimension mismatch");
157 else if (nel == 1 && p_nel == 1)
174 else if (nel == p_nel)
190 std::list<std::string> plist
199 error (
"class: parent class dimension mismatch");
247 OCTAVE_NORETURN
static
251 error (
"invalid index for class");
254 OCTAVE_NORETURN
static
258 error (
"invalid index for class assignment");
261 OCTAVE_NORETURN
static
265 error (
"%s cannot be indexed with %c", nm.c_str (), t);
276 c(i).break_closure_cycles (frame);
293 error (
"malformed class");
297 std::string nm = idx(0).xstring_value (
"invalid index for class");
301 if (p == my_map.
end ())
302 error (
"class has no member '%s'", nm.c_str ());
313 Matrix retval (1, 2, 1.0);
329 retval = lv(0).matrix_value ();
335 int nd = dv.
ndims ();
339 for (
int i = 0; i < nd; i++)
371 error (
"@%s/numel: invalid return value", cn.c_str ());
373 retval = lv(0).idx_type_value (
true);
383 const std::list<octave_value_list>& idx,
400 if (type.length () > 1 && type[1] ==
'.')
402 auto p = idx.begin ();
409 retval(0) = (t.
numel () == 1 ? t(0)
446 retval = retval(0).next_subsref (nargout, type, idx, skip);
468 bool maybe_cs_list_query = (type[0] ==
'.' || type[0] ==
'{'
469 || (type.length () > 1 && type[0] ==
'('
472 int true_nargout = nargout;
474 if (maybe_cs_list_query)
478 if (type[0] !=
'.') tmp = idx.front ();
479 true_nargout =
xnumel (tmp);
492 if (type.length () == 1 && type[0] ==
'(')
508 if (val.
numel () != 1)
513 if (type.length () > 0 && type[0] ==
'.' && ! retval.
isstruct ())
521 const std::list<octave_value_list>& idx,
530 const std::list<octave_value_list>& idx,
542 const std::string& type,
543 const std::list<octave_value_list>& idx,
601 error (
"@%s/subsasgn returned more than one value",
621 error (
"malformed class");
635 int n = type.length ();
639 if (
n > 1 && ! (type.length () == 2 && type[0] ==
'(' && type[1] ==
'.'))
645 if (type.length () > 1 && type[1] ==
'.')
647 auto p = idx.begin ();
654 std::string key = key_idx(0).xstring_value (
"invalid index for class assignment");
664 Cell map_elt = map_val.
index (idx.front (),
true);
669 std::list<octave_value_list> next_idx (idx);
674 next_idx.erase (next_idx.begin ());
675 next_idx.erase (next_idx.begin ());
679 t_rhs = u.
subsasgn (type.substr (2), next_idx, rhs);
692 std::string key = key_idx(0).string_value ();
694 std::list<octave_value_list> next_idx (idx);
696 next_idx.erase (next_idx.begin ());
698 std::string next_type = type.substr (1);
709 if (tmpc.
numel () != 1)
723 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
740 if (
n > 1 && type[1] ==
'.')
742 auto p = idx.begin ();
747 std::string key = key_idx(0).xstring_value (
"assignment to class element failed");
768 error (
"invalid class assignment");
785 std::string key = key_idx(0).string_value ();
831 error (
"no subsindex method defined for class %s",
840 error (
"subsindex function must return a valid index vector");
855 std::size_t retval = 0;
883 retval = tmp(0).is_true ();
1007 error (
"cname/char method did not return a string");
1009 retval = tmp(0).string_vector_value (pad);
1035 bool retval =
false;
1046 octave::symbol_table& symtab = interp.get_symbol_table ();
1050 bool have_ctor =
false;
1067 octave::unwind_protect frame;
1073 bool execution_error =
false;
1081 catch (
const octave::execution_exception&)
1083 interp.recover_from_exception ();
1085 execution_error =
true;
1088 if (! execution_error && result.
length () == 1)
1115 bool might_have_inheritance =
false;
1116 std::string dbgstr =
"dork";
1128 might_have_inheritance =
true;
1135 if (might_have_inheritance)
1165 os <<
"# classname: " <<
class_name () <<
"\n";
1170 if (lp.find_method (
class_name (),
"saveobj") !=
"")
1175 m = tmp(0).map_value ();
1180 os <<
"# length: " <<
m.nfields () <<
"\n";
1182 auto i =
m.begin ();
1183 while (i !=
m.end ())
1190 return ! os.fail ();
1202 std::string classname;
1204 if (!
extract_keyword (is,
"classname", classname) || classname.empty ())
1205 error (
"load: failed to extract name of class");
1208 error (
"load: failed to extract number of elements in class");
1229 m.assign (nm, tcell);
1233 error (
"load: failed to load class");
1241 warning (
"load: unable to reconstruct object inheritance");
1245 if (lp.find_method (classname,
"loadobj") !=
"")
1250 m_map = tmp(0).map_value ();
1267 int32_t classname_len =
class_name ().length ();
1269 os.write (
reinterpret_cast<char *
> (&classname_len), 4);
1276 if (lp.find_method (
class_name (),
"saveobj") !=
"")
1281 m = tmp(0).map_value ();
1286 int32_t
len =
m.nfields ();
1287 os.write (
reinterpret_cast<char *
> (&
len), 4);
1289 auto i =
m.begin ();
1290 while (i !=
m.end ())
1297 return ! os.fail ();
1309 bool success =
true;
1311 int32_t classname_len;
1313 is.read (
reinterpret_cast<char *
> (&classname_len), 4);
1321 classname[classname_len] =
'\0';
1322 if (! is.read (
reinterpret_cast<char *
> (classname), classname_len))
1329 if (! is.read (
reinterpret_cast<char *
> (&
len), 4))
1354 m.assign (nm, tcell);
1362 warning (
"load: unable to reconstruct object inheritance");
1366 if (lp.find_method (
c_name,
"loadobj") !=
"")
1371 m_map = tmp(0).map_value ();
1376 warning (
"load: failed to load class");
1390 bool save_as_floats)
1392 #if defined (HAVE_HDF5)
1395 hid_t group_hid = -1;
1396 hid_t type_hid = -1;
1397 hid_t space_hid = -1;
1398 hid_t class_hid = -1;
1399 hid_t data_hid = -1;
1405 #if defined (HAVE_HDF5_18)
1409 group_hid = H5Gcreate (loc_id, name, 0);
1415 type_hid = H5Tcopy (H5T_C_S1); H5Tset_size (type_hid,
c_name.length () + 1);
1420 space_hid = H5Screate_simple (0, hdims,
nullptr);
1423 #if defined (HAVE_HDF5_18)
1424 class_hid = H5Dcreate (group_hid,
"classname", type_hid, space_hid,
1428 class_hid = H5Dcreate (group_hid,
"classname", type_hid, space_hid,
1431 if (class_hid < 0 || H5Dwrite (class_hid, type_hid,
octave_H5S_ALL,
1436 #if defined (HAVE_HDF5_18)
1440 data_hid = H5Gcreate (group_hid,
"value", 0);
1445 if (lp.find_method (
class_name (),
"saveobj") !=
"")
1450 m = tmp(0).map_value ();
1457 while (i !=
m.end ())
1461 bool retval2 =
add_hdf5_data (data_hid, val,
m.key (i),
"",
false,
1473 H5Gclose (data_hid);
1476 H5Dclose (class_hid);
1479 H5Sclose (space_hid);
1482 H5Tclose (type_hid);
1485 H5Gclose (group_hid);
1490 octave_unused_parameter (loc_id);
1491 octave_unused_parameter (name);
1492 octave_unused_parameter (save_as_floats);
1503 bool retval =
false;
1505 #if defined (HAVE_HDF5)
1507 hid_t group_hid = -1;
1508 hid_t data_hid = -1;
1509 hid_t type_hid = -1;
1510 hid_t type_class_hid = -1;
1511 hid_t space_hid = -1;
1512 hid_t subgroup_hid = -1;
1519 int current_item = 0;
1520 hsize_t num_obj = 0;
1524 #if defined (HAVE_HDF5_18)
1527 group_hid = H5Gopen (loc_id, name);
1532 #if defined (HAVE_HDF5_18)
1535 data_hid = H5Dopen (group_hid,
"classname");
1541 type_hid = H5Dget_type (data_hid);
1543 type_class_hid = H5Tget_class (type_hid);
1545 if (type_class_hid != H5T_STRING)
1548 space_hid = H5Dget_space (data_hid);
1549 rank = H5Sget_simple_extent_ndims (space_hid);
1554 slen = H5Tget_size (type_hid);
1564 st_id = H5Tcopy (H5T_C_S1);
1565 H5Tset_size (st_id, slen);
1572 H5Dclose (data_hid);
1573 H5Gclose (group_hid);
1578 H5Dclose (data_hid);
1586 #if defined (HAVE_HDF5_18)
1589 subgroup_hid = H5Gopen (group_hid, name);
1591 H5Gget_num_objs (subgroup_hid, &num_obj);
1592 H5Gclose (subgroup_hid);
1594 while (current_item <
static_cast<int> (num_obj)
1603 m.assign (dsub.
name, tcell);
1612 warning (
"load: unable to reconstruct object inheritance");
1616 if (lp.find_method (
c_name,
"loadobj") !=
"")
1621 m_map = tmp(0).map_value ();
1628 H5Dclose (data_hid);
1631 H5Gclose (group_hid);
1634 octave_unused_parameter (loc_id);
1635 octave_unused_parameter (name);
1665 : m_field_names (), m_parent_class_names ()
1668 error (
"invalid call to exemplar_info constructor");
1684 error (
"invalid comparison of class exemplar to non-class object");
1687 error (
"mismatch in number of fields");
1695 if (obj_fnames[i] != fnames[i])
1696 error (
"mismatch in field names");
1700 error (
"mismatch in number of parent classes");
1702 const std::list<std::string> obj_parents
1704 const std::list<std::string> pnames = parents ();
1706 auto p = obj_parents.begin ();
1707 auto q = pnames.begin ();
1709 while (p != obj_parents.end ())
1712 error (
"mismatch in parent classes");
1733 int nargin = args.length ();
1746 std::string
id = args(1).xstring_value (
"class: ID (class name) must be a string");
1753 error (
"class: invalid call from outside class constructor or method");
1756 error (
"class: '%s' is invalid as a class name in this context",
1759 octave_map m = args(0).xmap_value (
"class: S must be a valid structure");
1776 else if (! it->second.compare (retval))
1777 error (
"class: object of class '%s' does not match previously constructed objects",
1822 if (args.length () != 2)
1828 1).xcellstr_value (
"isa: CLASSNAME must be a string or cell array of strings");
1834 std::string cls = clsnames(idx);
1836 || (cls ==
"float" && obj.
isfloat ())
1837 || (cls ==
"integer" && obj.
isinteger ())
1838 || (cls ==
"numeric" && obj.
isnumeric ())
1840 matches(idx) =
true;
1843 return ovl (matches);
1906 DEFUN (__parent_classes__, args, ,
1912 if (args.length () != 1)
1930 if (args.length () != 1)
1939 static std::set<std::string> built_in_class_names;
1941 if (built_in_class_names.empty ())
1943 built_in_class_names.insert (
"double");
1944 built_in_class_names.insert (
"single");
1945 built_in_class_names.insert (
"cell");
1946 built_in_class_names.insert (
"struct");
1947 built_in_class_names.insert (
"logical");
1948 built_in_class_names.insert (
"char");
1949 built_in_class_names.insert (
"function handle");
1950 built_in_class_names.insert (
"int8");
1951 built_in_class_names.insert (
"uint8");
1952 built_in_class_names.insert (
"int16");
1953 built_in_class_names.insert (
"uint16");
1954 built_in_class_names.insert (
"int32");
1955 built_in_class_names.insert (
"uint32");
1956 built_in_class_names.insert (
"int64");
1957 built_in_class_names.insert (
"uint64");
1960 return built_in_class_names.find (cn) != built_in_class_names.end ();
1979 error (
"superiorto: invalid call from outside class constructor");
1981 for (
int i = 0; i < args.length (); i++)
1983 std::string inf_class = args(i).xstring_value (
"superiorto: CLASS_NAME must be a string");
1992 std::string sup_class = fcn->
name ();
1994 error (
"superiorto: opposite precedence already set for %s and %s",
1995 sup_class.c_str (), inf_class.c_str ());
2017 error (
"inferiorto: invalid call from outside class constructor");
2019 for (
int i = 0; i < args.length (); i++)
2021 std::string sup_class = args(i).xstring_value (
"inferiorto: CLASS_NAME must be a string");
2024 error (
"inferiorto: cannot give user-defined class lower "
2025 "precedence than built-in class");
2029 std::string inf_class = fcn->
name ();
2031 error (
"inferiorto: opposite precedence already set for %s and %s",
2032 inf_class.c_str (), sup_class.c_str ());
2080 return execute (tw, nargout, args);
2143 DEFUN (__inline_ctor__, args, ,
bool isvector(const dim_vector &dim)
void swap_bytes< 4 >(void *ptr)
OCTARRAY_OVERRIDABLE_FUNC_API void make_unique(void)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Cell reshape(const dim_vector &new_dims) const
Cell index(const octave_value_list &idx, bool resize_ok=false) const
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
Vector representing the dimensions (size) of an Array.
octave_idx_type ndims(void) const
Number of dimensions.
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
octave::refcount< octave_idx_type > count
virtual bool is_string(void) const
virtual octave_base_value * unique_parent_class(const std::string &)
virtual octave_map map_value(void) const
OCTINTERP_API void indent(std::ostream &os) const
OCTINTERP_API void newline(std::ostream &os) const
virtual Matrix size(void)
virtual bool is_matrix_type(void) const
OCTINTERP_API void warn_load(const char *type) const
virtual bool is_scalar_type(void) const
virtual octave_idx_type xnumel(const octave_value_list &)
virtual octave_base_value * find_parent_class(const std::string &)
virtual octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
static void register_type(void)
friend class octave_value
OCTINTERP_API void warn_save(const char *type) const
OCTINTERP_API bool compare(const octave_value &obj) const
string_vector m_field_names
std::list< std::string > m_parent_class_names
std::list< std::string > parents(void) const
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
OCTINTERP_API void print(std::ostream &os, bool pr_as_read_syntax=false)
std::string type_name(void) const
OCTINTERP_API string_vector map_keys(void) const
OCTINTERP_API octave_base_value * unique_parent_class(const std::string &)
OCTINTERP_API octave_base_value * unique_clone(void)
OCTINTERP_API octave_idx_type xnumel(const octave_value_list &)
OCTINTERP_API octave_base_value * find_parent_class(const std::string &)
OCTINTERP_API bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
OCTINTERP_API void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
OCTINTERP_API std::size_t byte_size(void) const
OCTINTERP_API Cell dotref(const octave_value_list &idx)
OCTINTERP_API octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
std::list< std::string > m_parent_list
OCTINTERP_API bool load_hdf5(octave_hdf5_id loc_id, const char *name)
static std::map< std::string, exemplar_info > exemplar_map
octave_idx_type numel(void) const
std::string class_name(void) const
octave_base_value * clone(void) const
OCTINTERP_API octave_value subsasgn_common(const octave_value &obj, const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
OCTINTERP_API mxArray * as_mxArray(bool interleaved) const
static const std::string t_name
octave_map map_value(void) const
OCTINTERP_API bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
OCTINTERP_API bool in_class_method(void)
OCTINTERP_API octave::idx_vector index_vector(bool require_integers=false) const
OCTINTERP_API bool save_ascii(std::ostream &os)
void break_closure_cycles(const std::shared_ptr< octave::stack_frame > &frame)
std::size_t nparents(void) const
OCTINTERP_API bool is_instance_of(const std::string &) const
OCTINTERP_API string_vector string_vector_value(bool pad) const
octave_idx_type nfields(void) const
dim_vector dims(void) const
OCTINTERP_API bool reconstruct_parents(void)
OCTINTERP_API bool load_ascii(std::istream &is)
OCTINTERP_API Matrix size(void)
OCTINTERP_API std::string get_current_method_class(void)
std::map< std::string, exemplar_info >::const_iterator exemplar_const_iterator
bool isobject(void) const
static OCTINTERP_API void clear_exemplar_map(void)
OCTINTERP_API bool is_true(void) const
OCTINTERP_API bool save_binary(std::ostream &os, bool save_as_floats)
OCTINTERP_API bool reconstruct_exemplar(void)
static OCTINTERP_API octave_value numeric_conv(const Cell &val, const std::string &type)
OCTINTERP_API octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
std::string dispatch_class(void) const
virtual bool is_anonymous_function_of_class(const std::string &="") const
bool is_class_method(const std::string &cname="") const
bool is_class_constructor(const std::string &cname="") const
bool is_private_function_of_class(const std::string &nm) const
std::string name(void) const
octave_value_list execute(tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
octave_inline_fcn(const octave_inline_fcn &ob)=delete
octave_inline_fcn(octave_inline *obj)
octave_value_list call(tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
octave_inline * m_inline_obj
~octave_inline_fcn(void)=default
octave_inline(const octave_inline &)=default
octave_inline(const octave_map &m)
octave_function * function_value(bool)
~octave_inline(void)=default
bool is_inline_function(void) const
octave_base_value * empty_clone(void) const
std::shared_ptr< octave_inline_fcn > m_fcn_obj
octave_base_value * clone(void) const
void resize(const dim_vector &dv, bool fill=false)
octave_idx_type nfields(void) const
const_iterator cend(void) const
octave_fields::const_iterator const_iterator
void delete_elements(const octave::idx_vector &i)
void setfield(const std::string &key, const Cell &val)
octave_idx_type numel(void) const
const_iterator seek(const std::string &k) const
bool contains(const std::string &name) const
void assign(const std::string &k, const Cell &val)
std::string key(const_iterator p) const
const_iterator end(void) const
string_vector keys(void) const
const_iterator cbegin(void) const
const Cell & contents(const_iterator p) const
dim_vector dims(void) const
octave_idx_type index(const_iterator p) const
bool subsasgn_optimization_ok(void)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
octave_idx_type length(void) const
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
bool is_function(void) const
OCTINTERP_API octave_function * function_value(bool silent=false) const
OCTINTERP_API octave_value_list list_value(void) const
bool is_instance_of(const std::string &cls_name) const
octave::idx_vector index_vector(bool require_integers=false) const
std::list< std::string > parent_class_name_list(void) const
OCTINTERP_API octave_map xmap_value(const char *fmt,...) const
static OCTINTERP_API octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
bool isnumeric(void) const
OCTINTERP_API Cell xcell_value(const char *fmt,...) const
octave_idx_type numel(void) const
bool is_cs_list(void) const
octave_base_value * internal_rep(void) const
OCTINTERP_API octave_value storable_value(void) const
bool is_defined(void) const
bool isinteger(void) const
std::string class_name(void) const
OCTINTERP_API octave_user_function * user_function_value(bool silent=false) const
bool isstruct(void) const
bool is_zero_by_zero(void) const
std::size_t byte_size(void) const
octave_idx_type nfields(void) const
string_vector parent_class_names(void) const
OCTINTERP_API octave_map map_value(void) const
bool isobject(void) const
std::size_t nparents(void) const
bool is_user_function(void) const
OCTINTERP_API octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
dim_vector dims(void) const
bool set_class_relationship(const std::string &sup_class, const std::string &inf_class)
octave_function * caller_function(void) const
interpreter & get_interpreter(void)
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void interpreter_try(unwind_protect &frame)
void warning(const char *fmt,...)
void error(const char *fmt,...)
void panic_unless(bool cond)
#define panic_impossible()
void err_wrong_type_arg(const char *name, const char *s)
void err_indexed_cs_list(void)
octave::idx_vector idx_vector
interpreter & __get_interpreter__(void)
load_path & __get_load_path__(void)
symbol_table & __get_symbol_table__(void)
tree_evaluator & __get_evaluator__(void)
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
std::string read_binary_data(std::istream &is, bool swap, octave::mach_info::float_format fmt, const std::string &filename, bool &global, octave_value &tc, std::string &doc)
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count, const bool do_name_validation)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
octave_value make_idx_args(const std::string &type, const std::list< octave_value_list > &idx, const std::string &who)
bool called_from_builtin(void)
static OCTAVE_NORETURN void err_invalid_index_type(const std::string &nm, char t)
static OCTAVE_NORETURN void err_invalid_index1(void)
static OCTAVE_NORETURN void err_invalid_index_for_assignment(void)
static bool is_built_in_class(const std::string &cn)
OCTINTERP_API octave_value binary_op(type_info &ti, octave_value::binary_op op, const octave_value &a, const octave_value &b)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.