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");
248 OCTAVE_NORETURN
static
252 error (
"invalid index for class");
255 OCTAVE_NORETURN
static
259 error (
"invalid index for class assignment");
262 OCTAVE_NORETURN
static
266 error (
"%s cannot be indexed with %c", nm.c_str (), t);
272 assert (idx.
length () == 1);
282 error (
"malformed class");
286 std::string nm = idx(0).xstring_value (
"invalid index for class");
290 if (p == my_map.
end ())
291 error (
"class has no member '%s'", nm.c_str ());
319 retval = lv(0).matrix_value ();
325 int nd = dv.
ndims ();
329 for (
int i = 0; i < nd; i++)
362 error (
"@%s/numel: invalid return value", cn.c_str ());
364 retval = lv(0).idx_type_value (
true);
374 const std::list<octave_value_list>& idx,
391 if (
type.length () > 1 &&
type[1] ==
'.')
393 auto p = idx.begin ();
460 bool maybe_cs_list_query = (
type[0] ==
'.' ||
type[0] ==
'{'
461 || (
type.length () > 1 &&
type[0] ==
'('
464 int true_nargout = nargout;
466 if (maybe_cs_list_query)
470 if (
type[0] !=
'.') tmp = idx.front ();
471 true_nargout =
xnumel (tmp);
484 if (
type.length () == 1 &&
type[0] ==
'(')
500 if (val.
numel () != 1)
513 const std::list<octave_value_list>& idx,
522 const std::list<octave_value_list>& idx,
534 const std::string&
type,
535 const std::list<octave_value_list>& idx,
595 error (
"@%s/subsasgn returned more than one value",
615 error (
"malformed class");
629 int n =
type.length ();
633 if (
n > 1 && ! (
type.length () == 2 &&
type[0] ==
'(' &&
type[1] ==
'.'))
639 if (
type.length () > 1 &&
type[1] ==
'.')
641 auto p = idx.begin ();
646 assert (key_idx.
length () == 1);
648 std::string key = key_idx(0).xstring_value (
"invalid index for class assignment");
658 Cell map_elt = map_val.
index (idx.front (),
true);
663 std::list<octave_value_list> next_idx (idx);
668 next_idx.erase (next_idx.begin ());
669 next_idx.erase (next_idx.begin ());
684 assert (key_idx.
length () == 1);
686 std::string key = key_idx(0).string_value ();
688 std::list<octave_value_list> next_idx (idx);
690 next_idx.erase (next_idx.begin ());
692 std::string next_type =
type.substr (1);
703 if (tmpc.
numel () != 1)
717 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
734 if (
n > 1 &&
type[1] ==
'.')
736 auto p = idx.begin ();
739 assert (key_idx.
length () == 1);
741 std::string key = key_idx(0).xstring_value (
"assignment to class element failed");
762 error (
"invalid class assignment");
777 assert (key_idx.
length () == 1);
779 std::string key = key_idx(0).string_value ();
826 error (
"no subsindex method defined for class %s",
835 error (
"subsindex function must return a valid index vector");
854 std::string key =
map.
key (it);
879 retval = tmp(0).is_true ();
1004 error (
"cname/char method did not return a string");
1006 retval = tmp(0).string_vector_value (pad);
1050 bool have_ctor =
false;
1073 bool execution_error =
false;
1081 catch (
const octave::execution_exception&)
1085 execution_error =
true;
1088 if (! execution_error && result.
length () == 1)
1115 bool might_have_inheritance =
false;
1116 std::string dbgstr =
"dork";
1121 std::string key =
map.
key (it);
1128 might_have_inheritance =
true;
1135 if (might_have_inheritance)
1165 os <<
"# classname: " <<
class_name () <<
"\n";
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");
1228 m.assign (nm, tcell);
1232 error (
"load: failed to load class");
1240 warning (
"load: unable to reconstruct object inheritance");
1249 map = tmp(0).map_value ();
1266 int32_t classname_len =
class_name ().length ();
1268 os.write (
reinterpret_cast<char *
> (&classname_len), 4);
1280 m = tmp(0).map_value ();
1285 int32_t
len =
m.nfields ();
1286 os.write (
reinterpret_cast<char *
> (&
len), 4);
1288 auto i =
m.begin ();
1289 while (i !=
m.end ())
1296 return ! os.fail ();
1308 bool success =
true;
1310 int32_t classname_len;
1312 is.read (
reinterpret_cast<char *
> (&classname_len), 4);
1320 classname[classname_len] =
'\0';
1321 if (! is.read (
reinterpret_cast<char *
> (classname), classname_len))
1328 if (! is.read (
reinterpret_cast<char *
> (&
len), 4))
1352 m.assign (nm, tcell);
1360 warning (
"load: unable to reconstruct object inheritance");
1369 map = tmp(0).map_value ();
1374 warning (
"load: failed to load class");
1388 bool save_as_floats)
1390 #if defined (HAVE_HDF5)
1393 hid_t group_hid = -1;
1394 hid_t type_hid = -1;
1395 hid_t space_hid = -1;
1396 hid_t class_hid = -1;
1397 hid_t data_hid = -1;
1403 #if defined (HAVE_HDF5_18)
1407 group_hid = H5Gcreate (loc_id,
name, 0);
1413 type_hid = H5Tcopy (H5T_C_S1); H5Tset_size (type_hid,
c_name.length () + 1);
1418 space_hid = H5Screate_simple (0, hdims,
nullptr);
1421 #if defined (HAVE_HDF5_18)
1422 class_hid = H5Dcreate (group_hid,
"classname", type_hid, space_hid,
1426 class_hid = H5Dcreate (group_hid,
"classname", type_hid, space_hid,
1429 if (class_hid < 0 || H5Dwrite (class_hid, type_hid,
octave_H5S_ALL,
1434 #if defined (HAVE_HDF5_18)
1438 data_hid = H5Gcreate (group_hid,
"value", 0);
1448 m = tmp(0).map_value ();
1455 while (i !=
m.end ())
1459 bool retval2 =
add_hdf5_data (data_hid, val,
m.key (i),
"",
false,
1471 H5Gclose (data_hid);
1474 H5Dclose (class_hid);
1477 H5Sclose (space_hid);
1480 H5Tclose (type_hid);
1483 H5Gclose (group_hid);
1488 octave_unused_parameter (loc_id);
1489 octave_unused_parameter (
name);
1490 octave_unused_parameter (save_as_floats);
1503 #if defined (HAVE_HDF5)
1505 hid_t group_hid = -1;
1506 hid_t data_hid = -1;
1507 hid_t type_hid = -1;
1508 hid_t type_class_hid = -1;
1509 hid_t space_hid = -1;
1510 hid_t subgroup_hid = -1;
1517 int current_item = 0;
1518 hsize_t num_obj = 0;
1522 #if defined (HAVE_HDF5_18)
1525 group_hid = H5Gopen (loc_id,
name);
1530 #if defined (HAVE_HDF5_18)
1533 data_hid = H5Dopen (group_hid,
"classname");
1539 type_hid = H5Dget_type (data_hid);
1541 type_class_hid = H5Tget_class (type_hid);
1543 if (type_class_hid != H5T_STRING)
1546 space_hid = H5Dget_space (data_hid);
1547 rank = H5Sget_simple_extent_ndims (space_hid);
1552 slen = H5Tget_size (type_hid);
1562 st_id = H5Tcopy (H5T_C_S1);
1563 H5Tset_size (st_id, slen);
1570 H5Dclose (data_hid);
1571 H5Gclose (group_hid);
1576 H5Dclose (data_hid);
1584 #if defined (HAVE_HDF5_18)
1587 subgroup_hid = H5Gopen (group_hid,
name);
1589 H5Gget_num_objs (subgroup_hid, &num_obj);
1590 H5Gclose (subgroup_hid);
1592 while (current_item <
static_cast<int> (num_obj)
1600 m.assign (dsub.
name, tcell);
1609 warning (
"load: unable to reconstruct object inheritance");
1618 map = tmp(0).map_value ();
1625 H5Dclose (data_hid);
1628 H5Gclose (group_hid);
1631 octave_unused_parameter (loc_id);
1632 octave_unused_parameter (
name);
1663 : field_names (), parent_class_names ()
1666 error (
"invalid call to exemplar_info constructor");
1682 error (
"invalid comparison of class exemplar to non-class object");
1685 error (
"mismatch in number of fields");
1693 if (obj_fnames[i] != fnames[i])
1694 error (
"mismatch in field names");
1698 error (
"mismatch in number of parent classes");
1700 const std::list<std::string> obj_parents
1702 const std::list<std::string> pnames = parents ();
1704 auto p = obj_parents.begin ();
1705 auto q = pnames.begin ();
1707 while (p != obj_parents.end ())
1710 error (
"mismatch in parent classes");
1729 int nargin = args.length ();
1738 retval = args(0).class_name ();
1742 std::string
id = args(1).xstring_value (
"class: ID (class name) must be a string");
1749 error (
"class: invalid call from outside class constructor or method");
1752 error (
"class: '%s' is invalid as a class name in this context",
1755 octave_map m = args(0).xmap_value (
"class: S must be a valid structure");
1772 else if (! it->second.compare (
retval))
1773 error (
"class: object of class '%s' does not match previously constructed objects",
1818 if (args.length () != 2)
1823 Array<std::string> clsnames = args(1).xcellstr_value (
"isa: CLASSNAME must be a string or cell array of strings");
1829 std::string cls = clsnames(idx);
1831 || (cls ==
"float" && obj.
isfloat ())
1832 || (cls ==
"integer" && obj.
isinteger ())
1833 || (cls ==
"numeric" && obj.
isnumeric ())
1835 matches(idx) =
true;
1838 return ovl (matches);
1901 DEFUN (__parent_classes__, args, ,
1907 if (args.length () != 1)
1925 if (args.length () != 1)
1934 static std::set<std::string> built_in_class_names;
1936 if (built_in_class_names.empty ())
1938 built_in_class_names.insert (
"double");
1939 built_in_class_names.insert (
"single");
1940 built_in_class_names.insert (
"cell");
1941 built_in_class_names.insert (
"struct");
1942 built_in_class_names.insert (
"logical");
1943 built_in_class_names.insert (
"char");
1944 built_in_class_names.insert (
"function handle");
1945 built_in_class_names.insert (
"int8");
1946 built_in_class_names.insert (
"uint8");
1947 built_in_class_names.insert (
"int16");
1948 built_in_class_names.insert (
"uint16");
1949 built_in_class_names.insert (
"int32");
1950 built_in_class_names.insert (
"uint32");
1951 built_in_class_names.insert (
"int64");
1952 built_in_class_names.insert (
"uint64");
1955 return built_in_class_names.find (cn) != built_in_class_names.end ();
1974 error (
"superiorto: invalid call from outside class constructor");
1976 for (
int i = 0; i < args.length (); i++)
1978 std::string inf_class = args(i).xstring_value (
"superiorto: CLASS_NAME must be a string");
1987 std::string sup_class = fcn->
name ();
1989 error (
"superiorto: opposite precedence already set for %s and %s",
1990 sup_class.c_str (), inf_class.c_str ());
2012 error (
"inferiorto: invalid call from outside class constructor");
2014 for (
int i = 0; i < args.length (); i++)
2016 std::string sup_class = args(i).xstring_value (
"inferiorto: CLASS_NAME must be a string");
2019 error (
"inferiorto: cannot give user-defined class lower "
2020 "precedence than built-in class");
2024 std::string inf_class = fcn->
name ();
2026 error (
"inferiorto: opposite precedence already set for %s and %s",
2027 inf_class.c_str (), sup_class.c_str ());
2075 return execute (tw, nargout, args);
2138 DEFUN (__inline_ctor__, args, ,
bool isvector(const dim_vector &dim)
void swap_bytes< 4 >(void *ptr)
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
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
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.
void recover_from_exception(void)
symbol_table & get_symbol_table(void)
std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
bool set_class_relationship(const std::string &sup_class, const std::string &inf_class)
void add_to_parent_map(const std::string &classname, const std::list< std::string > &parent_list)
octave_value find_method(const std::string &name, const std::string &dispatch_type)
octave_function * caller_function(void) const
octave_function * current_function(bool skip_first=false) const
interpreter & get_interpreter(void)
int register_type(const std::string &, const std::string &, const octave_value &, bool abort_on_duplicate=false)
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
void indent(std::ostream &os) const
void newline(std::ostream &os) const
virtual Matrix size(void)
virtual bool is_matrix_type(void) const
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
void warn_save(const char *type) const
string_vector field_names
std::list< std::string > parent_class_names
bool compare(const octave_value &obj) const
std::list< std::string > parents(void) const
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
void print(std::ostream &os, bool pr_as_read_syntax=false)
std::string type_name(void) const
string_vector map_keys(void) const
octave_base_value * unique_parent_class(const std::string &)
octave_base_value * unique_clone(void)
octave_idx_type xnumel(const octave_value_list &)
octave_base_value * find_parent_class(const std::string &)
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Cell dotref(const octave_value_list &idx)
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
mxArray * as_mxArray(void) const
size_t byte_size(void) const
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
octave_value subsasgn_common(const octave_value &obj, const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
static const std::string t_name
octave_map map_value(void) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
bool in_class_method(void)
bool save_ascii(std::ostream &os)
bool is_instance_of(const std::string &) const
string_vector string_vector_value(bool pad) const
idx_vector index_vector(bool require_integers=false) const
size_t nparents(void) const
octave_idx_type nfields(void) const
dim_vector dims(void) const
bool reconstruct_parents(void)
bool load_ascii(std::istream &is)
std::string get_current_method_class(void)
std::map< std::string, exemplar_info >::const_iterator exemplar_const_iterator
bool isobject(void) const
static void clear_exemplar_map(void)
bool save_binary(std::ostream &os, bool save_as_floats)
bool reconstruct_exemplar(void)
static octave_value numeric_conv(const Cell &val, const std::string &type)
octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
std::list< std::string > parent_list
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_inline_fcn(const octave_inline_fcn &ob)=delete
octave_value_list execute(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
octave_inline_fcn(octave_inline *obj)
octave_inline * m_inline_obj
octave_value_list call(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
~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)
void delete_elements(const idx_vector &i)
octave_idx_type nfields(void) const
const_iterator cend(void) const
octave_fields::const_iterator const_iterator
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
Cell xcell_value(const char *fmt,...) const
octave_map xmap_value(const char *fmt,...) const
bool is_instance_of(const std::string &cls_name) const
octave_user_function * user_function_value(bool silent=false) const
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
std::list< std::string > parent_class_name_list(void) const
bool isnumeric(void) const
octave_idx_type numel(void) const
bool is_cs_list(void) const
octave_base_value * internal_rep(void) const
size_t nparents(void) const
bool is_defined(void) const
bool isinteger(void) const
std::string class_name(void) const
octave_function * function_value(bool silent=false) const
bool isstruct(void) const
bool is_zero_by_zero(void) const
octave_idx_type nfields(void) const
string_vector parent_class_names(void) const
octave_value storable_value(void) const
size_t byte_size(void) const
octave_value_list list_value(void) const
bool isobject(void) const
octave_map map_value(void) const
idx_vector index_vector(bool require_integers=false) const
bool is_user_function(void) const
dim_vector dims(void) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
const octave_hdf5_id octave_H5P_DEFAULT
const octave_hdf5_id octave_H5S_ALL
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 warning(const char *fmt,...)
void interpreter_try(octave::unwind_protect &frame)
void error(const char *fmt,...)
#define panic_impossible()
void err_wrong_type_arg(const char *name, const char *s)
void err_indexed_cs_list(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)
interpreter & __get_interpreter__(const std::string &who)
tree_evaluator & __get_evaluator__(const std::string &who)
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.
symbol_table & __get_symbol_table__(const std::string &who)
load_path & __get_load_path__(const std::string &who)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
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)
octave_value::octave_value(const Array< char > &chm, char type) return retval
OCTINTERP_API octave_value do_binary_op(octave::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.