24 #if defined (HAVE_CONFIG_H)
83 error (
"parents must be objects");
88 error (
"duplicate class in parent tree");
138 Cell c (parent_dims);
142 std::list<std::string> plist
151 error (
"class: parent class dimension mismatch");
153 else if (nel == 1 && p_nel == 1)
170 else if (nel == p_nel)
186 std::list<std::string> plist
195 error (
"class: parent class dimension mismatch");
239 OCTAVE_NORETURN
static
243 error (
"invalid index for class");
246 OCTAVE_NORETURN
static
250 error (
"invalid index for class assignment");
253 OCTAVE_NORETURN
static
257 error (
"%s cannot be indexed with %c", nm.c_str (),
t);
263 assert (idx.
length () == 1);
273 error (
"malformed class");
277 std::string nm = idx(0).xstring_value (
"invalid index for class");
281 if (p == my_map.
end ())
282 error (
"class has no member '%s'", nm.c_str ());
303 || ! lv(0).is_matrix_type () || ! lv(0).dims ().is_vector ())
306 retval = lv(0).matrix_value ();
312 int nd = dv.
ndims ();
316 for (
int i = 0;
i < nd;
i++)
345 if (lv.
length () != 1 || ! lv(0).is_scalar_type ())
346 error (
"@%s/numel: invalid return value", cn.c_str ());
348 retval = lv(0).idx_type_value (
true);
358 const std::list<octave_value_list>& idx,
375 if (type.length () > 1 && type[1] ==
'.')
377 std::list<octave_value_list>::const_iterator
p = idx.begin ();
441 bool maybe_cs_list_query = (type[0] ==
'.' || type[0] ==
'{'
442 || (type.length () > 1 && type[0] ==
'('
447 if (maybe_cs_list_query)
451 if (type[0] !=
'.') tmp = idx.front ();
452 true_nargout =
numel (tmp);
465 if (type.length () == 1 && type[0] ==
'(')
481 if (val.
numel () != 1)
486 if (type.length () > 0 && type[0] ==
'.' && ! retval.
is_map ())
494 const std::list<octave_value_list>& idx,
503 const std::list<octave_value_list>& idx,
516 const std::list<octave_value_list>& idx,
573 error (
"@%s/subsasgn returned more than one value",
593 error (
"malformed class");
611 if (n > 1 && ! (type.length () == 2 && type[0] ==
'(' && type[1] ==
'.'))
617 if (type.length () > 1 && type[1] ==
'.')
619 std::list<octave_value_list>::const_iterator
p = idx.begin ();
624 assert (key_idx.
length () == 1);
626 std::string key = key_idx(0).xstring_value (
"invalid index for class assignment");
636 Cell map_elt = map_val.
index (idx.front (),
true);
641 std::list<octave_value_list> next_idx (idx);
646 next_idx.erase (next_idx.begin ());
647 next_idx.erase (next_idx.begin ());
651 t_rhs = u.
subsasgn (type.substr (2), next_idx, rhs);
662 assert (key_idx.
length () == 1);
666 std::list<octave_value_list> next_idx (idx);
668 next_idx.erase (next_idx.begin ());
681 if (tmpc.
numel () != 1)
695 t_rhs = tmp.
subsasgn (next_type, next_idx, rhs);
712 if (n > 1 && type[1] ==
'.')
714 std::list<octave_value_list>::const_iterator
p = idx.begin ();
717 assert (key_idx.
length () == 1);
719 std::string key = key_idx(0).xstring_value (
"assignment to class element failed");
740 error (
"invalid class assignment");
755 assert (key_idx.
length () == 1);
801 error (
"no subsindex method defined for class %s",
809 if (
tmp(0).is_object ())
810 error (
"subsindex function must return a valid index vector");
851 retval =
tmp(0).is_true ();
872 for (std::list<std::string>::iterator pit =
parent_list.begin ();
903 for (std::list<std::string>::iterator pit =
parent_list.begin ();
941 for (std::list<std::string>::const_iterator pit =
parent_list.begin ();
978 if (!
tmp(0).is_string ())
979 error (
"cname/char method did not return a string");
981 retval =
tmp(0).string_vector_value (pad);
1032 arg_names[0] =
name;
1041 os << name <<
" = <class " <<
class_name () <<
">";
1063 bool have_ctor =
false;
1086 bool execution_error =
false;
1094 catch (
const octave::execution_exception&)
1098 execution_error =
true;
1101 if (! execution_error && result.
length () == 1)
1128 bool might_have_inheritance =
false;
1141 might_have_inheritance =
true;
1148 if (might_have_inheritance)
1159 for (std::list<std::string>::iterator pit =
parent_list.begin ();
1180 os <<
"# classname: " <<
class_name () <<
"\n";
1187 m =
tmp(0).map_value ();
1192 os <<
"# length: " << m.
nfields () <<
"\n";
1195 while (i != m.
end ())
1202 return ! os.fail ();
1216 if (!
extract_keyword (is,
"classname", classname) || classname.empty ())
1217 error (
"load: failed to extract name of class");
1220 error (
"load: failed to extract number of elements in class");
1244 error (
"load: failed to load class");
1252 warning (
"load: unable to reconstruct object inheritance");
1260 map =
tmp(0).map_value ();
1277 int32_t classname_len =
class_name ().length ();
1279 os.write (reinterpret_cast<char *> (&classname_len), 4);
1288 m =
tmp(0).map_value ();
1294 os.write (reinterpret_cast<char *> (&len), 4);
1297 while (i != m.
end ())
1304 return ! os.fail ();
1316 bool success =
true;
1318 int32_t classname_len;
1320 is.read (reinterpret_cast<char *> (&classname_len), 4);
1328 classname[classname_len] =
'\0';
1329 if (! is.read (reinterpret_cast<char *> (classname), classname_len))
1336 if (! is.read (reinterpret_cast<char *> (&len), 4))
1368 warning (
"load: unable to reconstruct object inheritance");
1375 map =
tmp(0).map_value ();
1380 warning (
"load: failed to load class");
1396 #if defined (HAVE_HDF5)
1399 hid_t group_hid = -1;
1400 hid_t type_hid = -1;
1401 hid_t space_hid = -1;
1402 hid_t class_hid = -1;
1403 hid_t data_hid = -1;
1407 #if defined (HAVE_HDF5_18)
1411 group_hid = H5Gcreate (loc_id, name, 0);
1417 type_hid = H5Tcopy (H5T_C_S1); H5Tset_size (type_hid,
c_name.length () + 1);
1422 space_hid = H5Screate_simple (0 , hdims, 0);
1425 #if defined (HAVE_HDF5_18)
1426 class_hid = H5Dcreate (group_hid,
"classname", type_hid, space_hid,
1430 class_hid = H5Dcreate (group_hid,
"classname", type_hid, space_hid,
1433 if (class_hid < 0 || H5Dwrite (class_hid, type_hid,
octave_H5S_ALL,
1438 #if defined (HAVE_HDF5_18)
1442 data_hid = H5Gcreate (group_hid,
"value", 0);
1452 m =
tmp(0).map_value ();
1459 while (i != m.
end ())
1475 H5Gclose (data_hid);
1478 H5Dclose (class_hid);
1481 H5Sclose (space_hid);
1484 H5Tclose (type_hid);
1487 H5Gclose (group_hid);
1492 octave_unused_parameter (loc_id);
1493 octave_unused_parameter (name);
1494 octave_unused_parameter (save_as_floats);
1507 #if defined (HAVE_HDF5)
1509 hid_t group_hid = -1;
1510 hid_t data_hid = -1;
1511 hid_t type_hid = -1;
1512 hid_t type_class_hid = -1;
1513 hid_t space_hid = -1;
1514 hid_t subgroup_hid = -1;
1521 int current_item = 0;
1522 hsize_t num_obj = 0;
1526 #if defined (HAVE_HDF5_18)
1529 group_hid = H5Gopen (loc_id, name);
1534 #if defined (HAVE_HDF5_18)
1537 data_hid = H5Dopen (group_hid,
"classname");
1543 type_hid = H5Dget_type (data_hid);
1545 type_class_hid = H5Tget_class (type_hid);
1547 if (type_class_hid != H5T_STRING)
1550 space_hid = H5Dget_space (data_hid);
1551 rank = H5Sget_simple_extent_ndims (space_hid);
1556 slen = H5Tget_size (type_hid);
1566 st_id = H5Tcopy (H5T_C_S1);
1567 H5Tset_size (st_id, slen);
1574 H5Dclose (data_hid);
1575 H5Gclose (group_hid);
1580 H5Dclose (data_hid);
1588 #if defined (HAVE_HDF5_18)
1591 subgroup_hid = H5Gopen (group_hid, name);
1593 H5Gget_num_objs (subgroup_hid, &num_obj);
1594 H5Gclose (subgroup_hid);
1596 while (current_item < static_cast<int> (num_obj)
1613 warning (
"load: unable to reconstruct object inheritance");
1620 map =
tmp(0).map_value ();
1627 H5Dclose (data_hid);
1630 H5Gclose (group_hid);
1633 octave_unused_parameter (loc_id);
1634 octave_unused_parameter (name);
1662 : field_names (), parent_class_names ()
1665 error (
"invalid call to exemplar_info constructor");
1681 error (
"invalid comparison of class exemplar to non-class object");
1684 error (
"mismatch in number of fields");
1692 if (obj_fnames[
i] != fnames[
i])
1693 error (
"mismatch in field names");
1697 error (
"mismatch in number of parent classes");
1699 std::list<std::string> obj_parents
1701 std::list<std::string> pnames = parents ();
1703 std::list<std::string>::const_iterator
p = obj_parents.begin ();
1704 std::list<std::string>::const_iterator q = pnames.begin ();
1706 while (p != obj_parents.end ())
1709 error (
"mismatch in parent classes");
1737 retval =
args(0).class_name ();
1741 std::string id =
args(1).xstring_value (
"class: ID (class name) must be a string");
1746 error (
"class: invalid call from outside class constructor or method");
1749 error (
"class: '%s' is invalid as a class name in this context",
1752 octave_map m =
args(0).xmap_value (
"class: S must be a valid structure");
1765 = octave_class::exemplar_map.find (
id);
1767 if (it == octave_class::exemplar_map.end ())
1769 else if (! it->second.compare (retval))
1770 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");
1835 matches(idx) =
true;
1838 return ovl (matches);
1910 if (
args.length () != 1)
1928 if (
args.length () != 1)
1943 if (
args.length () != 2)
1955 error (
"ismethod: first argument must be object or class name");
1993 static std::set<std::string> built_in_class_names;
1995 if (built_in_class_names.empty ())
1997 built_in_class_names.insert (
"double");
1998 built_in_class_names.insert (
"single");
1999 built_in_class_names.insert (
"cell");
2000 built_in_class_names.insert (
"struct");
2001 built_in_class_names.insert (
"logical");
2002 built_in_class_names.insert (
"char");
2003 built_in_class_names.insert (
"function handle");
2004 built_in_class_names.insert (
"int8");
2005 built_in_class_names.insert (
"uint8");
2006 built_in_class_names.insert (
"int16");
2007 built_in_class_names.insert (
"uint16");
2008 built_in_class_names.insert (
"int32");
2009 built_in_class_names.insert (
"uint32");
2010 built_in_class_names.insert (
"int64");
2011 built_in_class_names.insert (
"uint64");
2014 return built_in_class_names.find (cn) != built_in_class_names.end ();
2030 error (
"superiorto: invalid call from outside class constructor");
2032 for (
int i = 0;
i <
args.length ();
i++)
2034 std::string inf_class =
args(
i).xstring_value (
"superiorto: CLASS_NAME must be a string");
2038 if (is_built_in_class (inf_class))
2043 error (
"superiorto: opposite precedence already set for %s and %s",
2044 sup_class.c_str (), inf_class.c_str ());
2063 error (
"inferiorto: invalid call from outside class constructor");
2065 for (
int i = 0;
i <
args.length ();
i++)
2067 std::string sup_class =
args(
i).xstring_value (
"inferiorto: CLASS_NAME must be a string");
2069 if (is_built_in_class (sup_class))
2070 error (
"inferiorto: cannot give user-defined class lower "
2071 "precedence than built-in class");
2075 error (
"inferiorto: opposite precedence already set for %s and %s",
2076 inf_class.c_str (), sup_class.c_str ());
static octave_value numeric_conv(const Cell &val, const std::string &type)
bool called_from_builtin(void)
virtual octave_base_value * unique_parent_class(const std::string &)
string_vector keys(void) const
bool is_object(void) const
bool in_class_method(void)
idx_vector index_vector(bool require_integers=false) const
const Cell & contents(const_iterator p) const
scalar structure containing the fields
size_t nparents(void) const
octave_refcount< octave_idx_type > count
std::list< std::string > parents(void) const
octave_map xmap_value(const char *fmt,...) const
void delete_elements(const idx_vector &i)
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
void assign(const std::string &k, const Cell &val)
octave_base_value * clone(void) const
virtual bool is_class_method(const std::string &="") const
Cell reshape(const dim_vector &new_dims) const
virtual octave_map map_value(void) const
static octave_value find_method(const std::string &name, const std::string &dispatch_type)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
OCTINTERP_API void print_usage(void)
bool save_binary(std::ostream &os, bool &save_as_floats)
static std::list< std::string > methods(const std::string &class_name, const std::string &pack_name="")
bool is_function(void) const
octave_idx_type numel(void) const
Number of elements in the array.
bool is_instance_of(const std::string &) const
identity matrix If supplied two scalar respectively For allows like xample val
const octave_hdf5_id octave_H5S_ALL
octave_idx_type length(void) const
dim_vector dims(void) const
octave_idx_type nfields(void) const
std::list< std::string > parent_class_name_list(void) const
octave_map map_value(void) const
Cell xcell_value(const char *fmt,...) const
std::string type_name(void) const
bool contains(const std::string &name) const
bool is_numeric_type(void) const
bool is_defined(void) const
#define DEFUN(name, args_name, nargout_name, doc)
static void add_to_parent_map(const std::string &classname, const std::list< std::string > &parent_list)
void error(const char *fmt,...)
std::string name(void) const
void indent(std::ostream &os) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
virtual bool is_class_constructor(const std::string &="") const
static const std::string t_name
static octave_function * current(void)
octave_idx_type numel(void) const
Cell dotref(const octave_value_list &idx)
string_vector string_vector_value(bool pad) const
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
static std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
void newline(std::ostream &os) const
const_iterator end(void) const
bool is_private_function_of_class(const std::string &nm) const
virtual octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
std::string dispatch_class(void) const
void print_with_name(std::ostream &os, const std::string &name, bool print_padding=true)
bool is_instance_of(const std::string &cls_name) const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
virtual octave_idx_type numel(void) const
string_vector field_names
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
idx_vector index_vector(bool require_integers=false) const
bool is_float_type(void) const
octave_map map_value(void) const
void err_indexed_cs_list(void)
std::map< std::string, exemplar_info >::const_iterator exemplar_const_iterator
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
void warn_load(const char *type) 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 OCTAVE_NORETURN void err_invalid_index_for_assignment(void)
static std::map< std::string, exemplar_info > exemplar_map
virtual octave_base_value * find_parent_class(const std::string &)
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
void swap_bytes< 4 >(void *ptr)
static octave_function * caller(void)
Additional arguments name a list of parent classes from which the new class is derived eealso nargin
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
bool reconstruct_parents(void)
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_as_global, int precision)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
octave_idx_type nfields(void) const
octave_idx_type numel(const octave_value_list &idx)
void print(std::ostream &os, bool pr_as_read_syntax=false)
std::string string_value(bool force=false) const
nd deftypefn *octave_map m
static void register_type(void)
static OCTAVE_NORETURN void err_invalid_index_type(const std::string &nm, char t)
bool is_string(void) const
octave_user_function * user_function_value(bool silent=false) const
mxArray * as_mxArray(void) const
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)
dim_vector dims(void) const
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
#define panic_impossible()
bool compare(const octave_value &obj) const
std::string key(const_iterator p) const
octave_idx_type length(void) const
std::list< std::string > parent_class_names
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
string_vector parent_class_names(void) const
const_iterator begin(void) const
virtual Matrix size(void)
dim_vector dims(void) const
void warn_save(const char *type) const
void err_wrong_type_arg(const char *name, const char *s)
With real return the complex result
string_vector map_keys(void) const
bool print_name_tag(std::ostream &os, const std::string &name) const
friend class octave_value
void setfield(const std::string &key, const Cell &val)
octave_function * function_value(bool silent=false) const
static bool set_class_relationship(const std::string &sup_class, const std::string &inf_class)
void warning(const char *fmt,...)
static OCTAVE_NORETURN void err_invalid_index1(void)
octave::unwind_protect frame
void recover_from_exception(void)
octave_base_value * unique_clone(void)
bool is_empty(void) const
octave_value make_idx_args(const std::string &type, const std::list< octave_value_list > &idx, const std::string &who)
bool subsasgn_optimization_ok(void)
octave_base_value * find_parent_class(const std::string &)
static void clear_exemplar_map(void)
size_t nparents(void) const
octave_idx_type nfields(void) const
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
=val(i)}if ode{val(i)}occurs in table i
static int register_type(const std::string &, const std::string &, const octave_value &)
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
std::list< std::string > parent_list
bool is_cs_list(void) const
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count)
octave_idx_type numel(void) const
octave_idx_type ndims(void) const
Number of dimensions.
std::string class_name(void) const
Cell index(const octave_value_list &idx, bool resize_ok=false) const
bool is_object(void) const
size_t byte_size(void) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
const_iterator seek(const std::string &k) const
virtual bool is_anonymous_function_of_class(const std::string &="") const
bool is_user_function(void) const
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
const octave_hdf5_id octave_H5P_DEFAULT
octave_value_list list_value(void) const
octave_idx_type index(const_iterator p) const
void resize(const dim_vector &dv, bool fill=false)
octave_base_value * unique_parent_class(const std::string &)
bool load_ascii(std::istream &is)
octave_fields::const_iterator const_iterator
bool reconstruct_exemplar(void)
octave_base_value * internal_rep(void) const
bool save_ascii(std::ostream &os)
write the output to stdout if nargout is
Vector representing the dimensions (size) of an Array.
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
octave_value storable_value(void) const
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
bool is_zero_by_zero(void) const
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
std::string get_current_method_class(void)
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
octave_value do_binary_op(octave_value::binary_op op, const octave_value &v1, const octave_value &v2)
size_t byte_size(void) const
OCTINTERP_API void interpreter_try(octave::unwind_protect &)
std::string class_name(void) const
bool is_integer_type(void) const
void stash_name_tags(const string_vector &nm)