24 #if defined (HAVE_CONFIG_H) 84 error (
"parents must be objects");
89 error (
"duplicate class in parent tree");
139 Cell c (parent_dims);
143 std::list<std::string> plist
152 error (
"class: parent class dimension mismatch");
154 else if (nel == 1 && p_nel == 1)
171 else if (nel == p_nel)
187 std::list<std::string> plist
196 error (
"class: parent class dimension mismatch");
245 OCTAVE_NORETURN
static 249 error (
"invalid index for class");
252 OCTAVE_NORETURN
static 256 error (
"invalid index for class assignment");
259 OCTAVE_NORETURN
static 263 error (
"%s cannot be indexed with %c",
nm.c_str (),
t);
269 assert (idx.
length () == 1);
279 error (
"malformed class");
283 std::string nm = idx(0).xstring_value (
"invalid index for class");
287 if (
p == my_map.
end ())
288 error (
"class has no member '%s'",
nm.c_str ());
313 || ! lv(0).is_matrix_type () || ! lv(0).dims ().isvector ())
316 retval = lv(0).matrix_value ();
326 for (
int i = 0;
i < nd;
i++)
358 if (lv.
length () != 1 || ! lv(0).is_scalar_type ())
359 error (
"@%s/numel: invalid return value", cn.c_str ());
361 retval = lv(0).idx_type_value (
true);
371 const std::list<octave_value_list>& idx,
388 if (
type.length () > 1 &&
type[1] ==
'.')
390 std::list<octave_value_list>::const_iterator
p = idx.begin ();
457 bool maybe_cs_list_query = (
type[0] ==
'.' ||
type[0] ==
'{' 458 || (
type.length () > 1 &&
type[0] ==
'(' 463 if (maybe_cs_list_query)
467 if (
type[0] !=
'.')
tmp = idx.front ();
481 if (
type.length () == 1 &&
type[0] ==
'(')
497 if (
val.numel () != 1)
510 const std::list<octave_value_list>& idx,
519 const std::list<octave_value_list>& idx,
532 const std::list<octave_value_list>& idx,
591 if (
tmp.length () > 1)
592 error (
"@%s/subsasgn returned more than one value",
612 error (
"malformed class");
626 int n =
type.length ();
630 if (n > 1 && ! (
type.length () == 2 &&
type[0] ==
'(' &&
type[1] ==
'.'))
636 if (
type.length () > 1 &&
type[1] ==
'.')
638 std::list<octave_value_list>::const_iterator
p = idx.begin ();
643 assert (key_idx.
length () == 1);
645 std::string key = key_idx(0).xstring_value (
"invalid index for class assignment");
655 Cell map_elt = map_val.
index (idx.front (),
true);
660 std::list<octave_value_list> next_idx (idx);
665 next_idx.erase (next_idx.begin ());
666 next_idx.erase (next_idx.begin ());
670 t_rhs =
u.subsasgn (
type.substr (2), next_idx, rhs);
681 assert (key_idx.
length () == 1);
685 std::list<octave_value_list> next_idx (idx);
687 next_idx.erase (next_idx.begin ());
700 if (tmpc.
numel () != 1)
705 if (!
tmp.is_defined () ||
tmp.is_zero_by_zero ())
714 t_rhs =
tmp.subsasgn (next_type, next_idx, rhs);
731 if (n > 1 &&
type[1] ==
'.')
733 std::list<octave_value_list>::const_iterator
p = idx.begin ();
736 assert (key_idx.
length () == 1);
738 std::string key = key_idx(0).xstring_value (
"assignment to class element failed");
759 error (
"invalid class assignment");
774 assert (key_idx.
length () == 1);
823 error (
"no subsindex method defined for class %s",
831 if (
tmp(0).isobject ())
832 error (
"subsindex function must return a valid index vector");
998 if (
tmp.length () >= 1)
1000 if (!
tmp(0).is_string ())
1001 error (
"cname/char method did not return a string");
1003 retval =
tmp(0).string_vector_value (pad);
1058 bool have_ctor =
false;
1081 bool execution_error =
false;
1089 catch (
const octave::execution_exception&)
1093 execution_error =
true;
1096 if (! execution_error &&
result.length () == 1)
1123 bool might_have_inheritance =
false;
1136 might_have_inheritance =
true;
1143 if (might_have_inheritance)
1183 m =
tmp(0).map_value ();
1188 os <<
"# length: " << m.
nfields () <<
"\n";
1191 while (
i != m.
end ())
1198 return !
os.fail ();
1213 error (
"load: failed to extract name of class");
1216 error (
"load: failed to extract number of elements in class");
1240 error (
"load: failed to load class");
1248 warning (
"load: unable to reconstruct object inheritance");
1257 map =
tmp(0).map_value ();
1274 int32_t classname_len =
class_name ().length ();
1276 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");
1377 map =
tmp(0).map_value ();
1382 warning (
"load: failed to load class");
1398 #if defined (HAVE_HDF5) 1401 hid_t group_hid = -1;
1402 hid_t type_hid = -1;
1403 hid_t space_hid = -1;
1404 hid_t class_hid = -1;
1405 hid_t data_hid = -1;
1411 #if defined (HAVE_HDF5_18) 1415 group_hid = H5Gcreate (loc_id,
name, 0);
1421 type_hid = H5Tcopy (H5T_C_S1); H5Tset_size (type_hid,
c_name.length () + 1);
1426 space_hid = H5Screate_simple (0 , hdims,
nullptr);
1429 #if defined (HAVE_HDF5_18) 1430 class_hid = H5Dcreate (group_hid,
"classname", type_hid, space_hid,
1434 class_hid = H5Dcreate (group_hid,
"classname", type_hid, space_hid,
1437 if (class_hid < 0 || H5Dwrite (class_hid, type_hid,
octave_H5S_ALL,
1442 #if defined (HAVE_HDF5_18) 1446 data_hid = H5Gcreate (group_hid,
"value", 0);
1456 m =
tmp(0).map_value ();
1463 while (
i != m.
end ())
1479 H5Gclose (data_hid);
1482 H5Dclose (class_hid);
1485 H5Sclose (space_hid);
1488 H5Tclose (type_hid);
1491 H5Gclose (group_hid);
1496 octave_unused_parameter (loc_id);
1497 octave_unused_parameter (
name);
1511 #if defined (HAVE_HDF5) 1513 hid_t group_hid = -1;
1514 hid_t data_hid = -1;
1515 hid_t type_hid = -1;
1516 hid_t type_class_hid = -1;
1517 hid_t space_hid = -1;
1518 hid_t subgroup_hid = -1;
1525 int current_item = 0;
1526 hsize_t num_obj = 0;
1530 #if defined (HAVE_HDF5_18) 1533 group_hid = H5Gopen (loc_id,
name);
1538 #if defined (HAVE_HDF5_18) 1541 data_hid = H5Dopen (group_hid,
"classname");
1547 type_hid = H5Dget_type (data_hid);
1549 type_class_hid = H5Tget_class (type_hid);
1551 if (type_class_hid != H5T_STRING)
1554 space_hid = H5Dget_space (data_hid);
1555 rank = H5Sget_simple_extent_ndims (space_hid);
1560 slen = H5Tget_size (type_hid);
1570 st_id = H5Tcopy (H5T_C_S1);
1571 H5Tset_size (st_id, slen);
1578 H5Dclose (data_hid);
1579 H5Gclose (group_hid);
1584 H5Dclose (data_hid);
1592 #if defined (HAVE_HDF5_18) 1595 subgroup_hid = H5Gopen (group_hid,
name);
1597 H5Gget_num_objs (subgroup_hid, &num_obj);
1598 H5Gclose (subgroup_hid);
1600 while (current_item < static_cast<int> (num_obj)
1617 warning (
"load: unable to reconstruct object inheritance");
1626 map =
tmp(0).map_value ();
1633 H5Dclose (data_hid);
1636 H5Gclose (group_hid);
1639 octave_unused_parameter (loc_id);
1640 octave_unused_parameter (
name);
1671 : field_names (), parent_class_names ()
1674 error (
"invalid call to exemplar_info constructor");
1690 error (
"invalid comparison of class exemplar to non-class object");
1693 error (
"mismatch in number of fields");
1701 if (obj_fnames[
i] != fnames[
i])
1702 error (
"mismatch in field names");
1706 error (
"mismatch in number of parent classes");
1708 std::list<std::string> obj_parents
1710 std::list<std::string> pnames = parents ();
1712 std::list<std::string>::const_iterator
p = obj_parents.begin ();
1713 std::list<std::string>::const_iterator q = pnames.begin ();
1715 while (
p != obj_parents.end ())
1718 error (
"mismatch in parent classes");
1737 int nargin = args.length ();
1750 std::string id = args(1).xstring_value (
"class: ID (class name) must be a string");
1757 error (
"class: invalid call from outside class constructor or method");
1760 error (
"class: '%s' is invalid as a class name in this context",
1763 octave_map m = args(0).xmap_value (
"class: S must be a valid structure");
1780 else if (! it->second.compare (
retval))
1781 error (
"class: object of class '%s' does not match previously constructed objects",
1826 if (args.length () != 2)
1831 Array<std::string> clsnames = args(1).xcellstr_value (
"isa: CLASSNAME must be a string or cell array of strings");
1839 || (cls ==
"float" && obj.
isfloat ())
1840 || (cls ==
"integer" && obj.
isinteger ())
1841 || (cls ==
"numeric" && obj.
isnumeric ())
1843 matches(idx) =
true;
1846 return ovl (matches);
1909 DEFUN (__parent_classes__, args, ,
1915 if (args.length () != 1)
1933 if (args.length () != 1)
1948 if (args.length () != 2)
1960 error (
"ismethod: first argument must be object or class name");
2002 static std::set<std::string> built_in_class_names;
2004 if (built_in_class_names.empty ())
2006 built_in_class_names.insert (
"double");
2007 built_in_class_names.insert (
"single");
2008 built_in_class_names.insert (
"cell");
2009 built_in_class_names.insert (
"struct");
2010 built_in_class_names.insert (
"logical");
2011 built_in_class_names.insert (
"char");
2012 built_in_class_names.insert (
"function handle");
2013 built_in_class_names.insert (
"int8");
2014 built_in_class_names.insert (
"uint8");
2015 built_in_class_names.insert (
"int16");
2016 built_in_class_names.insert (
"uint16");
2017 built_in_class_names.insert (
"int32");
2018 built_in_class_names.insert (
"uint32");
2019 built_in_class_names.insert (
"int64");
2020 built_in_class_names.insert (
"uint64");
2023 return built_in_class_names.find (cn) != built_in_class_names.end ();
2042 error (
"superiorto: invalid call from outside class constructor");
2044 for (
int i = 0;
i < args.length ();
i++)
2046 std::string inf_class = args(
i).xstring_value (
"superiorto: CLASS_NAME must be a string");
2050 if (is_built_in_class (inf_class))
2057 error (
"superiorto: opposite precedence already set for %s and %s",
2058 sup_class.c_str (), inf_class.c_str ());
2080 error (
"inferiorto: invalid call from outside class constructor");
2082 for (
int i = 0;
i < args.length ();
i++)
2084 std::string sup_class = args(
i).xstring_value (
"inferiorto: CLASS_NAME must be a string");
2086 if (is_built_in_class (sup_class))
2087 error (
"inferiorto: cannot give user-defined class lower " 2088 "precedence than built-in class");
2094 error (
"inferiorto: opposite precedence already set for %s and %s",
2095 inf_class.c_str (), sup_class.c_str ());
dim_vector dims(void) const
static octave_value numeric_conv(const Cell &val, const std::string &type)
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
OCTINTERP_API octave_value_list feval(const std::string &name, const octave_value_list &args=octave_value_list(), int nargout=0)
octave_map map_value(void) const
bool called_from_builtin(void)
Cell index(const octave_value_list &idx, bool resize_ok=false) const
virtual octave_base_value * unique_parent_class(const std::string &)
bool in_class_method(void)
scalar structure containing the fields
octave_idx_type numel(void) const
bool contains(const std::string &name) const
octave_base_value * internal_rep(void) const
std::string class_name(void) const
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
bool is_user_function(void) const
void delete_elements(const idx_vector &i)
bool is_instance_of(const std::string &cls_name) const
std::string string_value(bool force=false) const
string_vector keys(void) const
void assign(const std::string &k, const Cell &val)
static void recover_from_exception(void)
octave_map map_value(void) const
OCTINTERP_API void print_usage(void)
bool save_binary(std::ostream &os, bool &save_as_floats)
idx_vector index_vector(bool require_integers=false) const
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
bool compare(const octave_value &obj) const
identity matrix If supplied two scalar respectively For allows like xample val
const octave_hdf5_id octave_H5S_ALL
void newline(std::ostream &os) const
bool is_cs_list(void) const
virtual bool print_name_tag(std::ostream &os, const std::string &name) const
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
std::string key(const_iterator p) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
static const std::string t_name
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
string_vector map_keys(void) const
bool is_defined(void) const
Cell dotref(const octave_value_list &idx)
const_iterator end(void) 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
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
std::list< std::string > parents(void) const
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
bool isobject(void) const
std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
virtual octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
void print_with_name(std::ostream &os, const std::string &name, bool print_padding=true)
void warn_load(const char *type) const
octave_value resize(const dim_vector &dv, bool fill=false) const
string_vector field_names
virtual octave_map map_value(void) const
void err_indexed_cs_list(void)
std::map< std::string, exemplar_info >::const_iterator exemplar_const_iterator
octave_value storable_value(void) const
octave_idx_type index(const_iterator p) const
size_t byte_size(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 OCTAVE_NORETURN void err_invalid_index_for_assignment(void)
symbol_table & __get_symbol_table__(const std::string &who)
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)
mxArray * as_mxArray(void) const
bool is_instance_of(const std::string &) const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
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 set_class_relationship(const std::string &sup_class, const std::string &inf_class)
bool reconstruct_parents(void)
std::string dispatch_class(void) const
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 extract_keyword(std::istream &is, const char *keyword, const bool next_only)
octave_idx_type numel(const octave_value_list &idx)
octave_function * caller(void) const
void print(std::ostream &os, bool pr_as_read_syntax=false)
static OCTAVE_NORETURN void err_invalid_index_type(const std::string &nm, char t)
OCTINTERP_API octave_value do_binary_op(octave::type_info &ti, octave_value::binary_op op, const octave_value &a, const octave_value &b)
bool is_private_function_of_class(const std::string &nm) const
dim_vector dims(void) const
bool isinteger(void) const
virtual bool is_class_method(const std::string &="") 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)
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
#define panic_impossible()
std::list< std::string > parent_class_name_list(void) const
virtual octave_idx_type numel(void) const
octave_function * function_value(bool silent=false) const
const Cell & contents(const_iterator p) const
octave_user_function * user_function_value(bool silent=false) const
void warn_save(const char *type) const
std::string class_name(void) const
static void register_type(void)
octave_value find_method(const std::string &name, const std::string &dispatch_type)
string_vector parent_class_names(void) const
octave_base_value * clone(void) const
bool is_function(void) const
virtual bool is_anonymous_function_of_class(const std::string &="") const
std::list< std::string > parent_class_names
bool isstruct(void) const
string_vector string_vector_value(bool pad) const
virtual Matrix size(void)
octave_idx_type nfields(void) const
load_path & __get_load_path__(const std::string &who)
octave_idx_type numel(void) const
void err_wrong_type_arg(const char *name, const char *s)
With real return the complex result
void indent(std::ostream &os) const
friend class octave_value
void setfield(const std::string &key, const Cell &val)
octave_function * current(void) const
octave_idx_type nfields(void) const
void warning(const char *fmt,...)
static OCTAVE_NORETURN void err_invalid_index1(void)
octave::unwind_protect frame
bool print_name_tag(std::ostream &os, const std::string &name) const
octave_base_value * unique_clone(void)
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_value_list list_value(void) const
octave_base_value * find_parent_class(const std::string &)
static void clear_exemplar_map(void)
std::list< std::string > methods(const std::string &class_name, const std::string &pack_name="")
int register_type(const std::string &, const std::string &, const octave_value &, bool abort_on_duplicate=false)
void add_to_parent_map(const std::string &classname, const std::list< std::string > &parent_list)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
virtual bool is_class_constructor(const std::string &="") const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
std::list< std::string > parent_list
call_stack & __get_call_stack__(const std::string &who)
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count)
octave_idx_type length(void) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
octave_map xmap_value(const char *fmt,...) const
octave::refcount< octave_idx_type > count
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
bool isobject(void) const
octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
octave_idx_type nfields(void) const
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
const octave_hdf5_id octave_H5P_DEFAULT
Cell reshape(const dim_vector &new_dims) const
bool is_string(void) const
octave_idx_type ndims(void) const
Number of dimensions.
void resize(const dim_vector &dv, bool fill=false)
size_t nparents(void) const
octave_base_value * unique_parent_class(const std::string &)
bool load_ascii(std::istream &is)
dim_vector dims(void) const
octave_fields::const_iterator const_iterator
bool reconstruct_exemplar(void)
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type length(void) const
bool save_ascii(std::ostream &os)
write the output to stdout if nargout is
Vector representing the dimensions (size) of an Array.
const_iterator begin(void) const
std::string name(void) const
const_iterator seek(const std::string &k) 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
virtual void print_with_name(std::ostream &output_buf, const std::string &name, bool print_padding=true)
Cell xcell_value(const char *fmt,...) const
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
bool isnumeric(void) const
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
std::string get_current_method_class(void)
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)
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
std::string type_name(void) const
idx_vector index_vector(bool require_integers=false) const
OCTINTERP_API void interpreter_try(octave::unwind_protect &)
size_t nparents(void) const